2021-09-21 09:29:20 +00:00
|
|
|
import { useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
|
|
|
|
2021-09-21 09:29:20 +00:00
|
|
|
import Badge from "@components/ui/Badge";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Button from "@components/ui/Button";
|
|
|
|
|
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 (
|
|
|
|
<>
|
|
|
|
<div className="flex flex-row items-center">
|
2021-10-08 11:43:48 +00:00
|
|
|
<h2 className="font-cal text-lg leading-6 font-medium text-gray-900">{t("2fa")}</h2>
|
2021-09-21 09:29:20 +00:00
|
|
|
<Badge className="text-xs ml-2" variant={enabled ? "success" : "gray"}>
|
2021-10-13 09:34:55 +00:00
|
|
|
{enabled ? t("enabled") : t("disabled")}
|
2021-09-21 09:29:20 +00:00
|
|
|
</Badge>
|
|
|
|
</div>
|
2021-10-08 11:43:48 +00:00
|
|
|
<p className="mt-1 text-sm text-gray-500">{t("add_an_extra_layer_of_security")}</p>
|
2021-09-21 09:29:20 +00:00
|
|
|
|
|
|
|
<Button
|
|
|
|
className="mt-6"
|
|
|
|
type="submit"
|
|
|
|
onClick={() => (enabled ? setDisableModalOpen(true) : setEnableModalOpen(true))}>
|
2021-10-13 09:34:55 +00:00
|
|
|
{enabled ? t("disable") : t("enable")} {t("2fa")}
|
2021-09-21 09:29:20 +00:00
|
|
|
</Button>
|
|
|
|
|
|
|
|
{enableModalOpen && (
|
|
|
|
<EnableTwoFactorModal
|
|
|
|
onEnable={() => {
|
|
|
|
setEnabled(true);
|
|
|
|
setEnableModalOpen(false);
|
|
|
|
}}
|
|
|
|
onCancel={() => setEnableModalOpen(false)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{disableModalOpen && (
|
|
|
|
<DisableTwoFactorModal
|
|
|
|
onDisable={() => {
|
|
|
|
setEnabled(false);
|
|
|
|
setDisableModalOpen(false);
|
|
|
|
}}
|
|
|
|
onCancel={() => setDisableModalOpen(false)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TwoFactorAuthSection;
|