From a202637b49d685518381fc2d2cc0faf3c378a1b9 Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sun, 15 Dec 2024 09:20:28 +0000 Subject: [PATCH 1/7] site name env --- src/env.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/env.mjs b/src/env.mjs index 49511e4e..9b05930c 100644 --- a/src/env.mjs +++ b/src/env.mjs @@ -28,6 +28,7 @@ const server = z.object({ const client = z.object({ // NEXT_PUBLIC_CLIENTVAR: z.string().min(1), NEXT_PUBLIC_APP_VERSION: z.string().optional(), + NEXT_PUBLIC_SITE_NAME: z.string().optional(), }); /** @@ -42,6 +43,7 @@ const processEnv = { NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET, NEXTAUTH_URL: process.env.NEXTAUTH_URL, NEXT_PUBLIC_APP_VERSION: process.env.NEXT_PUBLIC_APP_VERSION, + NEXT_PUBLIC_SITE_NAME: process.env.NEXT_PUBLIC_SITE_NAME, // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR, }; From 66d15acd8569c94c8aa6d56ceefe77c9a4986c1e Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sun, 15 Dec 2024 09:29:42 +0000 Subject: [PATCH 2/7] dockerfile arg --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index 14aa6016..b1d740e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,7 @@ RUN \ FROM base AS builder ARG NEXT_PUBLIC_APP_VERSION +ARG NEXT_PUBLIC_SITE_NAME WORKDIR /app COPY --from=deps /app/node_modules ./node_modules @@ -58,6 +59,9 @@ ARG NEXTAUTH_SECRET ARG NEXT_PUBLIC_APP_VERSION ENV NEXT_PUBLIC_APP_VERSION ${NEXT_PUBLIC_APP_VERSION} +ARG NEXT_PUBLIC_SITE_NAME +ENV NEXT_PUBLIC_SITE_NAME ${NEXT_PUBLIC_SITE_NAME} + ENV NODE_ENV production # Disable telemetry during runtime. From d396514caef022956d752dbe11babaa6da9da9cd Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sun, 15 Dec 2024 09:38:20 +0000 Subject: [PATCH 3/7] env --- src/utils/global.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/global.ts b/src/utils/global.ts index f720aa70..851f2d09 100644 --- a/src/utils/global.ts +++ b/src/utils/global.ts @@ -3,6 +3,6 @@ import { env } from "~/env.mjs"; // If it is not set, use the default value "ZTnet". -export const globalSiteTitle = process.env.NEXT_PUBLIC_SITE_NAME || "ZTNET"; +export const globalSiteTitle = env.NEXT_PUBLIC_SITE_NAME || "ZTNET"; export const globalSiteVersion = env.NEXT_PUBLIC_APP_VERSION || "development"; From e626b66fb64da56fb82e47929b3afa72fed8598e Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sun, 15 Dec 2024 10:52:20 +0000 Subject: [PATCH 4/7] added option to set sitename from the admin menu. removed from env --- .devcontainer/init-cmd.sh | 1 - .github/workflows/main_build.yml | 1 - .github/workflows/pull_request.yml | 1 - Dockerfile | 4 --- docs/docs/Installation/FreeBSD.md | 1 - docs/docs/Installation/options.md | 6 ---- install.ztnet/bash/ztnet.sh | 2 -- .../20241215102802_sitename/migration.sql | 2 ++ prisma/schema.prisma | 5 +-- src/components/layouts/header.tsx | 6 ++-- src/env.mjs | 2 -- src/locales/en/common.json | 4 +++ src/pages/admin/index.tsx | 5 +-- src/pages/admin/settings/index.tsx | 31 +++++++++++++++++++ src/pages/auth/forgotPassword/index.tsx | 6 ++-- src/pages/auth/forgotPassword/reset/index.tsx | 5 +-- src/pages/auth/login/index.tsx | 7 +++-- src/pages/auth/mfaRecovery/index.tsx | 7 +++-- src/pages/auth/mfaRecovery/reset/index.tsx | 5 +-- src/pages/auth/register/index.tsx | 6 ++-- src/pages/auth/verifyEmail/index.tsx | 6 ++-- src/pages/central/[id].tsx | 8 +++-- src/pages/central/index.tsx | 13 ++++---- src/pages/dashboard/index.tsx | 8 +++-- src/pages/network/[id].tsx | 8 +++-- src/pages/network/index.tsx | 6 ++-- src/pages/organization/[orgid].tsx | 6 ++-- src/pages/organization/[orgid]/[id].tsx | 6 ++-- .../organization/[orgid]/admin/index.tsx | 5 +-- .../[orgid]/admin/invite/index.tsx | 5 ++- .../[orgid]/admin/settings/index.tsx | 4 +-- .../[orgid]/admin/webhooks/index.tsx | 5 +-- src/pages/user-settings/index.tsx | 6 ++-- src/server/api/routers/adminRoute.ts | 1 + src/server/api/routers/settingsRouter.ts | 14 ++++++++- src/utils/global.ts | 3 -- 36 files changed, 132 insertions(+), 79 deletions(-) create mode 100644 prisma/migrations/20241215102802_sitename/migration.sql diff --git a/.devcontainer/init-cmd.sh b/.devcontainer/init-cmd.sh index a0c3b916..741bdb89 100755 --- a/.devcontainer/init-cmd.sh +++ b/.devcontainer/init-cmd.sh @@ -6,7 +6,6 @@ set -e # cat << EOF > .env # DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?schema=public # ZT_ADDR=${ZT_ADDR} -# NEXT_PUBLIC_SITE_NAME=${NEXT_PUBLIC_SITE_NAME} # EOF until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -c '\q'; do diff --git a/.github/workflows/main_build.yml b/.github/workflows/main_build.yml index 4885c855..e6472512 100644 --- a/.github/workflows/main_build.yml +++ b/.github/workflows/main_build.yml @@ -31,7 +31,6 @@ jobs: echo "DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres?schema=public" >> .env echo "NEXTAUTH_SECRET=dummy_key" >> .env echo "NEXTAUTH_URL=http://localhost:3000" >> .env - echo "NEXT_PUBLIC_SITE_NAME=ZTnet" >> .env echo "NEXT_PUBLIC_APP_VERSION=" >> .env echo "IS_GITHUB_ACTION=true" >> .env diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index dcf3bdba..b5a0ddcf 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -20,7 +20,6 @@ jobs: echo "DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres?schema=public" >> .env echo "NEXTAUTH_SECRET=dummy_key" >> .env echo "NEXTAUTH_URL=http://localhost:3000" >> .env - echo "NEXT_PUBLIC_SITE_NAME=ZTnet" >> .env echo "NEXT_PUBLIC_APP_VERSION=" >> .env echo "IS_GITHUB_ACTION=true" >> .env diff --git a/Dockerfile b/Dockerfile index b1d740e3..14aa6016 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,6 @@ RUN \ FROM base AS builder ARG NEXT_PUBLIC_APP_VERSION -ARG NEXT_PUBLIC_SITE_NAME WORKDIR /app COPY --from=deps /app/node_modules ./node_modules @@ -59,9 +58,6 @@ ARG NEXTAUTH_SECRET ARG NEXT_PUBLIC_APP_VERSION ENV NEXT_PUBLIC_APP_VERSION ${NEXT_PUBLIC_APP_VERSION} -ARG NEXT_PUBLIC_SITE_NAME -ENV NEXT_PUBLIC_SITE_NAME ${NEXT_PUBLIC_SITE_NAME} - ENV NODE_ENV production # Disable telemetry during runtime. diff --git a/docs/docs/Installation/FreeBSD.md b/docs/docs/Installation/FreeBSD.md index 15294b3c..1a87cf21 100644 --- a/docs/docs/Installation/FreeBSD.md +++ b/docs/docs/Installation/FreeBSD.md @@ -81,7 +81,6 @@ setenv PRISMA_QUERY_ENGINE_LIBRARY /root/prisma-engines/target/release/libquery_ ``` DATABASE_URL=postgresql://postgres:postgres@localhost:5432/ztnet?schema=public ZT_ADDR=http://127.0.0.1:9993 - NEXT_PUBLIC_SITE_NAME=ZTnet NEXTAUTH_URL="http://ZTNET_Controller_Web_UI_IP_ADDRESS:3000" NEXTAUTH_SECRET="random_secret" ``` diff --git a/docs/docs/Installation/options.md b/docs/docs/Installation/options.md index 0a06063d..2288cda3 100644 --- a/docs/docs/Installation/options.md +++ b/docs/docs/Installation/options.md @@ -19,7 +19,6 @@ To use these environment variables in a Docker Compose setup, define them in you services: ztnet: environment: - NEXT_PUBLIC_SITE_NAME: "ZTNET" NEXTAUTH_URL: http://your_server_ip:3000 # ... other environment variables ... ``` @@ -29,7 +28,6 @@ Edit the `.env` file in `/opt/ztnet` to set the environment variables. For examp ```bash DATABASE_URL=postgresql://postgres:postgres@postgres:5432/ztnet?schema=public -NEXT_PUBLIC_SITE_NAME=ZTNET NEXTAUTH_URL=http://your_server_ip:3000 ``` @@ -37,10 +35,6 @@ NEXTAUTH_URL=http://your_server_ip:3000 Configure the application using the following environment variables: ### ZTNET Configuration -- `NEXT_PUBLIC_SITE_NAME` - - Description: Site name. - - Default: `ZTNET`. - - `HOSTNAME` - Description: Hostname of the server. Only available in standalone mode. - Default: `0.0.0.0`. diff --git a/install.ztnet/bash/ztnet.sh b/install.ztnet/bash/ztnet.sh index c5fb0482..819d59a5 100755 --- a/install.ztnet/bash/ztnet.sh +++ b/install.ztnet/bash/ztnet.sh @@ -728,7 +728,6 @@ check_existing_env_handler() { # Define default values for variables declare -A env_vars=( ["NEXTAUTH_SECRET"]=$(openssl rand -hex 32) - ["NEXT_PUBLIC_SITE_NAME"]="ZTnet" ["NEXTAUTH_URL"]="${server_ip}:3000" ["ZT_ADDR"]= ["ZT_SECRET"]= @@ -1000,7 +999,6 @@ NEXT_PUBLIC_APP_VERSION="${CUSTOM_VERSION:-$latestTag}" DATABASE_URL="postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@127.0.0.1:5432/$POSTGRES_DB?schema=public" set_env_temp_var "DATABASE_URL" "$DATABASE_URL" set_env_temp_var "ZT_ADDR" "$ZT_ADDR" -set_env_temp_var "NEXT_PUBLIC_SITE_NAME" "$NEXT_PUBLIC_SITE_NAME" set_env_temp_var "NEXTAUTH_URL" "$NEXTAUTH_URL" set_env_temp_var "NEXT_PUBLIC_APP_VERSION" "$NEXT_PUBLIC_APP_VERSION" set_env_temp_var "NEXTAUTH_SECRET" "$NEXTAUTH_SECRET" diff --git a/prisma/migrations/20241215102802_sitename/migration.sql b/prisma/migrations/20241215102802_sitename/migration.sql new file mode 100644 index 00000000..40522cfe --- /dev/null +++ b/prisma/migrations/20241215102802_sitename/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "GlobalOptions" ADD COLUMN "siteName" TEXT NOT NULL DEFAULT 'ZTNET'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4cf912cd..672c1510 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -20,8 +20,9 @@ enum Role { } model GlobalOptions { - id Int @id @default(autoincrement()) - + id Int @id @default(autoincrement()) + // Site + siteName String @default("ZTNET") // Registration enableRegistration Boolean @default(true) firstUserRegistration Boolean @default(true) // not in use, will be removed at a later stage diff --git a/src/components/layouts/header.tsx b/src/components/layouts/header.tsx index 7b720b83..65862281 100644 --- a/src/components/layouts/header.tsx +++ b/src/components/layouts/header.tsx @@ -1,10 +1,10 @@ import { useSession } from "next-auth/react"; import { useTheme } from "next-themes"; -import { globalSiteTitle } from "~/utils/global"; import { useSidebarStore } from "~/utils/store"; import ZtnetLogo from "docs/images/logo/ztnet_200x178.png"; import Link from "next/link"; import { forwardRef } from "react"; +import { api } from "~/utils/api"; const Themes = [ "light", @@ -26,6 +26,8 @@ const Header = forwardRef>( const { theme, setTheme } = useTheme(); const { toggle, open } = useSidebarStore(); + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + return (
>( src={ZtnetLogo.src} /> - {globalSiteTitle} + {globalOptions?.siteName || "ZTNET"} diff --git a/src/env.mjs b/src/env.mjs index 9b05930c..49511e4e 100644 --- a/src/env.mjs +++ b/src/env.mjs @@ -28,7 +28,6 @@ const server = z.object({ const client = z.object({ // NEXT_PUBLIC_CLIENTVAR: z.string().min(1), NEXT_PUBLIC_APP_VERSION: z.string().optional(), - NEXT_PUBLIC_SITE_NAME: z.string().optional(), }); /** @@ -43,7 +42,6 @@ const processEnv = { NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET, NEXTAUTH_URL: process.env.NEXTAUTH_URL, NEXT_PUBLIC_APP_VERSION: process.env.NEXT_PUBLIC_APP_VERSION, - NEXT_PUBLIC_SITE_NAME: process.env.NEXT_PUBLIC_SITE_NAME, // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR, }; diff --git a/src/locales/en/common.json b/src/locales/en/common.json index 449b2653..d6100e71 100644 --- a/src/locales/en/common.json +++ b/src/locales/en/common.json @@ -441,6 +441,10 @@ }, "admin": { "settings": { + "application": { + "siteName": "Site Name", + "description": "Customize the name of your site to better align with your brand" + }, "publicPages": { "sectionTitle": "Public Pages", "description": "Customize the text displayed on your login and registration pages to better align with your brand or provide specific instructions to your users." diff --git a/src/pages/admin/index.tsx b/src/pages/admin/index.tsx index a14dbe13..9e9d9729 100644 --- a/src/pages/admin/index.tsx +++ b/src/pages/admin/index.tsx @@ -3,7 +3,6 @@ import { useRouter } from "next/router"; import { LayoutAdminAuthenticated } from "~/components/layouts/layout"; import Users from "./users"; import Controller from "./controller"; -import { globalSiteTitle } from "~/utils/global"; import Mail from "./mail"; import Notification from "./notification"; import { useTranslations } from "next-intl"; @@ -13,9 +12,11 @@ import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; import MetaTags from "~/components/shared/metaTags"; import Link from "next/link"; +import { api } from "~/utils/api"; const AdminSettings = ({ orgIds }) => { - const title = `${globalSiteTitle} - Admin Settings`; + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const title = `${globalOptions?.siteName} - Admin Settings`; const router = useRouter(); const { tab = "members" } = router.query; diff --git a/src/pages/admin/settings/index.tsx b/src/pages/admin/settings/index.tsx index 0edd625c..3fc2df06 100644 --- a/src/pages/admin/settings/index.tsx +++ b/src/pages/admin/settings/index.tsx @@ -37,6 +37,37 @@ const Settings = () => { return (
+ +
+

{t("settings.application.description")}

+
+
+ + new Promise((resolve) => { + setWelcomeMessage(params); + resolve(true); + }) + } + /> +
+
{ + const { data: globalOptions } = api.settings.getPublicOptions.useQuery(); + const t = useTranslations(); - const title = `${globalSiteTitle} - Forgot Password`; + const title = `${globalOptions?.siteName} - Forgot Password`; return (
diff --git a/src/pages/auth/forgotPassword/reset/index.tsx b/src/pages/auth/forgotPassword/reset/index.tsx index fed8e691..3d6d7c0d 100644 --- a/src/pages/auth/forgotPassword/reset/index.tsx +++ b/src/pages/auth/forgotPassword/reset/index.tsx @@ -4,7 +4,6 @@ import { api } from "~/utils/api"; import { toast } from "react-hot-toast"; import { type ErrorData, type ZodErrorFieldErrors } from "~/types/errorHandling"; import Head from "next/head"; -import { globalSiteTitle } from "~/utils/global"; import FormInput from "~/components/auth/formInput"; import FormSubmitButtons from "~/components/auth/formSubmitButton"; import { useTranslations } from "next-intl"; @@ -18,6 +17,8 @@ const ForgotPassword = () => { const { token } = router.query; const [state, setState] = useState({ password: "", newPassword: "" }); + const { data: globalOptions } = api.settings.getPublicOptions.useQuery(); + const { mutate: resetPassword, isLoading } = api.auth.changePasswordFromJwt.useMutation(); const { data: tokenData, isLoading: validateTokenLoading } = @@ -79,7 +80,7 @@ const ForgotPassword = () => { if (validateTokenLoading || !tokenData || tokenData.error) { return null; } - const title = `${globalSiteTitle} - Reset Password`; + const title = `${globalOptions?.siteName} - Reset Password`; return (
diff --git a/src/pages/auth/login/index.tsx b/src/pages/auth/login/index.tsx index 2e5c2cdf..5182fc43 100644 --- a/src/pages/auth/login/index.tsx +++ b/src/pages/auth/login/index.tsx @@ -12,13 +12,14 @@ import { useRouter } from "next/router"; import classNames from "classnames"; import { ErrorCode, getErrorMessage } from "~/utils/errorCode"; import { useTranslations } from "next-intl"; -import { globalSiteTitle } from "~/utils/global"; - -const title = `${globalSiteTitle} - Sign In`; const Login = ({ oauthExclusiveLogin, oauthEnabled }) => { const t = useTranslations(); const currentYear = new Date().getFullYear(); + + const { data: globalOptions } = api.settings.getPublicOptions.useQuery(); + const title = `${globalOptions?.siteName} - Sign In`; + const { data: options, isLoading: loadingRegistration } = api.public.registrationAllowed.useQuery(); const router = useRouter(); diff --git a/src/pages/auth/mfaRecovery/index.tsx b/src/pages/auth/mfaRecovery/index.tsx index 0b9b1c7c..32d2b298 100644 --- a/src/pages/auth/mfaRecovery/index.tsx +++ b/src/pages/auth/mfaRecovery/index.tsx @@ -7,11 +7,14 @@ import Link from "next/link"; import React, { ReactElement } from "react"; import MfaRecoveryForm from "~/components/auth/mfaRecoveryForm"; import { LayoutPublic } from "~/components/layouts/layout"; -import { globalSiteTitle } from "~/utils/global"; +import { api } from "~/utils/api"; const MfaRecovery = () => { const t = useTranslations(); - const title = `${globalSiteTitle} - Forgot Password`; + + const { data: globalOptions } = api.settings.getPublicOptions.useQuery(); + + const title = `${globalOptions?.siteName} - Forgot Password`; return (
diff --git a/src/pages/auth/mfaRecovery/reset/index.tsx b/src/pages/auth/mfaRecovery/reset/index.tsx index 823cbe60..e05df34f 100644 --- a/src/pages/auth/mfaRecovery/reset/index.tsx +++ b/src/pages/auth/mfaRecovery/reset/index.tsx @@ -5,7 +5,6 @@ import { Session } from "next-auth"; import { toast } from "react-hot-toast"; import { type ErrorData, type ZodErrorFieldErrors } from "~/types/errorHandling"; import Head from "next/head"; -import { globalSiteTitle } from "~/utils/global"; import FormInput from "~/components/auth/formInput"; import FormSubmitButtons from "~/components/auth/formSubmitButton"; import { ErrorCode } from "~/utils/errorCode"; @@ -18,6 +17,8 @@ const MfaRecoveryReset = () => { const router = useRouter(); const { token } = router.query; const [state, setState] = useState({ email: "", password: "", recoveryCode: "" }); + + const { data: globalOptions } = api.settings.getPublicOptions.useQuery(); const { mutate: resetMfa, isLoading } = api.mfaAuth.mfaResetValidation.useMutation(); const { data: tokenData, isLoading: validateTokenLoading } = @@ -86,7 +87,7 @@ const MfaRecoveryReset = () => { setState({ ...state, [e.target.name]: e.target.value }); }; - const title = `${globalSiteTitle} - Reset MFA`; + const title = `${globalOptions?.siteName} - Reset MFA`; if (validateTokenLoading || !tokenData) { return null; } diff --git a/src/pages/auth/register/index.tsx b/src/pages/auth/register/index.tsx index ec651e8f..2598a39e 100644 --- a/src/pages/auth/register/index.tsx +++ b/src/pages/auth/register/index.tsx @@ -6,14 +6,16 @@ import React, { ReactElement } from "react"; import { LayoutPublic } from "~/components/layouts/layout"; import RegisterForm from "~/components/auth/registerForm"; import { prisma } from "~/server/db"; -import { globalSiteTitle } from "~/utils/global"; import { useRouter } from "next/router"; import RegisterOrganizationInviteForm from "~/components/auth/registerOrganizationInvite"; import Link from "next/link"; import { useTranslations } from "next-intl"; +import { api } from "~/utils/api"; const Register = () => { - const title = `${globalSiteTitle} - Sign Up`; + const { data: globalOptions } = api.settings.getPublicOptions.useQuery(); + const title = `${globalOptions?.siteName} - Sign Up`; + const t = useTranslations(); const router = useRouter(); const { organizationInvite } = router.query as { organizationInvite?: string }; diff --git a/src/pages/auth/verifyEmail/index.tsx b/src/pages/auth/verifyEmail/index.tsx index bcc03807..13bbcb8c 100644 --- a/src/pages/auth/verifyEmail/index.tsx +++ b/src/pages/auth/verifyEmail/index.tsx @@ -3,21 +3,21 @@ import { api } from "~/utils/api"; import { Session } from "next-auth"; import { toast } from "react-hot-toast"; import Head from "next/head"; -import { globalSiteTitle } from "~/utils/global"; import { ErrorCode } from "~/utils/errorCode"; import { useTranslations } from "next-intl"; import { GetServerSideProps, GetServerSidePropsContext } from "next"; import { getSession } from "next-auth/react"; import { useState, useEffect } from "react"; -const title = `${globalSiteTitle} - VerifyEmail`; - const VerifyEmail = () => { const t = useTranslations(); const router = useRouter(); const { token } = router.query; const [redirectCountdown, setRedirectCountdown] = useState(5); + const { data: globalOptions } = api.settings.getPublicOptions.useQuery(); + const title = `${globalOptions?.siteName} - VerifyEmail`; + const { data: tokenData, isLoading: validateTokenLoading } = api.auth.validateEmailVerificationToken.useQuery( { diff --git a/src/pages/central/[id].tsx b/src/pages/central/[id].tsx index bb404249..fd525f60 100644 --- a/src/pages/central/[id].tsx +++ b/src/pages/central/[id].tsx @@ -20,7 +20,6 @@ import { useTranslations } from "next-intl"; import NetworkDescription from "../../components/networkByIdPage/networkDescription"; import NetworkName from "~/components/networkByIdPage/networkName"; import Head from "next/head"; -import { globalSiteTitle } from "~/utils/global"; import { NetworkDns } from "~/components/networkByIdPage/networkDns"; import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; @@ -43,6 +42,9 @@ const CentralNetworkById = ({ orgIds }) => { // }); const callModal = useModalStore((state) => state.callModal); const { query, push: router } = useRouter(); + + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const { mutate: deleteNetwork } = api.network.deleteNetwork.useMutation(); const { data: networkById, @@ -58,10 +60,10 @@ const CentralNetworkById = ({ orgIds }) => { useOrganizationWebsocket(orgIds); - const pageTitle = `${globalSiteTitle} - ${networkById?.network?.name}`; + const pageTitle = `${globalOptions?.siteName} - ${networkById?.network?.name}`; if (loadingNetwork) { - const pageTitleLoading = `${globalSiteTitle}`; + const pageTitleLoading = `${globalOptions?.siteName}`; // add loading progress bar to center of page, vertially and horizontally return ( <> diff --git a/src/pages/central/index.tsx b/src/pages/central/index.tsx index 71bb2bee..d63e1359 100644 --- a/src/pages/central/index.tsx +++ b/src/pages/central/index.tsx @@ -4,15 +4,12 @@ import { LayoutAuthenticated } from "~/components/layouts/layout"; import type { NextPageWithLayout } from "../_app"; import { api } from "~/utils/api"; import { CentralNetworkTable } from "../../components/networkPage/centralNetworkTable"; -import { globalSiteTitle } from "~/utils/global"; import { useTranslations } from "next-intl"; import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; import { useRouter } from "next/router"; -const title = `${globalSiteTitle} - Zerotier Central`; - -const HeadSection = () => ( +const HeadSection = ({ title }: { title: string }) => ( {title} @@ -32,6 +29,10 @@ const CentralNetworks: NextPageWithLayout = ({ orgIds }: IProps) => { const b = useTranslations("commonButtons"); const t = useTranslations("networks"); const router = useRouter(); + + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const title = `${globalOptions?.siteName} - Zerotier Central`; + const { data: centralNetworks, isLoading, @@ -61,7 +62,7 @@ const CentralNetworks: NextPageWithLayout = ({ orgIds }: IProps) => { // add loading progress bar to center of page, vertially and horizontally return ( <> - +

@@ -73,7 +74,7 @@ const CentralNetworks: NextPageWithLayout = ({ orgIds }: IProps) => { return ( <> - +
ZT Central Networks
diff --git a/src/pages/dashboard/index.tsx b/src/pages/dashboard/index.tsx index a9ddcdf5..e0d46b99 100644 --- a/src/pages/dashboard/index.tsx +++ b/src/pages/dashboard/index.tsx @@ -2,9 +2,9 @@ import Head from "next/head"; import { type ReactElement } from "react"; import { LayoutAuthenticated } from "~/components/layouts/layout"; import type { NextPageWithLayout } from "../_app"; -import { globalSiteTitle } from "~/utils/global"; import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; +import { api } from "~/utils/api"; type OrganizationId = { id: string; @@ -14,7 +14,9 @@ interface IProps { } const Dashboard: NextPageWithLayout = ({ orgIds }: IProps) => { - const title = `${globalSiteTitle} - Dashboard`; + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const title = `${globalOptions?.siteName} - Dashboard`; + useOrganizationWebsocket(orgIds); return ( @@ -29,7 +31,7 @@ const Dashboard: NextPageWithLayout = ({ orgIds }: IProps) => {
{/*
test
*/}
- Welcome to {globalSiteTitle} + Welcome to {globalOptions?.siteName}
{/* grid with cards */}
diff --git a/src/pages/network/[id].tsx b/src/pages/network/[id].tsx index 6eb4b718..10e62348 100644 --- a/src/pages/network/[id].tsx +++ b/src/pages/network/[id].tsx @@ -22,7 +22,6 @@ import { useTranslations } from "next-intl"; import NetworkName from "~/components/networkByIdPage/networkName"; import NetworkDescription from "~/components/networkByIdPage/networkDescription"; import Head from "next/head"; -import { globalSiteTitle } from "~/utils/global"; import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; import NetworkLoadingSkeleton from "~/components/shared/networkLoadingSkeleton"; @@ -56,6 +55,9 @@ const NetworkById = ({ orgIds }: IProps) => { const callModal = useModalStore((state) => state.callModal); const { query, push: router } = useRouter(); + + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const { mutate: deleteNetwork } = api.network.deleteNetwork.useMutation(); const { data: networkById, @@ -69,7 +71,7 @@ const NetworkById = ({ orgIds }: IProps) => { { enabled: !!query.id, refetchInterval: 10000 }, ); const { network, members = [] } = networkById || {}; - const pageTitle = `${globalSiteTitle} - ${network?.name}`; + const pageTitle = `${globalOptions?.siteName} - ${network?.name}`; if (errorNetwork) { return ( <> @@ -110,7 +112,7 @@ const NetworkById = ({ orgIds }: IProps) => { ); } if (loadingNetwork) { - const pageTitleLoading = `${globalSiteTitle}`; + const pageTitleLoading = `${globalOptions?.siteName}`; // add loading progress bar to center of page, vertially and horizontally return ( <> diff --git a/src/pages/network/index.tsx b/src/pages/network/index.tsx index 221c66b1..9c484937 100644 --- a/src/pages/network/index.tsx +++ b/src/pages/network/index.tsx @@ -3,7 +3,6 @@ import { LayoutAuthenticated } from "~/components/layouts/layout"; import type { NextPageWithLayout } from "../_app"; import { api } from "~/utils/api"; import { NetworkTable } from "../../components/networkPage/networkTable"; -import { globalSiteTitle } from "~/utils/global"; import { useTranslations } from "next-intl"; import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; @@ -25,13 +24,14 @@ interface IProps { user: User; } -const title = `${globalSiteTitle} - Local Controller`; - const Networks: NextPageWithLayout = ({ orgIds, user }: IProps) => { const b = useTranslations("commonButtons"); const t = useTranslations("networks"); const router = useRouter(); + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const title = `${globalOptions?.siteName} - Local Controller`; + const handleApiError = useTrpcApiErrorHandler(); const handleApiSuccess = useTrpcApiSuccessHandler(); diff --git a/src/pages/organization/[orgid].tsx b/src/pages/organization/[orgid].tsx index 7af8e863..35c67018 100644 --- a/src/pages/organization/[orgid].tsx +++ b/src/pages/organization/[orgid].tsx @@ -12,15 +12,12 @@ import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; import MetaTags from "~/components/shared/metaTags"; import NetworkLoadingSkeleton from "~/components/shared/networkLoadingSkeleton"; -import { globalSiteTitle } from "~/utils/global"; import cn from "classnames"; import { useTrpcApiErrorHandler, useTrpcApiSuccessHandler, } from "~/hooks/useTrpcApiHandler"; -const title = `${globalSiteTitle} - Organization`; - const OrganizationById = ({ user, orgIds }) => { const b = useTranslations("commonButtons"); const t = useTranslations("organization"); @@ -32,6 +29,9 @@ const OrganizationById = ({ user, orgIds }) => { const handleApiError = useTrpcApiErrorHandler(); const handleApiSuccess = useTrpcApiSuccessHandler(); + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const title = `${globalOptions?.siteName} - Organization`; + useOrganizationWebsocket(orgIds); const { data: meOrgRole } = api.org.getOrgUserRoleById.useQuery({ diff --git a/src/pages/organization/[orgid]/[id].tsx b/src/pages/organization/[orgid]/[id].tsx index cb0f55d1..4dc3cc54 100644 --- a/src/pages/organization/[orgid]/[id].tsx +++ b/src/pages/organization/[orgid]/[id].tsx @@ -21,7 +21,6 @@ import { InviteMemberByMail } from "~/components/networkByIdPage/inviteMemberbyM import { useTranslations } from "next-intl"; import NetworkName from "~/components/networkByIdPage/networkName"; import NetworkDescription from "~/components/networkByIdPage/networkDescription"; -import { globalSiteTitle } from "~/utils/global"; import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; import NetworkLoadingSkeleton from "~/components/shared/networkLoadingSkeleton"; @@ -47,6 +46,7 @@ const OrganizationNetworkById = ({ orgIds }: IProps) => { useOrganizationWebsocket(orgIds); + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); const { mutate: deleteNetwork } = api.network.deleteNetwork.useMutation(); const { data: networkById, @@ -59,7 +59,7 @@ const OrganizationNetworkById = ({ orgIds }: IProps) => { { enabled: !!query.id, refetchInterval: 10000 }, ); const { network, members = [] } = networkById || {}; - const pageTitle = `${globalSiteTitle} - ${network?.name}`; + const pageTitle = `${globalOptions?.siteName} - ${network?.name}`; if (errorNetwork) { return ( @@ -102,7 +102,7 @@ const OrganizationNetworkById = ({ orgIds }: IProps) => { } if (loadingNetwork) { - const pageTitleLoading = `${globalSiteTitle}`; + const pageTitleLoading = `${globalOptions?.siteName}`; // add loading progress bar to center of page, vertially and horizontally return ( <> diff --git a/src/pages/organization/[orgid]/admin/index.tsx b/src/pages/organization/[orgid]/admin/index.tsx index ecd5392e..c77263c5 100644 --- a/src/pages/organization/[orgid]/admin/index.tsx +++ b/src/pages/organization/[orgid]/admin/index.tsx @@ -1,7 +1,6 @@ import React, { type ReactElement } from "react"; import { useRouter } from "next/router"; import { LayoutOrganizationAuthenticated } from "~/components/layouts/layout"; -import { globalSiteTitle } from "~/utils/global"; import { useTranslations } from "next-intl"; import { getServerSideProps } from "~/server/getServerSideProps"; import useOrganizationWebsocket from "~/hooks/useOrganizationWebsocket"; @@ -10,9 +9,11 @@ import OrganizationSettings from "./settings"; import OrganizationWebhook from "./webhooks"; import OrganizationNetworkSetting from "./network"; import OrganizationInvites from "./invite"; +import { api } from "~/utils/api"; const OrganizationAdminSettings = ({ orgIds, user }) => { - const title = `${globalSiteTitle} - Admin Settings`; + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const title = `${globalOptions?.siteName} - Admin Settings`; const router = useRouter(); const { tab = "members", orgid: organizationId } = router.query; diff --git a/src/pages/organization/[orgid]/admin/invite/index.tsx b/src/pages/organization/[orgid]/admin/invite/index.tsx index dacba02d..65c79c0c 100644 --- a/src/pages/organization/[orgid]/admin/invite/index.tsx +++ b/src/pages/organization/[orgid]/admin/invite/index.tsx @@ -9,7 +9,6 @@ import { getServerSideProps } from "~/server/getServerSideProps"; import { api } from "~/utils/api"; import TimeAgo from "react-timeago"; import cn from "classnames"; -import { globalSiteTitle } from "~/utils/global"; import HeadSection from "~/components/shared/metaTags"; import MenuSectionDividerWrapper from "~/components/shared/menuSectionDividerWrapper"; @@ -129,12 +128,12 @@ const OrganizationInvites = () => { const t = useTranslations(); const router = useRouter(); const organizationId = router.query.orgid as string; - + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); const { data: orgInvites } = api.org.getInvites.useQuery({ organizationId, }); - const pageTitle = `${globalSiteTitle} - Invitations`; + const pageTitle = `${globalOptions?.siteName} - Invitations`; return (
diff --git a/src/pages/organization/[orgid]/admin/settings/index.tsx b/src/pages/organization/[orgid]/admin/settings/index.tsx index 468c0d9d..c4ee2e7b 100644 --- a/src/pages/organization/[orgid]/admin/settings/index.tsx +++ b/src/pages/organization/[orgid]/admin/settings/index.tsx @@ -8,7 +8,6 @@ import { useRouter } from "next/router"; import { LayoutOrganizationAuthenticated } from "~/components/layouts/layout"; import { getServerSideProps } from "~/server/getServerSideProps"; import HeadSection from "~/components/shared/metaTags"; -import { globalSiteTitle } from "~/utils/global"; import InputField from "~/components/elements/inputField"; import { useTrpcApiErrorHandler } from "~/hooks/useTrpcApiHandler"; import MenuSectionDividerWrapper from "~/components/shared/menuSectionDividerWrapper"; @@ -30,6 +29,7 @@ const OrganizationSettings = ({ user }) => { const { mutate: leaveOrg } = api.org.leave.useMutation({ onError: handleApiError, }); + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); const { data: orgData, refetch: refecthOrgById } = api.org.getOrgById.useQuery( { @@ -60,7 +60,7 @@ const OrganizationSettings = ({ user }) => { }, }); - const pageTitle = `${globalSiteTitle} - Meta`; + const pageTitle = `${globalOptions?.siteName} - Meta`; return (
diff --git a/src/pages/organization/[orgid]/admin/webhooks/index.tsx b/src/pages/organization/[orgid]/admin/webhooks/index.tsx index 3deba074..c65565c0 100644 --- a/src/pages/organization/[orgid]/admin/webhooks/index.tsx +++ b/src/pages/organization/[orgid]/admin/webhooks/index.tsx @@ -11,7 +11,6 @@ import { getServerSideProps } from "~/server/getServerSideProps"; import { useRouter } from "next/router"; import TimeAgo from "react-timeago"; import HeadSection from "~/components/shared/metaTags"; -import { globalSiteTitle } from "~/utils/global"; import { useTrpcApiErrorHandler, useTrpcApiSuccessHandler, @@ -105,6 +104,8 @@ const OrganizationWebhook = () => { const [input, setInput] = useState(initialState); + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + // TODO make only one request instead of Orgbyid and AllOrgs const { refetch: refecthOrg } = api.org.getOrgById.useQuery({ organizationId, @@ -154,7 +155,7 @@ const OrganizationWebhook = () => { } }; - const pageTitle = `${globalSiteTitle} - Webhooks`; + const pageTitle = `${globalOptions?.siteName} - Webhooks`; return (
diff --git a/src/pages/user-settings/index.tsx b/src/pages/user-settings/index.tsx index 92104399..ef363383 100644 --- a/src/pages/user-settings/index.tsx +++ b/src/pages/user-settings/index.tsx @@ -5,12 +5,14 @@ import { LayoutAuthenticated } from "~/components/layouts/layout"; import Account from "./account"; import { useTranslations } from "next-intl"; import UserNetworkSetting from "./network"; -import { globalSiteTitle } from "~/utils/global"; import { getServerSideProps } from "~/server/getServerSideProps"; import UserSettingsNotification from "./notification"; +import { api } from "~/utils/api"; const UserSettings = () => { - const title = `${globalSiteTitle} - User Settings`; + const { data: globalOptions } = api.settings.getAllOptions.useQuery(); + const title = `${globalOptions?.siteName} - User Settings`; + const router = useRouter(); const t = useTranslations("userSettings"); const { tab = "members" } = router.query; diff --git a/src/server/api/routers/adminRoute.ts b/src/server/api/routers/adminRoute.ts index c48d4791..f74567b5 100644 --- a/src/server/api/routers/adminRoute.ts +++ b/src/server/api/routers/adminRoute.ts @@ -349,6 +349,7 @@ export const adminRouter = createTRPCRouter({ userRegistrationNotification: z.boolean().optional(), welcomeMessageTitle: z.string().max(50).optional(), welcomeMessageBody: z.string().max(350).optional(), + siteName: z.string().max(30).optional(), }), ) .mutation(async ({ ctx, input }) => { diff --git a/src/server/api/routers/settingsRouter.ts b/src/server/api/routers/settingsRouter.ts index a71dac0a..dcd06704 100644 --- a/src/server/api/routers/settingsRouter.ts +++ b/src/server/api/routers/settingsRouter.ts @@ -1,4 +1,4 @@ -import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc"; +import { createTRPCRouter, protectedProcedure, publicProcedure } from "~/server/api/trpc"; import { SMTP_SECRET, decrypt, generateInstanceSecret } from "~/utils/encryption"; export const settingsRouter = createTRPCRouter({ @@ -23,4 +23,16 @@ export const settingsRouter = createTRPCRouter({ } return options; }), + getPublicOptions: publicProcedure.query(async ({ ctx }) => { + const publicOptions = await ctx.prisma.globalOptions.findFirst({ + where: { + id: 1, + }, + select: { + siteName: true, + }, + }); + + return publicOptions; + }), }); diff --git a/src/utils/global.ts b/src/utils/global.ts index 851f2d09..faf05c3c 100644 --- a/src/utils/global.ts +++ b/src/utils/global.ts @@ -2,7 +2,4 @@ import { env } from "~/env.mjs"; -// If it is not set, use the default value "ZTnet". -export const globalSiteTitle = env.NEXT_PUBLIC_SITE_NAME || "ZTNET"; - export const globalSiteVersion = env.NEXT_PUBLIC_APP_VERSION || "development"; From 61fd918b058aea75bf3b8d2eddf5518cb5115c29 Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sun, 15 Dec 2024 11:03:30 +0000 Subject: [PATCH 5/7] translations --- src/locales/en/common.json | 4 ++-- src/locales/es/common.json | 4 ++++ src/locales/fr/common.json | 4 ++++ src/locales/no/common.json | 4 ++++ src/locales/pl/common.json | 4 ++++ src/locales/ru/common.json | 4 ++++ src/locales/zh-tw/common.json | 4 ++++ src/locales/zh/common.json | 4 ++++ src/pages/admin/settings/index.tsx | 14 +++++++------- 9 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/locales/en/common.json b/src/locales/en/common.json index d6100e71..04bc1743 100644 --- a/src/locales/en/common.json +++ b/src/locales/en/common.json @@ -442,8 +442,8 @@ "admin": { "settings": { "application": { - "siteName": "Site Name", - "description": "Customize the name of your site to better align with your brand" + "title": "Application", + "description": "Customize the application's appearance and behavior to better align with your brand" }, "publicPages": { "sectionTitle": "Public Pages", diff --git a/src/locales/es/common.json b/src/locales/es/common.json index 9b93fc37..9e4616d6 100644 --- a/src/locales/es/common.json +++ b/src/locales/es/common.json @@ -441,6 +441,10 @@ }, "admin": { "settings": { + "application": { + "title": "Aplicación", + "description": "Personaliza la apariencia y el comportamiento de la aplicación para alinearla mejor con tu marca" + }, "publicPages": { "sectionTitle": "Páginas Públicas", "description": "Personaliza el texto que se muestra en tus páginas de inicio de sesión y registro para alinearlo mejor con tu marca o proporcionar instrucciones específicas a tus usuarios." diff --git a/src/locales/fr/common.json b/src/locales/fr/common.json index c22a103a..16251967 100644 --- a/src/locales/fr/common.json +++ b/src/locales/fr/common.json @@ -441,6 +441,10 @@ }, "admin": { "settings": { + "application": { + "title": "Application", + "description": "Personnalisez l'apparence et le comportement de l'application pour mieux correspondre à votre marque" + }, "publicPages": { "sectionTitle": "Pages publiques", "description": "Personnalisez le texte affiché sur vos pages de connexion et d'inscription pour mieux correspondre à votre marque ou fournir des instructions spécifiques à vos utilisateurs." diff --git a/src/locales/no/common.json b/src/locales/no/common.json index 14d48bd7..ac694d9d 100644 --- a/src/locales/no/common.json +++ b/src/locales/no/common.json @@ -441,6 +441,10 @@ }, "admin": { "settings": { + "application": { + "title": "Applikasjon", + "description": "Tilpass applikasjonens utseende og oppførsel for å bedre tilpasse den til merkevaren din" + }, "publicPages": { "sectionTitle": "Offentlige Sider", "description": "Tilpass teksten som vises på innloggings- og registreringssidene dine for å bedre samsvare med merkevaren din eller gi spesifikke instruksjoner til brukerne dine." diff --git a/src/locales/pl/common.json b/src/locales/pl/common.json index 790b71a0..c001e0f8 100644 --- a/src/locales/pl/common.json +++ b/src/locales/pl/common.json @@ -441,6 +441,10 @@ }, "admin": { "settings": { + "application": { + "title": "Aplikacja", + "description": "Dostosuj wygląd i zachowanie aplikacji, aby lepiej pasowała do Twojej marki" + }, "publicPages": { "sectionTitle": "Strony startowe", "description": "Dostosuj tekst wyświetlany na stronach logowania i rejestracji, aby lepiej pasował do Twojej marki lub zapewniał użytkownikom szczegółowe instrukcje." diff --git a/src/locales/ru/common.json b/src/locales/ru/common.json index b554b566..cc798326 100644 --- a/src/locales/ru/common.json +++ b/src/locales/ru/common.json @@ -441,6 +441,10 @@ }, "admin": { "settings": { + "application": { + "title": "Приложение", + "description": "Настройте внешний вид и поведение приложения для лучшего соответствия вашему бренду" + }, "publicPages": { "sectionTitle": "Публичные страницы", "description": "Настройте текст, отображаемый на ваших страницах входа и регистрации, чтобы лучше соответствовать вашему бренду или предоставить специальные инструкции вашим пользователям." diff --git a/src/locales/zh-tw/common.json b/src/locales/zh-tw/common.json index b1815285..3070a64c 100644 --- a/src/locales/zh-tw/common.json +++ b/src/locales/zh-tw/common.json @@ -441,6 +441,10 @@ }, "admin": { "settings": { + "application": { + "title": "應用程式", + "description": "自訂應用程式的外觀和行為,以更好地符合您的品牌" + }, "publicPages": { "sectionTitle": "公開頁面", "description": "自訂登入和註冊頁面上顯示的文字,以更好地與您的品牌保持一致或向您的使用者提供具體說明。" diff --git a/src/locales/zh/common.json b/src/locales/zh/common.json index bb4e87b7..4b798c4e 100644 --- a/src/locales/zh/common.json +++ b/src/locales/zh/common.json @@ -441,6 +441,10 @@ }, "admin": { "settings": { + "application": { + "title": "应用", + "description": "自定义应用的外观和行为,以更好地匹配您的品牌" + }, "publicPages": { "sectionTitle": "公共页面", "description": "自定义登录和注册页面上显示的文本,以更好地与您的品牌保持一致或向您的用户提供具体说明。" diff --git a/src/pages/admin/settings/index.tsx b/src/pages/admin/settings/index.tsx index 3fc2df06..7c145c47 100644 --- a/src/pages/admin/settings/index.tsx +++ b/src/pages/admin/settings/index.tsx @@ -19,9 +19,9 @@ const Settings = () => { isLoading: loadingOptions, refetch: refetchOptions, } = api.admin.getAllOptions.useQuery(); - - const { mutate: setWelcomeMessage } = api.admin.updateGlobalOptions.useMutation({ - onSuccess: handleApiSuccess({ actions: [refetchOptions] }), + const { refetch: refetcUserhOptions } = api.settings.getAllOptions.useQuery(); + const { mutate: setGlobalOptions } = api.admin.updateGlobalOptions.useMutation({ + onSuccess: handleApiSuccess({ actions: [refetchOptions, refetcUserhOptions] }), onError: handleApiError, }); @@ -38,7 +38,7 @@ const Settings = () => { return (
@@ -61,7 +61,7 @@ const Settings = () => { ]} submitHandler={(params) => new Promise((resolve) => { - setWelcomeMessage(params); + setGlobalOptions(params); resolve(true); }) } @@ -92,7 +92,7 @@ const Settings = () => { ]} submitHandler={(params) => new Promise((resolve) => { - setWelcomeMessage(params); + setGlobalOptions(params); resolve(true); }) } @@ -116,7 +116,7 @@ const Settings = () => { ]} submitHandler={(params) => new Promise((resolve) => { - setWelcomeMessage(params); + setGlobalOptions(params); resolve(true); }) } From b71c93f23d55f189f427419eff7d32c7eb04e494 Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sun, 15 Dec 2024 11:35:20 +0000 Subject: [PATCH 6/7] tests --- src/__tests__/__mocks__/networkById.ts | 16 ++++++++++++ src/__tests__/pages/auth/signin.test.tsx | 16 ++++++++++++ src/__tests__/pages/network/[id].test.tsx | 30 +++++++++++++++++++++- src/__tests__/pages/network/index.test.tsx | 16 ++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/__tests__/__mocks__/networkById.ts b/src/__tests__/__mocks__/networkById.ts index 635cbfcb..2934b50a 100644 --- a/src/__tests__/__mocks__/networkById.ts +++ b/src/__tests__/__mocks__/networkById.ts @@ -30,6 +30,22 @@ jest.mock("../../utils/api", () => ({ }), }, }, + settings: { + getAllOptions: { + useQuery: () => ({ + data: {}, + isLoading: false, + refetch: jest.fn(), + }), + }, + getPublicOptions: { + useQuery: () => ({ + data: {}, + isLoading: false, + refetch: jest.fn(), + }), + }, + }, networkMember: { getNetworkMemberById: { useQuery: () => ({ diff --git a/src/__tests__/pages/auth/signin.test.tsx b/src/__tests__/pages/auth/signin.test.tsx index 3088b568..e8be4d12 100644 --- a/src/__tests__/pages/auth/signin.test.tsx +++ b/src/__tests__/pages/auth/signin.test.tsx @@ -48,6 +48,22 @@ jest.mock("../../../utils/api", () => ({ }), }, }, + settings: { + getAllOptions: { + useQuery: () => ({ + data: {}, + isLoading: false, + refetch: jest.fn(), + }), + }, + getPublicOptions: { + useQuery: () => ({ + data: {}, + isLoading: false, + refetch: jest.fn(), + }), + }, + }, network: { getUserNetworks: { useQuery: jest.fn(), diff --git a/src/__tests__/pages/network/[id].test.tsx b/src/__tests__/pages/network/[id].test.tsx index d501bcb1..6706a3ed 100644 --- a/src/__tests__/pages/network/[id].test.tsx +++ b/src/__tests__/pages/network/[id].test.tsx @@ -28,6 +28,34 @@ jest.mock("~/server/db", () => ({ }, })); +jest.mock("../../../utils/api", () => { + return { + api: { + settings: { + getAllOptions: { + useQuery: () => ({ + data: {}, + isLoading: false, + refetch: jest.fn(), + }), + }, + getPublicOptions: { + useQuery: () => ({ + data: {}, + isLoading: false, + refetch: jest.fn(), + }), + }, + }, + network: { + getNetworkById: { + useQuery: jest.fn(), + }, + }, + }, + }; +}); + jest.mock("~/components/auth/withAuth", () => ({ withAuth: jest.fn().mockImplementation((gssp) => gssp), })); @@ -66,6 +94,7 @@ describe("NetworkById component", () => { refetch: jest.fn(), }); api.network.getNetworkById.useQuery = useQueryMock; + const context = { params: { orgIds: [] } as ParsedUrlQuery, locale: "en", @@ -351,7 +380,6 @@ describe("NetworkById component", () => { }); api.network.getNetworkById.useQuery = useQueryMock; - render( diff --git a/src/__tests__/pages/network/index.test.tsx b/src/__tests__/pages/network/index.test.tsx index e5794858..4d864bba 100644 --- a/src/__tests__/pages/network/index.test.tsx +++ b/src/__tests__/pages/network/index.test.tsx @@ -15,6 +15,22 @@ jest.mock("../../../utils/api", () => ({ useQuery: jest.fn(), }, }, + settings: { + getAllOptions: { + useQuery: () => ({ + data: {}, + isLoading: false, + refetch: jest.fn(), + }), + }, + getPublicOptions: { + useQuery: () => ({ + data: {}, + isLoading: false, + refetch: jest.fn(), + }), + }, + }, network: { getUserNetworks: { useQuery: jest.fn(), From a77c5b8db83bf7b96f587562d699389dd088e6e2 Mon Sep 17 00:00:00 2001 From: Bernt Christian Egeland Date: Sun, 15 Dec 2024 11:51:17 +0000 Subject: [PATCH 7/7] placeHolder --- src/pages/admin/settings/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/admin/settings/index.tsx b/src/pages/admin/settings/index.tsx index 7c145c47..35bc86d0 100644 --- a/src/pages/admin/settings/index.tsx +++ b/src/pages/admin/settings/index.tsx @@ -53,9 +53,8 @@ const Settings = () => { fields={[ { name: "siteName", - description: "Max 50 Char", + description: "Max 30 Char", type: "text", - placeholder: "Write a cool title ....", value: options?.siteName, }, ]}