Update support multiple domain and error handling

This commit is contained in:
Salman
2024-02-11 10:55:36 +05:30
parent 3f96f0a8fb
commit 2ef8781378
5 changed files with 45 additions and 22 deletions
@@ -1,7 +1,9 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import Link from "next/link";
import axios from "axios";
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
import { useSendVerificationEmail } from "@app/hooks/api";
import { Button, Input } from "../v2";
@@ -25,6 +27,7 @@ export default function EnterEmailStep({
setEmail,
incrementStep
}: DownloadBackupPDFStepProps): JSX.Element {
const { createNotification } = useNotificationContext();
const { mutateAsync } = useSendVerificationEmail();
const [emailError, setEmailError] = useState(false);
const { t } = useTranslation();
@@ -46,8 +49,18 @@ export default function EnterEmailStep({
// If everything is correct, go to the next step
if (!emailCheckBool) {
await mutateAsync({ email });
incrementStep();
try {
await mutateAsync({ email });
incrementStep();
} catch(e) {
if (axios.isAxiosError(e)) {
const { message = "Something went wrong" } = e.response?.data as { message: string};
createNotification({
type: "error",
text: message
})
}
}
}
};
@@ -66,17 +66,25 @@ export const AdminDashboardPage = () => {
}, [config]);
const handleSubmit = async () => {
config.allowSignUp = signUpMode !== "disabled";
config.inviteOnlySignUp = signUpMode === "invite-only";
config.allowSpecificDomainSignUp = signUpMode === "anyone" ? allowSpecificDomain : "";
try {
config.allowSignUp = signUpMode !== "disabled";
config.inviteOnlySignUp = signUpMode === "invite-only";
config.allowSpecificDomainSignUp = signUpMode === "anyone" ? allowSpecificDomain : "";
await updateServerConfig(config);
await updateServerConfig(config);
createNotification({
text: "Successfully changed sign up mode.",
type: "success"
});
}
createNotification({
text: "Successfully changed sign up setting.",
type: "success"
});
} catch (e) {
console.error(e);
createNotification({
type: "error",
text: "Failed to update sign up setting."
});
}
};
return (
<div className="container mx-auto max-w-7xl px-4 pb-12 text-white dark:[color-scheme:dark]">
@@ -118,12 +126,12 @@ export const AdminDashboardPage = () => {
{signUpMode === "anyone" && (
<div className="mt-4 flex items-center justify-between">
<div className="mb-4 flex text-mineshaft-100">
Allow email with only specific domain
Allow email with only specific domain(s)
</div>
<FormControl label="Leave blank to allow any domain handle" className="w-72">
<div>
<Input
placeholder="domain.com"
placeholder="domain.com, domain2.com"
leftIcon={<FontAwesomeIcon icon={faAt} />}
value={allowSpecificDomain}
onChange={(ev) => setAllowSpecificDomain(ev.target.value)}