2021-09-21 09:29:20 +00:00
|
|
|
import { useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2023-02-14 15:01:34 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Badge, Button } from "@calcom/ui";
|
2022-03-16 23:36:43 +00:00
|
|
|
|
2021-09-21 09:29:20 +00:00
|
|
|
import DisableTwoFactorModal from "./DisableTwoFactorModal";
|
2021-09-22 19:52:38 +00:00
|
|
|
import EnableTwoFactorModal from "./EnableTwoFactorModal";
|
2021-09-21 09:29:20 +00:00
|
|
|
|
2021-10-12 13:11:33 +00:00
|
|
|
const TwoFactorAuthSection = ({ twoFactorEnabled }: { twoFactorEnabled: boolean }) => {
|
2021-09-21 09:29:20 +00:00
|
|
|
const [enabled, setEnabled] = useState(twoFactorEnabled);
|
|
|
|
const [enableModalOpen, setEnableModalOpen] = useState(false);
|
|
|
|
const [disableModalOpen, setDisableModalOpen] = useState(false);
|
2021-10-12 13:11:33 +00:00
|
|
|
const { t } = useLocale();
|
2021-09-21 09:29:20 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-05-09 11:43:27 +00:00
|
|
|
<div className="flex flex-col justify-between pt-9 pl-2 sm:flex-row">
|
2022-04-16 02:58:34 +00:00
|
|
|
<div>
|
|
|
|
<div className="flex flex-row items-center">
|
|
|
|
<h2 className="font-cal text-lg font-medium leading-6 text-gray-900">{t("2fa")}</h2>
|
|
|
|
<Badge className="ml-2 text-xs" variant={enabled ? "success" : "gray"}>
|
|
|
|
{enabled ? t("enabled") : t("disabled")}
|
|
|
|
</Badge>
|
|
|
|
</div>
|
|
|
|
<p className="mt-1 text-sm text-gray-500">{t("add_an_extra_layer_of_security")}</p>
|
|
|
|
</div>
|
2022-05-09 11:43:27 +00:00
|
|
|
<div className="mt-5 sm:mt-0 sm:self-center">
|
2022-04-16 02:58:34 +00:00
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
color="secondary"
|
|
|
|
onClick={() => (enabled ? setDisableModalOpen(true) : setEnableModalOpen(true))}>
|
|
|
|
{enabled ? t("disable") : t("enable")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2021-09-21 09:29:20 +00:00
|
|
|
</div>
|
|
|
|
{enableModalOpen && (
|
|
|
|
<EnableTwoFactorModal
|
|
|
|
onEnable={() => {
|
|
|
|
setEnabled(true);
|
|
|
|
setEnableModalOpen(false);
|
|
|
|
}}
|
|
|
|
onCancel={() => setEnableModalOpen(false)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{disableModalOpen && (
|
|
|
|
<DisableTwoFactorModal
|
|
|
|
onDisable={() => {
|
|
|
|
setEnabled(false);
|
|
|
|
setDisableModalOpen(false);
|
|
|
|
}}
|
|
|
|
onCancel={() => setDisableModalOpen(false)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TwoFactorAuthSection;
|