2021-09-21 09:29:20 +00:00
|
|
|
import { useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
const TwoFactorAuthSection = ({ twoFactorEnabled }: { twoFactorEnabled: boolean }) => {
|
|
|
|
const [enabled, setEnabled] = useState(twoFactorEnabled);
|
|
|
|
const [enableModalOpen, setEnableModalOpen] = useState(false);
|
|
|
|
const [disableModalOpen, setDisableModalOpen] = useState(false);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="flex flex-row items-center">
|
2021-09-22 21:23:19 +00:00
|
|
|
<h2 className="font-cal text-lg leading-6 font-medium text-gray-900">Two-Factor Authentication</h2>
|
2021-09-21 09:29:20 +00:00
|
|
|
<Badge className="text-xs ml-2" variant={enabled ? "success" : "gray"}>
|
|
|
|
{enabled ? "Enabled" : "Disabled"}
|
|
|
|
</Badge>
|
|
|
|
</div>
|
|
|
|
<p className="mt-1 text-sm text-gray-500">
|
|
|
|
Add an extra layer of security to your account in case your password is stolen.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
className="mt-6"
|
|
|
|
type="submit"
|
|
|
|
onClick={() => (enabled ? setDisableModalOpen(true) : setEnableModalOpen(true))}>
|
|
|
|
{enabled ? "Disable" : "Enable"} Two-Factor Authentication
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
{enableModalOpen && (
|
|
|
|
<EnableTwoFactorModal
|
|
|
|
onEnable={() => {
|
|
|
|
setEnabled(true);
|
|
|
|
setEnableModalOpen(false);
|
|
|
|
}}
|
|
|
|
onCancel={() => setEnableModalOpen(false)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{disableModalOpen && (
|
|
|
|
<DisableTwoFactorModal
|
|
|
|
onDisable={() => {
|
|
|
|
setEnabled(false);
|
|
|
|
setDisableModalOpen(false);
|
|
|
|
}}
|
|
|
|
onCancel={() => setDisableModalOpen(false)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TwoFactorAuthSection;
|