chore: added publicRuntimeConfig

This commit is contained in:
Henit Chobisa 2023-09-06 06:27:49 +00:00
parent a718056b93
commit b0eee08499
7 changed files with 42 additions and 11 deletions

View File

@ -4,6 +4,8 @@ import { useRouter } from "next/router";
import useSWRInfinite from "swr/infinite";
import getConfig from "next/config";
// services
import projectService from "services/project.service";
// ui
@ -31,11 +33,13 @@ export const SelectRepository: React.FC<Props> = ({
const router = useRouter();
const { workspaceSlug } = router.query;
const { publicRuntimeConfig: { NEXT_PUBLIC_API_BASE_URL } } = getConfig();
const getKey = (pageIndex: number) => {
if (!workspaceSlug || !integration) return;
return `${
process.env.NEXT_PUBLIC_API_BASE_URL
NEXT_PUBLIC_API_BASE_URL
}/api/workspaces/${workspaceSlug}/workspace-integrations/${
integration.id
}/github-repositories/?page=${++pageIndex}`;

View File

@ -6,6 +6,7 @@ import { Controller, useForm } from "react-hook-form";
// headless ui
import { Dialog, Transition } from "@headlessui/react";
// ui components
import getConfig from "next/config";
import {
ToggleSwitch,
PrimaryButton,
@ -63,9 +64,11 @@ export const PublishProjectModal: React.FC<Props> = observer(() => {
const [isUnpublishing, setIsUnpublishing] = useState(false);
const [isUpdateRequired, setIsUpdateRequired] = useState(false);
const plane_deploy_url = process.env.NEXT_PUBLIC_DEPLOY_URL ?? "http://localhost:4000";
const { publicRuntimeConfig: { NEXT_PUBLIC_DEPLOY_URL } } = getConfig();
const router = useRouter();
const plane_deploy_url = NEXT_PUBLIC_DEPLOY_URL ?? "http://localhost:4000";
const router = useRouter()
const { workspaceSlug } = router.query;
const store: RootStore = useMobxStore();

View File

@ -8,6 +8,8 @@ import { Tooltip } from "components/ui";
// hooks
import useProjectDetails from "hooks/use-project-details";
import getConfig from "next/config";
type Props = {
breadcrumbs?: JSX.Element;
left?: JSX.Element;
@ -16,7 +18,7 @@ type Props = {
noHeader: boolean;
};
const { NEXT_PUBLIC_DEPLOY_URL } = process.env;
const { publicRuntimeConfig: { NEXT_PUBLIC_DEPLOY_URL } } = getConfig();
const plane_deploy_url = NEXT_PUBLIC_DEPLOY_URL ? NEXT_PUBLIC_DEPLOY_URL : "http://localhost:3001";
const Header: React.FC<Props> = ({ breadcrumbs, left, right, setToggleSidebar, noHeader }) => {

View File

@ -1,4 +1,5 @@
// cookies
import getConfig from "next/config";
import { convertCookieStringToObject } from "./cookie";
// types
import type { IProjectMember, IUser, IWorkspace, IWorkspaceMember } from "types";
@ -9,7 +10,9 @@ export const requiredAuth = async (cookie?: string) => {
if (!token) return null;
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";
const { publicRuntimeConfig: { NEXT_PUBLIC_API_BASE_URL } } = getConfig();
const baseUrl = NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";
let user: IUser | null = null;
@ -41,7 +44,9 @@ export const requiredAdmin = async (workspaceSlug: string, projectId: string, co
const cookies = convertCookieStringToObject(cookie);
const token = cookies?.accessToken;
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";
const { publicRuntimeConfig: { NEXT_PUBLIC_API_BASE_URL } } = getConfig();
const baseUrl = NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";
let memberDetail: IProjectMember | null = null;
@ -75,7 +80,9 @@ export const requiredWorkspaceAdmin = async (workspaceSlug: string, cookie?: str
const cookies = convertCookieStringToObject(cookie);
const token = cookies?.accessToken;
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";
const { publicRuntimeConfig: { NEXT_PUBLIC_API_BASE_URL } } = getConfig();
const baseUrl = NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";
let memberDetail: IWorkspaceMember | null = null;
@ -119,7 +126,8 @@ export const homePageRedirect = async (cookie?: string) => {
let workspaces: IWorkspace[] = [];
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";
const { publicRuntimeConfig: { NEXT_PUBLIC_API_BASE_URL } } = getConfig();
const baseUrl = NEXT_PUBLIC_API_BASE_URL || "https://api.plane.so";
const cookies = convertCookieStringToObject(cookie);
const token = cookies?.accessToken;

View File

@ -9,6 +9,10 @@ const extraImageDomains = (process.env.NEXT_PUBLIC_EXTRA_IMAGE_DOMAINS ?? "")
const nextConfig = {
reactStrictMode: false,
swcMinify: true,
publicRuntimeConfig: {
NEXT_PUBLIC_DEPLOY_URL: process.env.NEXT_PUBLIC_DEPLOY_URL,
NEXT_PUBLIC_API_BASE_URL: process.env.NEXT_PUBLIC_API_BASE_URL
},
images: {
domains: [
"vinci-web.s3.amazonaws.com",

View File

@ -2,6 +2,7 @@
import Head from "next/head";
import dynamic from "next/dynamic";
import Router from "next/router";
import App, { AppContext, AppProps } from 'next/app'
// themes
import { ThemeProvider } from "next-themes";
@ -20,8 +21,6 @@ import NProgress from "nprogress";
import { UserProvider } from "contexts/user.context";
import { ToastContextProvider } from "contexts/toast.context";
import { ThemeContextProvider } from "contexts/theme.context";
// types
import type { AppProps } from "next/app";
// constants
import { THEMES } from "constants/themes";
// constants
@ -45,6 +44,12 @@ Router.events.on("routeChangeStart", NProgress.start);
Router.events.on("routeChangeError", NProgress.done);
Router.events.on("routeChangeComplete", NProgress.done);
MyApp.getInitialProps = async (appContext: AppContext) => {
const appProps = await App.getInitialProps(appContext)
return { ...appProps }
}
function MyApp({ Component, pageProps }: AppProps) {
return (
// <UserProvider>

View File

@ -29,6 +29,7 @@ import { useMobxStore } from "lib/mobx/store-provider";
// next themes
import { useTheme } from "next-themes";
import { IUser } from "types";
import getConfig from "next/config";
// types
type EmailPasswordFormValues = {
@ -41,6 +42,10 @@ const HomePage: NextPage = observer(() => {
const store: any = useMobxStore();
const { setTheme } = useTheme();
const {
publicRuntimeConfig: { PROJECT_API },
} = getConfig()
const { isLoading, mutateUser } = useUserAuth("sign-in");
const { setToastAlert } = useToast();
@ -176,7 +181,7 @@ const HomePage: NextPage = observer(() => {
{parseInt(process.env.NEXT_PUBLIC_ENABLE_OAUTH || "0") ? (
<>
<h1 className="text-center text-2xl sm:text-2.5xl font-semibold text-custom-text-100">
Sign in to Plane
{ `Sign in to ${PROJECT_API} Plane` }
</h1>
<div className="flex flex-col divide-y divide-custom-border-200">
<div className="pb-7">