## What does this PR do? <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> - Add the prop customDividerClassName to customize the CSS Divider if needed - Add a divider on all modals with type="creation" prop, following the [figma](https://www.figma.com/file/9MOufQNLtdkpnDucmNX10R/1.-Cal-DS?type=design&node-id=29898%3A100590&t=62LvZCZAEZm5zDdw-1) design - Some type="creation" modals seem not to be this type, we pushed all changes with screenshots, if you want us to revert the changes on some modals we will revert  - Inline Embed:  - Enable Two-Factor Authentication:  -Enable Two-Factor Authentication (step 2):  -Enable Two-Factor Authentication (step 3):  - Disable Two-Factor Authentication:  - Delete Account:  - Update Timezone:  - Duplicate Event Type:  - Add a New Form:  - Change Team Member Role:  - Impersonate:  - Bulk Update Event Types:  - Connecting with MS Teams:  - Set a Default App Link:  - OIDC configuration:  - SAML Configuration:  - How to use booking questions as variables?   - Invite Link Settings:  - Add Action:  - Edit Keys:  - Create an Api Key:  - API key created successfully:  - Invite Team Member:  - Add a Question:  - Add a new event type: 
105 lines
3.2 KiB
TypeScript
105 lines
3.2 KiB
TypeScript
import { useState } from "react";
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import { ErrorCode } from "@calcom/features/auth/lib/ErrorCode";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { Button, Dialog, DialogContent, DialogFooter, Form, PasswordField } from "@calcom/ui";
|
|
|
|
import TwoFactor from "@components/auth/TwoFactor";
|
|
|
|
import TwoFactorAuthAPI from "./TwoFactorAuthAPI";
|
|
|
|
interface DisableTwoFactorAuthModalProps {
|
|
open: boolean;
|
|
onOpenChange: () => void;
|
|
|
|
/** Called when the user closes the modal without disabling two-factor auth */
|
|
onCancel: () => void;
|
|
/** Called when the user disables two-factor auth */
|
|
onDisable: () => void;
|
|
}
|
|
|
|
interface DisableTwoFactorValues {
|
|
totpCode: string;
|
|
password: string;
|
|
}
|
|
|
|
const DisableTwoFactorAuthModal = ({
|
|
onDisable,
|
|
onCancel,
|
|
open,
|
|
onOpenChange,
|
|
}: DisableTwoFactorAuthModalProps) => {
|
|
const [isDisabling, setIsDisabling] = useState(false);
|
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
|
const { t } = useLocale();
|
|
|
|
const form = useForm<DisableTwoFactorValues>();
|
|
|
|
async function handleDisable({ totpCode, password }: DisableTwoFactorValues) {
|
|
if (isDisabling) {
|
|
return;
|
|
}
|
|
setIsDisabling(true);
|
|
setErrorMessage(null);
|
|
|
|
try {
|
|
const response = await TwoFactorAuthAPI.disable(password, totpCode);
|
|
if (response.status === 200) {
|
|
onDisable();
|
|
return;
|
|
}
|
|
|
|
const body = await response.json();
|
|
if (body.error === ErrorCode.IncorrectPassword) {
|
|
setErrorMessage(t("incorrect_password"));
|
|
}
|
|
if (body.error === ErrorCode.SecondFactorRequired) {
|
|
setErrorMessage(t("2fa_required"));
|
|
}
|
|
if (body.error === ErrorCode.IncorrectTwoFactorCode) {
|
|
setErrorMessage(t("incorrect_2fa"));
|
|
} else {
|
|
setErrorMessage(t("something_went_wrong"));
|
|
}
|
|
} catch (e) {
|
|
setErrorMessage(t("something_went_wrong"));
|
|
console.error(t("error_disabling_2fa"), e);
|
|
} finally {
|
|
setIsDisabling(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent title={t("disable_2fa")} description={t("disable_2fa_recommendation")} type="creation">
|
|
<Form form={form} handleSubmit={handleDisable}>
|
|
<div className="mb-8">
|
|
<PasswordField
|
|
labelProps={{
|
|
className: "block text-sm font-medium text-default",
|
|
}}
|
|
{...form.register("password")}
|
|
className="border-default mt-1 block w-full rounded-md border px-3 py-2 text-sm focus:border-black focus:outline-none focus:ring-black"
|
|
/>
|
|
<TwoFactor center={false} />
|
|
|
|
{errorMessage && <p className="mt-1 text-sm text-red-700">{errorMessage}</p>}
|
|
</div>
|
|
|
|
<DialogFooter showDivider className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
|
<Button color="secondary" onClick={onCancel}>
|
|
{t("cancel")}
|
|
</Button>
|
|
<Button type="submit" className="me-2 ms-2" data-testid="disable-2fa" disabled={isDisabling}>
|
|
{t("disable")}
|
|
</Button>
|
|
</DialogFooter>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|
|
|
|
export default DisableTwoFactorAuthModal;
|