From 6de19e4a8b7bd45ae49d49d837b407dbcf7b8bf4 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Wed, 18 Sep 2024 00:02:06 +0700 Subject: [PATCH] feat: move variables to the backendD --- apps/frontend/next.config.js | 7 +- .../src/app/(site)/analytics/page.tsx | 7 +- .../src/app/(site)/billing/lifetime/page.tsx | 4 +- apps/frontend/src/app/(site)/billing/page.tsx | 4 +- .../frontend/src/app/(site)/launches/page.tsx | 4 +- .../src/app/(site)/marketplace/buyer/page.tsx | 4 +- .../src/app/(site)/marketplace/page.tsx | 4 +- .../app/(site)/marketplace/seller/page.tsx | 4 +- .../src/app/(site)/messages/[id]/page.tsx | 4 +- .../frontend/src/app/(site)/messages/page.tsx | 4 +- .../frontend/src/app/(site)/settings/page.tsx | 5 +- .../src/app/auth/activate/[code]/page.tsx | 4 +- apps/frontend/src/app/auth/activate/page.tsx | 4 +- .../src/app/auth/forgot/[token]/page.tsx | 4 +- apps/frontend/src/app/auth/forgot/page.tsx | 4 +- apps/frontend/src/app/auth/layout.tsx | 9 +-- apps/frontend/src/app/auth/login/page.tsx | 4 +- apps/frontend/src/app/auth/page.tsx | 4 +- apps/frontend/src/app/layout.tsx | 22 ++++-- apps/frontend/src/components/auth/login.tsx | 5 +- .../src/components/billing/faq.component.tsx | 48 +++++++----- .../billing/main.billing.component.tsx | 9 ++- .../launches/add.provider.component.tsx | 5 +- .../components/launches/calendar.context.tsx | 5 +- .../launches/helpers/new.image.component.tsx | 6 +- .../src/components/launches/polonto.tsx | 7 +- .../src/components/layout/layout.context.tsx | 6 +- .../src/components/layout/layout.settings.tsx | 16 ++-- .../components/layout/logout.component.tsx | 7 +- .../components/layout/settings.component.tsx | 7 +- .../src/components/layout/support.tsx | 6 +- apps/frontend/src/components/layout/title.tsx | 3 +- .../src/components/layout/top.menu.tsx | 77 ++++++++++--------- .../onboarding/connect.channels.tsx | 7 +- .../src/components/onboarding/onboarding.tsx | 30 ++++---- .../settings/settings.component.tsx | 7 +- apps/frontend/src/middleware.ts | 3 +- .../helpers/src/utils/custom.fetch.func.ts | 6 +- .../src/utils/is.general.server.side.ts | 3 + .../src/helpers/is.general.tsx | 4 +- .../src/helpers/use.media.directory.ts | 4 +- .../src/helpers/variable.context.tsx | 48 ++++++++++++ 42 files changed, 260 insertions(+), 165 deletions(-) create mode 100644 libraries/helpers/src/utils/is.general.server.side.ts create mode 100644 libraries/react-shared-libraries/src/helpers/variable.context.tsx diff --git a/apps/frontend/next.config.js b/apps/frontend/next.config.js index 3df2713a..34d130da 100644 --- a/apps/frontend/next.config.js +++ b/apps/frontend/next.config.js @@ -20,12 +20,7 @@ const nextConfig = { hostname: '**', }, ], - }, - env: { - isBillingEnabled: String(!!process.env.STRIPE_PUBLISHABLE_KEY), - isGeneral: String(!!process.env.IS_GENERAL), - frontendUrl: String(process.env.FRONTEND_URL), - }, + } }; const plugins = [ diff --git a/apps/frontend/src/app/(site)/analytics/page.tsx b/apps/frontend/src/app/(site)/analytics/page.tsx index ac117078..951f8bdb 100644 --- a/apps/frontend/src/app/(site)/analytics/page.tsx +++ b/apps/frontend/src/app/(site)/analytics/page.tsx @@ -1,20 +1,19 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; - export const dynamic = 'force-dynamic'; import { AnalyticsComponent } from '@gitroom/frontend/components/analytics/analytics.component'; import { Metadata } from 'next'; import { PlatformAnalytics } from '@gitroom/frontend/components/platform-analytics/platform.analytics'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Analytics`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Analytics`, description: '', }; export default async function Index() { return ( <> - {isGeneral() ? : } + {isGeneralServerSide() ? : } ); } diff --git a/apps/frontend/src/app/(site)/billing/lifetime/page.tsx b/apps/frontend/src/app/(site)/billing/lifetime/page.tsx index 8df7e829..916731df 100644 --- a/apps/frontend/src/app/(site)/billing/lifetime/page.tsx +++ b/apps/frontend/src/app/(site)/billing/lifetime/page.tsx @@ -3,10 +3,10 @@ import { LifetimeDeal } from '@gitroom/frontend/components/billing/lifetime.deal export const dynamic = 'force-dynamic'; import { Metadata } from 'next'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Lifetime deal`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Lifetime deal`, description: '', }; diff --git a/apps/frontend/src/app/(site)/billing/page.tsx b/apps/frontend/src/app/(site)/billing/page.tsx index d7a9722c..77bfcf7e 100644 --- a/apps/frontend/src/app/(site)/billing/page.tsx +++ b/apps/frontend/src/app/(site)/billing/page.tsx @@ -1,12 +1,12 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; export const dynamic = 'force-dynamic'; import { BillingComponent } from '@gitroom/frontend/components/billing/billing.component'; import { Metadata } from 'next'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Billing`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Billing`, description: '', }; diff --git a/apps/frontend/src/app/(site)/launches/page.tsx b/apps/frontend/src/app/(site)/launches/page.tsx index 82e36764..544fbab0 100644 --- a/apps/frontend/src/app/(site)/launches/page.tsx +++ b/apps/frontend/src/app/(site)/launches/page.tsx @@ -1,12 +1,12 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; export const dynamic = 'force-dynamic'; import {LaunchesComponent} from "@gitroom/frontend/components/launches/launches.component"; import {Metadata} from "next"; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz Calendar' : 'Gitroom Launches'}`, + title: `${isGeneralServerSide() ? 'Postiz Calendar' : 'Gitroom Launches'}`, description: '', } diff --git a/apps/frontend/src/app/(site)/marketplace/buyer/page.tsx b/apps/frontend/src/app/(site)/marketplace/buyer/page.tsx index a67c2404..b02c4dd6 100644 --- a/apps/frontend/src/app/(site)/marketplace/buyer/page.tsx +++ b/apps/frontend/src/app/(site)/marketplace/buyer/page.tsx @@ -2,10 +2,10 @@ import { Buyer } from '@gitroom/frontend/components/marketplace/buyer'; export const dynamic = 'force-dynamic'; import { Metadata } from 'next'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Marketplace`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Marketplace`, description: '', }; export default async function Index({ diff --git a/apps/frontend/src/app/(site)/marketplace/page.tsx b/apps/frontend/src/app/(site)/marketplace/page.tsx index f6d3302a..6f10ab0a 100644 --- a/apps/frontend/src/app/(site)/marketplace/page.tsx +++ b/apps/frontend/src/app/(site)/marketplace/page.tsx @@ -1,12 +1,12 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; export const dynamic = 'force-dynamic'; import { Metadata } from 'next'; import { cookies } from 'next/headers'; import { redirect } from 'next/navigation'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Marketplace`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Marketplace`, description: '', }; export default async function Index({ diff --git a/apps/frontend/src/app/(site)/marketplace/seller/page.tsx b/apps/frontend/src/app/(site)/marketplace/seller/page.tsx index dee662a4..a5776360 100644 --- a/apps/frontend/src/app/(site)/marketplace/seller/page.tsx +++ b/apps/frontend/src/app/(site)/marketplace/seller/page.tsx @@ -2,10 +2,10 @@ import { Seller } from '@gitroom/frontend/components/marketplace/seller'; export const dynamic = 'force-dynamic'; import { Metadata } from 'next'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Marketplace`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Marketplace`, description: '', }; export default async function Index({ diff --git a/apps/frontend/src/app/(site)/messages/[id]/page.tsx b/apps/frontend/src/app/(site)/messages/[id]/page.tsx index a416877d..9c78f737 100644 --- a/apps/frontend/src/app/(site)/messages/[id]/page.tsx +++ b/apps/frontend/src/app/(site)/messages/[id]/page.tsx @@ -3,10 +3,10 @@ import { Messages } from '@gitroom/frontend/components/messages/messages'; export const dynamic = 'force-dynamic'; import { Metadata } from 'next'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Messages`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Messages`, description: '', }; diff --git a/apps/frontend/src/app/(site)/messages/page.tsx b/apps/frontend/src/app/(site)/messages/page.tsx index 626b781e..70da5af7 100644 --- a/apps/frontend/src/app/(site)/messages/page.tsx +++ b/apps/frontend/src/app/(site)/messages/page.tsx @@ -1,11 +1,11 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; export const dynamic = 'force-dynamic'; import {Metadata} from "next"; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Messages`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Messages`, description: '', } diff --git a/apps/frontend/src/app/(site)/settings/page.tsx b/apps/frontend/src/app/(site)/settings/page.tsx index 6979dfd2..ba9acb8e 100644 --- a/apps/frontend/src/app/(site)/settings/page.tsx +++ b/apps/frontend/src/app/(site)/settings/page.tsx @@ -1,5 +1,3 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; - export const dynamic = 'force-dynamic'; import { SettingsComponent } from '@gitroom/frontend/components/settings/settings.component'; @@ -7,9 +5,10 @@ import { internalFetch } from '@gitroom/helpers/utils/internal.fetch'; import { redirect } from 'next/navigation'; import { RedirectType } from 'next/dist/client/components/redirect'; import { Metadata } from 'next'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Settings`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Settings`, description: '', }; export default async function Index({ diff --git a/apps/frontend/src/app/auth/activate/[code]/page.tsx b/apps/frontend/src/app/auth/activate/[code]/page.tsx index fb02d53a..ee6613c5 100644 --- a/apps/frontend/src/app/auth/activate/[code]/page.tsx +++ b/apps/frontend/src/app/auth/activate/[code]/page.tsx @@ -1,12 +1,12 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; export const dynamic = 'force-dynamic'; import { Metadata } from 'next'; import { AfterActivate } from '@gitroom/frontend/components/auth/after.activate'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} - Activate your account`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} - Activate your account`, description: '', }; diff --git a/apps/frontend/src/app/auth/activate/page.tsx b/apps/frontend/src/app/auth/activate/page.tsx index 607b709d..6cfe6609 100644 --- a/apps/frontend/src/app/auth/activate/page.tsx +++ b/apps/frontend/src/app/auth/activate/page.tsx @@ -1,12 +1,12 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; export const dynamic = 'force-dynamic'; import {Metadata} from "next"; import { Activate } from '@gitroom/frontend/components/auth/activate'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} - Activate your account`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} - Activate your account`, description: '', }; diff --git a/apps/frontend/src/app/auth/forgot/[token]/page.tsx b/apps/frontend/src/app/auth/forgot/[token]/page.tsx index 44f4ddd5..fc6e3e3f 100644 --- a/apps/frontend/src/app/auth/forgot/[token]/page.tsx +++ b/apps/frontend/src/app/auth/forgot/[token]/page.tsx @@ -1,12 +1,12 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; export const dynamic = 'force-dynamic'; import { ForgotReturn } from '@gitroom/frontend/components/auth/forgot-return'; import { Metadata } from 'next'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Forgot Password`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Forgot Password`, description: '', }; export default async function Auth(params: { params: { token: string } }) { diff --git a/apps/frontend/src/app/auth/forgot/page.tsx b/apps/frontend/src/app/auth/forgot/page.tsx index 8518e18e..79a53362 100644 --- a/apps/frontend/src/app/auth/forgot/page.tsx +++ b/apps/frontend/src/app/auth/forgot/page.tsx @@ -1,12 +1,12 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; export const dynamic = 'force-dynamic'; import {Forgot} from "@gitroom/frontend/components/auth/forgot"; import {Metadata} from "next"; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; export const metadata: Metadata = { - title: `${isGeneral() ? 'Postiz' : 'Gitroom'} Forgot Password`, + title: `${isGeneralServerSide() ? 'Postiz' : 'Gitroom'} Forgot Password`, description: '', }; diff --git a/apps/frontend/src/app/auth/layout.tsx b/apps/frontend/src/app/auth/layout.tsx index dc005197..14082286 100644 --- a/apps/frontend/src/app/auth/layout.tsx +++ b/apps/frontend/src/app/auth/layout.tsx @@ -1,11 +1,10 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; - export const dynamic = 'force-dynamic'; import { ReactNode } from 'react'; import Image from 'next/image'; import clsx from 'clsx'; import loadDynamic from 'next/dynamic'; +import { isGeneralServerSide } from '@gitroom/helpers/utils/is.general.server.side'; const ReturnUrlComponent = loadDynamic(() => import('./return.url.component')); export default async function AuthLayout({ @@ -22,15 +21,15 @@ export default async function AuthLayout({
Logo
- {isGeneral() ? ( + {isGeneralServerSide() ? ( - - {children} - + + + {children} + + ); diff --git a/apps/frontend/src/components/auth/login.tsx b/apps/frontend/src/components/auth/login.tsx index 741027f5..9810e5d6 100644 --- a/apps/frontend/src/components/auth/login.tsx +++ b/apps/frontend/src/components/auth/login.tsx @@ -10,8 +10,8 @@ import { classValidatorResolver } from '@hookform/resolvers/class-validator'; import { LoginUserDto } from '@gitroom/nestjs-libraries/dtos/auth/login.user.dto'; import { GithubProvider } from '@gitroom/frontend/components/auth/providers/github.provider'; import interClass from '@gitroom/react/helpers/inter.font'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; import { GoogleProvider } from '@gitroom/frontend/components/auth/providers/google.provider'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; type Inputs = { email: string; @@ -22,6 +22,7 @@ type Inputs = { export function Login() { const [loading, setLoading] = useState(false); + const {isGeneral} = useVariables(); const resolver = useMemo(() => { return classValidatorResolver(LoginUserDto); }, []); @@ -61,7 +62,7 @@ export function Login() {
- {!isGeneral() ? : } + {!isGeneral ? : }
{ + const {isGeneral} = useVariables(); + return [ + { + title: `Can I trust ${isGeneral ? 'Postiz' : 'Gitroom'}?`, + description: `${isGeneral ? 'Postiz' : 'Gitroom'} is proudly open-source! We believe in an ethical and transparent culture, meaning Postiz will live forever. You can check the entire code / or use it for your personal use. You can check the open-source repository click here.`, + }, + { + title: 'What are channels?', + description: `${ + isGeneral ? 'Postiz' : 'Gitroom' + } allows you to schedule your posts between different channels. A channel is a publishing platform where you can schedule your posts. For example, you can schedule your posts on Twitter, Linkedin, DEV and Hashnode`, - }, - { - title: 'What are team members?', - description: `If you have a team with multiple members, you can invite them to your workspace to collaborate on your posts and add their personal channels`, - }, - { - title: 'What is AI auto-complete?', - description: `We automate ChatGPT to help you write your social posts and articles`, - }, -]; + }, + { + title: 'What are team members?', + description: `If you have a team with multiple members, you can invite them to your workspace to collaborate on your posts and add their personal channels`, + }, + { + title: 'What is AI auto-complete?', + description: `We automate ChatGPT to help you write your social posts and articles`, + }, + ]; +} export const FAQSection: FC<{ title: string; description: string }> = ( props @@ -98,6 +103,7 @@ export const FAQSection: FC<{ title: string; description: string }> = ( }; export const FAQComponent: FC = () => { + const list = useFaqList(); return (

diff --git a/apps/frontend/src/components/billing/main.billing.component.tsx b/apps/frontend/src/components/billing/main.billing.component.tsx index 9c7b466a..dc55b7fd 100644 --- a/apps/frontend/src/components/billing/main.billing.component.tsx +++ b/apps/frontend/src/components/billing/main.billing.component.tsx @@ -19,7 +19,7 @@ import { useSWRConfig } from 'swr'; import { useUser } from '@gitroom/frontend/components/layout/user.context'; import interClass from '@gitroom/react/helpers/inter.font'; import { useRouter } from 'next/navigation'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; export interface Tiers { month: Array<{ @@ -153,6 +153,7 @@ export const MainBillingComponent: FC<{ sub?: Subscription; }> = (props) => { const { sub } = props; + const {isGeneral} = useVariables(); const { mutate } = useSWRConfig(); const fetch = useFetch(); const toast = useToaster(); @@ -329,7 +330,7 @@ export const MainBillingComponent: FC<{

{Object.entries(pricing) - .filter((f) => !isGeneral() || f[0] !== 'FREE') + .filter((f) => !isGeneral || f[0] !== 'FREE') .map(([name, values]) => (
- {isGeneral() && !subscription?.cancelAt && ( + {isGeneral && !subscription?.cancelAt && (
- {!isGeneral() && ( + {!isGeneral && (

Articles

diff --git a/apps/frontend/src/components/launches/calendar.context.tsx b/apps/frontend/src/components/launches/calendar.context.tsx index ae63d017..724dd29a 100644 --- a/apps/frontend/src/components/launches/calendar.context.tsx +++ b/apps/frontend/src/components/launches/calendar.context.tsx @@ -12,11 +12,10 @@ import { useState, } from 'react'; import dayjs from 'dayjs'; -import useSWR, { useSWRConfig } from 'swr'; +import useSWR from 'swr'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import { Post, Integration } from '@prisma/client'; -import { useRouter, useSearchParams } from 'next/navigation'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; +import { useSearchParams } from 'next/navigation'; import isoWeek from 'dayjs/plugin/isoWeek'; import weekOfYear from 'dayjs/plugin/weekOfYear'; diff --git a/apps/frontend/src/components/launches/helpers/new.image.component.tsx b/apps/frontend/src/components/launches/helpers/new.image.component.tsx index 312d159c..3078dfc5 100644 --- a/apps/frontend/src/components/launches/helpers/new.image.component.tsx +++ b/apps/frontend/src/components/launches/helpers/new.image.component.tsx @@ -7,6 +7,7 @@ import { TextAreaTextApi, } from '@uiw/react-md-editor'; import { showMediaBox } from '@gitroom/frontend/components/media/media.component'; +import { loadVars } from '@gitroom/react/helpers/variable.context'; export const newImage: ICommand = { name: 'image', @@ -27,6 +28,7 @@ export const newImage: ICommand = { ), execute: (state: ExecuteState, api: TextAreaTextApi) => { + const {uploadDirectory, backendUrl} = loadVars(); let newSelectionRange = selectWord({ text: state.text, selection: state.selection, @@ -70,7 +72,7 @@ export const newImage: ICommand = { prefix: '![', suffix: `](${ media.path.indexOf('http') === -1 - ? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY}` + ? `${backendUrl}/${uploadDirectory}` : `` }${media.path})`, }); @@ -85,7 +87,7 @@ export const newImage: ICommand = { prefix: '![image', suffix: `](${ media.path.indexOf('http') === -1 - ? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY}` + ? `${backendUrl}/${uploadDirectory}` : `` }${media.path})`, }); diff --git a/apps/frontend/src/components/launches/polonto.tsx b/apps/frontend/src/components/launches/polonto.tsx index d80eb48d..763f9aef 100644 --- a/apps/frontend/src/components/launches/polonto.tsx +++ b/apps/frontend/src/components/launches/polonto.tsx @@ -1,3 +1,5 @@ +'use client'; + import { createContext, FC, @@ -17,9 +19,12 @@ import { Button } from '@gitroom/react/form/button'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import { PictureGeneratorSection } from '@gitroom/frontend/components/launches/polonto/polonto.picture.generation'; import { useUser } from '@gitroom/frontend/components/layout/user.context'; +import { loadVars } from '@gitroom/react/helpers/variable.context'; const store = createStore({ - key: process.env.NEXT_PUBLIC_POLOTNO!, + get key() { + return loadVars().plontoKey; + }, showCredit: false, }); diff --git a/apps/frontend/src/components/layout/layout.context.tsx b/apps/frontend/src/components/layout/layout.context.tsx index 451bd408..9e75b9f2 100644 --- a/apps/frontend/src/components/layout/layout.context.tsx +++ b/apps/frontend/src/components/layout/layout.context.tsx @@ -5,6 +5,7 @@ import { FetchWrapperComponent } from '@gitroom/helpers/utils/custom.fetch'; import { deleteDialog } from '@gitroom/react/helpers/delete.dialog'; import { isGeneral } from '@gitroom/react/helpers/is.general'; import { useReturnUrl } from '@gitroom/frontend/app/auth/return.url.component'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; export default function LayoutContext(params: { children: ReactNode }) { if (params?.children) { @@ -16,6 +17,7 @@ export default function LayoutContext(params: { children: ReactNode }) { } function LayoutContextInner(params: { children: ReactNode }) { const returnUrl = useReturnUrl(); + const {backendUrl, isGeneral} = useVariables(); const afterRequest = useCallback( async (url: string, options: RequestInit, response: Response) => { @@ -32,7 +34,7 @@ function LayoutContextInner(params: { children: ReactNode }) { } if (response?.headers?.get('onboarding')) { - window.location.href = isGeneral() + window.location.href = isGeneral ? '/launches?onboarding=true' : '/analytics?onboarding=true'; @@ -70,7 +72,7 @@ function LayoutContextInner(params: { children: ReactNode }) { return ( {params?.children || <>} diff --git a/apps/frontend/src/components/layout/layout.settings.tsx b/apps/frontend/src/components/layout/layout.settings.tsx index b444f2e6..500befb7 100644 --- a/apps/frontend/src/components/layout/layout.settings.tsx +++ b/apps/frontend/src/components/layout/layout.settings.tsx @@ -25,13 +25,13 @@ import { SettingsComponent } from '@gitroom/frontend/components/layout/settings. import { Onboarding } from '@gitroom/frontend/components/onboarding/onboarding'; import { Support } from '@gitroom/frontend/components/layout/support'; import { ContinueProvider } from '@gitroom/frontend/components/layout/continue.provider'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; import { CopilotKit } from '@copilotkit/react-core'; import { Impersonate } from '@gitroom/frontend/components/layout/impersonate'; import clsx from 'clsx'; import { BillingComponent } from '@gitroom/frontend/components/billing/billing.component'; import dynamic from 'next/dynamic'; import { NewSubscription } from '@gitroom/frontend/components/layout/new.subscription'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; const ModeComponent = dynamic( () => import('@gitroom/frontend/components/layout/mode.component'), { ssr: false } @@ -44,6 +44,8 @@ dayjs.extend(isBetween); export const LayoutSettings = ({ children }: { children: ReactNode }) => { const fetch = useFetch(); + const {isGeneral} = useVariables(); + const {backendUrl, billingEnabled} = useVariables(); const load = useCallback(async (path: string) => { return await (await fetch(path)).json(); }, []); @@ -62,7 +64,7 @@ export const LayoutSettings = ({ children }: { children: ReactNode }) => { @@ -84,7 +86,7 @@ export const LayoutSettings = ({ children }: { children: ReactNode }) => { >
Logo {
- {isGeneral() ? ( + {isGeneral ? ( { )}
- {user?.orgId && (user.tier !== 'FREE' || !isGeneral() || process.env.isBillingEnabled === "false") ? ( + {user?.orgId && (user.tier !== 'FREE' || !isGeneral || !billingEnabled) ? ( ) : (
@@ -139,7 +141,7 @@ export const LayoutSettings = ({ children }: { children: ReactNode }) => {
- {(user.tier === 'FREE' && isGeneral()) && process.env.isBillingEnabled === "true" ? ( + {(user.tier === 'FREE' && isGeneral) && billingEnabled ? ( <>

diff --git a/apps/frontend/src/components/layout/logout.component.tsx b/apps/frontend/src/components/layout/logout.component.tsx index 5ff59b78..03d49227 100644 --- a/apps/frontend/src/components/layout/logout.component.tsx +++ b/apps/frontend/src/components/layout/logout.component.tsx @@ -1,10 +1,13 @@ -import { isGeneral } from '@gitroom/react/helpers/is.general'; +'use client'; + import { useCallback } from 'react'; import { deleteDialog } from '@gitroom/react/helpers/delete.dialog'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; export const LogoutComponent = () => { const fetch = useFetch(); + const {isGeneral} = useVariables(); const logout = useCallback(async () => { if (await deleteDialog('Are you sure you want to logout?', 'Yes logout')) { await fetch('/user/logout', { @@ -15,5 +18,5 @@ export const LogoutComponent = () => { } }, []); - return
Logout from {isGeneral() ? 'Postiz' : 'Gitroom'}
; + return
Logout from {isGeneral ? 'Postiz' : 'Gitroom'}
; }; diff --git a/apps/frontend/src/components/layout/settings.component.tsx b/apps/frontend/src/components/layout/settings.component.tsx index f14fdfd1..a0d8e817 100644 --- a/apps/frontend/src/components/layout/settings.component.tsx +++ b/apps/frontend/src/components/layout/settings.component.tsx @@ -1,3 +1,5 @@ +'use client'; + import { useModals } from '@mantine/modals'; import React, { FC, Ref, useCallback, useEffect, useMemo } from 'react'; import { Input } from '@gitroom/react/form/input'; @@ -12,12 +14,13 @@ import { useToaster } from '@gitroom/react/toaster/toaster'; import { useSWRConfig } from 'swr'; import clsx from 'clsx'; import { TeamsComponent } from '@gitroom/frontend/components/settings/teams.component'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; import { useUser } from '@gitroom/frontend/components/layout/user.context'; import { LogoutComponent } from '@gitroom/frontend/components/layout/logout.component'; import { useSearchParams } from 'next/navigation'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; export const SettingsPopup: FC<{ getRef?: Ref }> = (props) => { + const {isGeneral} = useVariables(); const { getRef } = props; const fetch = useFetch(); const toast = useToaster(); @@ -191,7 +194,7 @@ export const SettingsPopup: FC<{ getRef?: Ref }> = (props) => {

)} - {!!user?.tier?.team_members && isGeneral() && } + {!!user?.tier?.team_members && isGeneral && } {showLogout && }
diff --git a/apps/frontend/src/components/layout/support.tsx b/apps/frontend/src/components/layout/support.tsx index ba8781af..95444377 100644 --- a/apps/frontend/src/components/layout/support.tsx +++ b/apps/frontend/src/components/layout/support.tsx @@ -2,11 +2,13 @@ import { EventEmitter } from 'events'; import { useEffect, useState } from 'react'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; export const supportEmitter = new EventEmitter(); export const Support = () => { const [show, setShow] = useState(true); + const {discordUrl} = useVariables(); useEffect(() => { supportEmitter.on('change', setShow); @@ -15,11 +17,11 @@ export const Support = () => { } }, []); - if (!process.env.NEXT_PUBLIC_DISCORD_SUPPORT || !show) return null + if (!discordUrl || !show) return null return (
window.open(process.env.NEXT_PUBLIC_DISCORD_SUPPORT)} + onClick={() => window.open(discordUrl)} >
{ const path = usePathname(); + const menuItems = useMenuItems(); const currentTitle = useMemo(() => { return menuItems.find(item => path.indexOf(item.path) > -1)?.name; }, [path]); diff --git a/apps/frontend/src/components/layout/top.menu.tsx b/apps/frontend/src/components/layout/top.menu.tsx index 216bc481..52b3711b 100644 --- a/apps/frontend/src/components/layout/top.menu.tsx +++ b/apps/frontend/src/components/layout/top.menu.tsx @@ -5,36 +5,36 @@ import Link from 'next/link'; import clsx from 'clsx'; import { usePathname } from 'next/navigation'; import { useUser } from '@gitroom/frontend/components/layout/user.context'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; -const general = isGeneral(); - -export const menuItems = [ - ...(!general - ? [ +export const useMenuItems = () => { + const {isGeneral} = useVariables(); + return [ + ...(!isGeneral + ? [ { name: 'Analytics', icon: 'analytics', path: '/analytics', }, ] - : []), - { - name: isGeneral() ? 'Calendar' : 'Launches', - icon: 'launches', - path: '/launches', - }, - ...(general - ? [ + : []), + { + name: isGeneral ? 'Calendar' : 'Launches', + icon: 'launches', + path: '/launches', + }, + ...(isGeneral + ? [ { name: 'Analytics', icon: 'analytics', path: '/analytics', }, ] - : []), - ...(!general - ? [ + : []), + ...(!isGeneral + ? [ { name: 'Settings', icon: 'settings', @@ -42,36 +42,39 @@ export const menuItems = [ role: ['ADMIN', 'SUPERADMIN'], }, ] - : []), - { - name: 'Marketplace', - icon: 'marketplace', - path: '/marketplace', - }, - { - name: 'Messages', - icon: 'messages', - path: '/messages', - }, - { - name: 'Billing', - icon: 'billing', - path: '/billing', - role: ['ADMIN', 'SUPERADMIN'], - requireBilling: true, - }, -]; + : []), + { + name: 'Marketplace', + icon: 'marketplace', + path: '/marketplace', + }, + { + name: 'Messages', + icon: 'messages', + path: '/messages', + }, + { + name: 'Billing', + icon: 'billing', + path: '/billing', + role: ['ADMIN', 'SUPERADMIN'], + requireBilling: true, + }, + ]; +} export const TopMenu: FC = () => { const path = usePathname(); const user = useUser(); + const {billingEnabled} = useVariables(); + const menuItems = useMenuItems(); return (
    {menuItems .filter((f) => { - if (f.requireBilling && process.env.isBillingEnabled === 'false') { + if (f.requireBilling && !billingEnabled) { return false; } if (f.role) { diff --git a/apps/frontend/src/components/onboarding/connect.channels.tsx b/apps/frontend/src/components/onboarding/connect.channels.tsx index de9a912c..1b820a64 100644 --- a/apps/frontend/src/components/onboarding/connect.channels.tsx +++ b/apps/frontend/src/components/onboarding/connect.channels.tsx @@ -1,3 +1,5 @@ +'use client'; + import React, { FC, useCallback, @@ -15,10 +17,11 @@ import Image from 'next/image'; import { Menu } from '@gitroom/frontend/components/launches/menu/menu'; import { ApiModal } from '@gitroom/frontend/components/launches/add.provider.component'; import { useRouter } from 'next/navigation'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; export const ConnectChannels: FC = () => { const fetch = useFetch(); + const {isGeneral} = useVariables(); const router = useRouter(); const [identifier, setIdentifier] = useState(undefined); const [popup, setPopups] = useState(undefined); @@ -158,7 +161,7 @@ export const ConnectChannels: FC = () => { ))}
- {!isGeneral() && ( + {!isGeneral && (
Publishing Platforms
diff --git a/apps/frontend/src/components/onboarding/onboarding.tsx b/apps/frontend/src/components/onboarding/onboarding.tsx index ec3c71a3..d28e4470 100644 --- a/apps/frontend/src/components/onboarding/onboarding.tsx +++ b/apps/frontend/src/components/onboarding/onboarding.tsx @@ -8,8 +8,7 @@ import { GithubOnboarding } from '@gitroom/frontend/components/onboarding/github import { SettingsPopup } from '@gitroom/frontend/components/layout/settings.component'; import { Button } from '@gitroom/react/form/button'; import { ConnectChannels } from '@gitroom/frontend/components/onboarding/connect.channels'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; -import { AddAccount } from '@gitroom/frontend/components/marketplace/seller'; +import { useVariables } from '@gitroom/react/helpers/variable.context'; export const Step: FC<{ step: number; @@ -116,7 +115,8 @@ const SkipOnboarding: FC = () => { }; const Welcome: FC = () => { const [seller, setSeller] = useState(false); - const [lastStep, setLastStep] = useState(isGeneral() ? 3 : 4); + const {isGeneral} = useVariables(); + const [lastStep, setLastStep] = useState(isGeneral ? 3 : 4); const [step, setStep] = useState(1); const ref = useRef(); const router = useRouter(); @@ -148,7 +148,7 @@ const Welcome: FC = () => { const sellPosts = useCallback(() => { nextStep()(); - setLastStep(isGeneral() ? 4 : 5); + setLastStep(isGeneral ? 4 : 5); setSeller(true); }, [step]); @@ -162,7 +162,7 @@ const Welcome: FC = () => {
- {!isGeneral() && ( + {!isGeneral && ( <> { )} - + {seller && ( <> @@ -204,7 +204,7 @@ const Welcome: FC = () => {
)} - {step === 2 && !isGeneral() && ( + {step === 2 && !isGeneral && (
@@ -213,7 +213,7 @@ const Welcome: FC = () => {
)} - {step === 3 - (isGeneral() ? 1 : 0) && ( + {step === 3 - (isGeneral ? 1 : 0) && (
@@ -222,7 +222,7 @@ const Welcome: FC = () => {
)} - {step === 4 - (isGeneral() ? 1 : 0) && ( + {step === 4 - (isGeneral ? 1 : 0) && (
success @@ -231,8 +231,8 @@ const Welcome: FC = () => { You are done, from here you can:
-
- {!isGeneral() && ( +
+ {!isGeneral && ( )} @@ -245,7 +245,7 @@ const Welcome: FC = () => {
)} - {step === 5 - (isGeneral() ? 1 : 0) && ( + {step === 5 - (isGeneral ? 1 : 0) && (
To sell posts you would have to:
    @@ -254,7 +254,7 @@ const Welcome: FC = () => {
- +
diff --git a/apps/frontend/src/components/settings/settings.component.tsx b/apps/frontend/src/components/settings/settings.component.tsx index 2ce48227..051604f1 100644 --- a/apps/frontend/src/components/settings/settings.component.tsx +++ b/apps/frontend/src/components/settings/settings.component.tsx @@ -8,11 +8,10 @@ import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import useSWR from 'swr'; import { LoadingComponent } from '@gitroom/frontend/components/layout/loading'; import { useRouter } from 'next/navigation'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; - -const general = isGeneral(); +import { useVariables } from '@gitroom/react/helpers/variable.context'; export const SettingsComponent = () => { + const {isGeneral} = useVariables(); const user = useUser(); const router = useRouter(); @@ -53,7 +52,7 @@ export const SettingsComponent = () => { return (
- {!general && ( + {!isGeneral && (

Your Git Repository

diff --git a/apps/frontend/src/middleware.ts b/apps/frontend/src/middleware.ts index 9a3a3cee..72c27f7a 100644 --- a/apps/frontend/src/middleware.ts +++ b/apps/frontend/src/middleware.ts @@ -2,7 +2,6 @@ import { NextResponse } from 'next/server'; import type { NextRequest } from 'next/server'; import { fetchBackend } from '@gitroom/helpers/utils/custom.fetch.func'; import { removeSubdomain } from '@gitroom/helpers/subdomain/subdomain.management'; -import { isGeneral } from '@gitroom/react/helpers/is.general'; // This function can be marked `async` if using `await` inside export async function middleware(request: NextRequest) { @@ -92,7 +91,7 @@ export async function middleware(request: NextRequest) { if (nextUrl.pathname === '/') { return NextResponse.redirect( - new URL(isGeneral() ? '/launches' : `/analytics`, nextUrl.href) + new URL(!!process.env.IS_GENERAL ? '/launches' : `/analytics`, nextUrl.href) ); } diff --git a/libraries/helpers/src/utils/custom.fetch.func.ts b/libraries/helpers/src/utils/custom.fetch.func.ts index b1372bee..f7f38c07 100644 --- a/libraries/helpers/src/utils/custom.fetch.func.ts +++ b/libraries/helpers/src/utils/custom.fetch.func.ts @@ -1,3 +1,5 @@ +import { loadVars } from '@gitroom/react/helpers/variable.context'; + export interface Params { baseUrl: string; beforeRequest?: (url: string, options: RequestInit) => Promise; @@ -45,5 +47,7 @@ export const customFetch = ( }; export const fetchBackend = customFetch({ - baseUrl: process.env.NEXT_PUBLIC_BACKEND_URL!, + get baseUrl() { + return loadVars().backendUrl; + }, }); diff --git a/libraries/helpers/src/utils/is.general.server.side.ts b/libraries/helpers/src/utils/is.general.server.side.ts new file mode 100644 index 00000000..c24b8dc9 --- /dev/null +++ b/libraries/helpers/src/utils/is.general.server.side.ts @@ -0,0 +1,3 @@ +export const isGeneralServerSide = () => { + return !!process.env.IS_GENERAL; +} \ No newline at end of file diff --git a/libraries/react-shared-libraries/src/helpers/is.general.tsx b/libraries/react-shared-libraries/src/helpers/is.general.tsx index 1b18fa70..90fa96fe 100644 --- a/libraries/react-shared-libraries/src/helpers/is.general.tsx +++ b/libraries/react-shared-libraries/src/helpers/is.general.tsx @@ -1,3 +1,5 @@ +import { loadVars } from './variable.context'; + export const isGeneral = () => { - return process.env.isGeneral === 'true'; + return typeof process.env.IS_GENERAL === 'undefined' ? !!process.env.IS_GENERAL : loadVars?.()?.isGeneral; } \ No newline at end of file diff --git a/libraries/react-shared-libraries/src/helpers/use.media.directory.ts b/libraries/react-shared-libraries/src/helpers/use.media.directory.ts index 39157d56..7a989f26 100644 --- a/libraries/react-shared-libraries/src/helpers/use.media.directory.ts +++ b/libraries/react-shared-libraries/src/helpers/use.media.directory.ts @@ -1,11 +1,13 @@ import {useCallback} from "react"; +import { useVariables } from './variable.context'; export const useMediaDirectory = () => { + const {backendUrl, uploadDirectory} = useVariables(); const set = useCallback((path: string) => { if (path.indexOf('https') === 0) { return path; } - return `${process.env.NEXT_PUBLIC_BACKEND_URL}/${process.env.NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY}${path}`; + return `${backendUrl}/${uploadDirectory}${path}`; }, []); return { diff --git a/libraries/react-shared-libraries/src/helpers/variable.context.tsx b/libraries/react-shared-libraries/src/helpers/variable.context.tsx new file mode 100644 index 00000000..6fb98bb0 --- /dev/null +++ b/libraries/react-shared-libraries/src/helpers/variable.context.tsx @@ -0,0 +1,48 @@ +'use client'; + +import { createContext, FC, ReactNode, useContext, useEffect } from 'react'; + +interface VariableContextInterface { + billingEnabled: boolean; + isGeneral: boolean; + frontEndUrl: string; + plontoKey: string; + backendUrl: string; + discordUrl: string; + uploadDirectory: string; +} +const VariableContext = createContext({ + billingEnabled: false, + isGeneral: true, + frontEndUrl: '', + plontoKey: '', + backendUrl: '', + discordUrl: '', + uploadDirectory: '', +} as VariableContextInterface); + +export const VariableContextComponent: FC< + VariableContextInterface & { children: ReactNode } +> = (props) => { + const { children, ...otherProps } = props; + useEffect(() => { + if (typeof window !== 'undefined') { + // @ts-ignore + window.vars = otherProps; + } + }, []); + return ( + + {children} + + ); +}; + +export const useVariables = () => { + return useContext(VariableContext); +} + +export const loadVars = () => { + // @ts-ignore + return window.vars as VariableContextInterface; +}