diff --git a/public/locales/en-US/translation.json b/public/locales/en-US/translation.json index 2f4e4b0..a757df4 100644 --- a/public/locales/en-US/translation.json +++ b/public/locales/en-US/translation.json @@ -407,7 +407,11 @@ "helperText": "This is just a preview. Those are not real aliases." }, "randomAliasesIncreaseExplanation": "Random aliases' length will be increased from {{originalLength}} to {{increasedLength}} characters after {{amount}} aliases have been created.", - "resetLabel": "Reset to defaults" + "resetLabel": "Reset to defaults", + "disabled": { + "title": "Global settings are disabled", + "description": "Global settings have been disabled. You can enable them in the configuration file." + } } } }, diff --git a/src/apis/get-admin-settings.ts b/src/apis/get-admin-settings.ts index 6ce2f5e..8754f03 100644 --- a/src/apis/get-admin-settings.ts +++ b/src/apis/get-admin-settings.ts @@ -2,8 +2,7 @@ import {client} from "~/constants/axios-client" import {AdminSettings} from "~/server-types" export type GetAdminSettingsResponse = - | Partial - | { + | Partial & { detail: string code: "error:settings:global_settings_disabled" } diff --git a/src/apis/resend-email-login-code.ts b/src/apis/resend-email-login-code.ts index efef26b..28ff7f3 100644 --- a/src/apis/resend-email-login-code.ts +++ b/src/apis/resend-email-login-code.ts @@ -1,18 +1,11 @@ -import {SimpleDetailResponse} from "~/server-types" import {client} from "~/constants/axios-client" +import {SimpleDetailResponse} from "~/server-types" export interface ResendEmailLoginCodeData { email: string sameRequestToken: string } -export type ResendEmailLoginCodeResponse = - | SimpleDetailResponse - | { - detail: string - code: "ok:email_already_verified" - } - export default async function resendEmailLoginCode({ email, sameRequestToken, diff --git a/src/apis/resend-email-verification-code.ts b/src/apis/resend-email-verification-code.ts index 67f90ae..a46cc4d 100644 --- a/src/apis/resend-email-verification-code.ts +++ b/src/apis/resend-email-verification-code.ts @@ -1,9 +1,15 @@ import {SimpleDetailResponse} from "~/server-types" import {client} from "~/constants/axios-client" +export type ResendEmailVerificationCodeResponse = + | SimpleDetailResponse & { + detail: string + code: "ok:email_already_verified" + } + export default async function resendEmailVerificationCode( email: string, -): Promise { +): Promise { const {data} = await client.post( `${import.meta.env.VITE_SERVER_BASE_URL}/v1/auth/resend-email`, { diff --git a/src/apis/update-admin-settings.ts b/src/apis/update-admin-settings.ts index b7d2abe..e92d99d 100644 --- a/src/apis/update-admin-settings.ts +++ b/src/apis/update-admin-settings.ts @@ -2,15 +2,14 @@ import {client} from "~/constants/axios-client" import {AdminSettings} from "~/server-types" export type UpdateAdminSettingsResponse = - | Partial - | { + | Partial & { detail: string code: "error:settings:global_settings_disabled" } export default async function updateAdminSettings( settings: Partial, -): Promise { +): Promise { const {data} = await client.patch( `${import.meta.env.VITE_SERVER_BASE_URL}/v1/admin/settings`, settings, diff --git a/src/route-widgets/GlobalSettingsRoute/SettingsDisabled.tsx b/src/route-widgets/GlobalSettingsRoute/SettingsDisabled.tsx new file mode 100644 index 0000000..79a15e3 --- /dev/null +++ b/src/route-widgets/GlobalSettingsRoute/SettingsDisabled.tsx @@ -0,0 +1,38 @@ +import {RiAlertFill} from "react-icons/ri" +import {ReactElement} from "react" +import {useTranslation} from "react-i18next" + +import {Container, Grid, Typography} from "@mui/material" + +export default function SettingsDisabled(): ReactElement { + console.log("asdas") + const {t} = useTranslation() + + return ( + + + + + {t("routes.AdminRoute.settings.disabled.title")} + + + + + + + + {t("routes.AdminRoute.settings.disabled.description")} + + + + + ) +} diff --git a/src/route-widgets/GlobalSettingsRoute/SettingsForm.tsx b/src/route-widgets/GlobalSettingsRoute/SettingsForm.tsx index e38c6fc..87b542f 100644 --- a/src/route-widgets/GlobalSettingsRoute/SettingsForm.tsx +++ b/src/route-widgets/GlobalSettingsRoute/SettingsForm.tsx @@ -21,7 +21,7 @@ import {useMutation} from "@tanstack/react-query" import {AdminSettings} from "~/server-types" import {StringPoolField, createPool} from "~/components" -import {updateAdminSettings} from "~/apis" +import {UpdateAdminSettingsResponse, updateAdminSettings} from "~/apis" import {useErrorSuccessSnacks} from "~/hooks" import {queryClient} from "~/constants/react-query" import {parseFastAPIError} from "~/utils" @@ -85,7 +85,11 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) { .label(t("routes.AdminRoute.forms.settings.allowStatistics.label")), }) - const {mutateAsync} = useMutation>( + const {mutateAsync} = useMutation< + UpdateAdminSettingsResponse, + AxiosError, + Partial + >( async settings => { // Set values to `null` that are their defaults const strippedSettings = Object.fromEntries( @@ -102,10 +106,14 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) { }, { onError: showError, - onSuccess: newSettings => { + onSuccess: ({code, detail, ...newSettings}) => { + if (code === "error:settings:global_settings_disabled") { + return + } + showSuccess(t("routes.AdminRoute.settings.successMessage")) - queryClient.setQueryData(queryKey, newSettings) + queryClient.setQueryData>(queryKey, newSettings) }, }, ) diff --git a/src/route-widgets/LoginRoute/ConfirmCodeForm/ResendMailButton.tsx b/src/route-widgets/LoginRoute/ConfirmCodeForm/ResendMailButton.tsx index 3d52a46..06e3c13 100644 --- a/src/route-widgets/LoginRoute/ConfirmCodeForm/ResendMailButton.tsx +++ b/src/route-widgets/LoginRoute/ConfirmCodeForm/ResendMailButton.tsx @@ -6,9 +6,9 @@ import React, {ReactElement} from "react" import {useMutation} from "@tanstack/react-query" -import {resendEmailLoginCode} from "~/apis" +import {ResendEmailLoginCodeResponse, resendEmailLoginCode} from "~/apis" import {MutationStatusSnackbar, TimedButton} from "~/components" -import {ServerSettings, SimpleDetailResponse} from "~/server-types" +import {ServerSettings} from "~/server-types" export interface ResendMailButtonProps { email: string @@ -22,7 +22,7 @@ export default function ResendMailButton({ const settings = useLoaderData() as ServerSettings const {t} = useTranslation() - const mutation = useMutation(() => + const mutation = useMutation(() => resendEmailLoginCode({ email, sameRequestToken, diff --git a/src/route-widgets/SignupRoute/YouGotMail/ResendMailButton.tsx b/src/route-widgets/SignupRoute/YouGotMail/ResendMailButton.tsx index b049c9e..a6426dc 100644 --- a/src/route-widgets/SignupRoute/YouGotMail/ResendMailButton.tsx +++ b/src/route-widgets/SignupRoute/YouGotMail/ResendMailButton.tsx @@ -6,20 +6,31 @@ import React, {ReactElement} from "react" import {useMutation} from "@tanstack/react-query" -import {resendEmailVerificationCode} from "~/apis" +import {ResendEmailVerificationCodeResponse, resendEmailVerificationCode} from "~/apis" import {MutationStatusSnackbar, TimedButton} from "~/components" -import {ServerSettings, SimpleDetailResponse} from "~/server-types" +import {ServerSettings} from "~/server-types" export interface ResendMailButtonProps { email: string + onEmailAlreadyVerified: () => void } -export default function ResendMailButton({email}: ResendMailButtonProps): ReactElement { +export default function ResendMailButton({ + email, + onEmailAlreadyVerified, +}: ResendMailButtonProps): ReactElement { const {t} = useTranslation() const settings = useLoaderData() as ServerSettings - const mutation = useMutation(() => - resendEmailVerificationCode(email), + const mutation = useMutation( + () => resendEmailVerificationCode(email), + { + onSuccess: ({code}: any) => { + if (code === "ok:email_already_verified") { + onEmailAlreadyVerified() + } + }, + }, ) const {mutate} = mutation diff --git a/src/route-widgets/SignupRoute/YouGotMail/YouGotMail.tsx b/src/route-widgets/SignupRoute/YouGotMail/YouGotMail.tsx index 5fa50bd..c01de46 100644 --- a/src/route-widgets/SignupRoute/YouGotMail/YouGotMail.tsx +++ b/src/route-widgets/SignupRoute/YouGotMail/YouGotMail.tsx @@ -67,7 +67,7 @@ export default function YouGotMail({email, onGoBack}: YouGotMailProps): ReactEle - +