2022-09-05 21:08:59 +00:00
|
|
|
import { useState } from "react";
|
2022-08-30 19:46:52 +00:00
|
|
|
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Badge, getSettingsLayout as getLayout, Loader, Meta, Switch } from "@calcom/ui";
|
2022-08-30 19:46:52 +00:00
|
|
|
|
2022-11-01 13:29:01 +00:00
|
|
|
import DisableTwoFactorModal from "@components/settings/DisableTwoFactorModal";
|
|
|
|
import EnableTwoFactorModal from "@components/settings/EnableTwoFactorModal";
|
2022-08-30 19:46:52 +00:00
|
|
|
|
|
|
|
const TwoFactorAuthView = () => {
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
|
|
|
|
const { t } = useLocale();
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data: user, isLoading } = trpc.viewer.me.useQuery();
|
2022-08-30 19:46:52 +00:00
|
|
|
|
|
|
|
const [enableModalOpen, setEnableModalOpen] = useState(false);
|
|
|
|
const [disableModalOpen, setDisableModalOpen] = useState(false);
|
|
|
|
|
|
|
|
if (isLoading) return <Loader />;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-09-14 09:42:48 +00:00
|
|
|
<Meta title="Two-Factor Authentication" description="Manage settings for your account passwords" />
|
2022-08-30 19:46:52 +00:00
|
|
|
<div className="mt-6 flex items-start space-x-4">
|
|
|
|
<Switch
|
|
|
|
checked={user?.twoFactorEnabled}
|
|
|
|
onCheckedChange={() =>
|
|
|
|
user?.twoFactorEnabled ? setDisableModalOpen(true) : setEnableModalOpen(true)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<div>
|
|
|
|
<div className="flex">
|
2022-09-05 21:08:59 +00:00
|
|
|
<p className="font-semibold">{t("two_factor_auth")}</p>
|
2022-08-30 19:46:52 +00:00
|
|
|
<Badge className="ml-2 text-xs" variant={user?.twoFactorEnabled ? "success" : "gray"}>
|
|
|
|
{user?.twoFactorEnabled ? t("enabled") : t("disabled")}
|
|
|
|
</Badge>
|
|
|
|
</div>
|
2022-09-05 21:08:59 +00:00
|
|
|
<p className="text-sm text-gray-600">Add an extra layer of security to your account.</p>
|
2022-08-30 19:46:52 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<EnableTwoFactorModal
|
|
|
|
open={enableModalOpen}
|
|
|
|
onOpenChange={() => setEnableModalOpen(!enableModalOpen)}
|
|
|
|
onEnable={() => {
|
|
|
|
setEnableModalOpen(false);
|
2022-11-10 23:40:01 +00:00
|
|
|
utils.viewer.me.invalidate();
|
2022-08-30 19:46:52 +00:00
|
|
|
}}
|
|
|
|
onCancel={() => {
|
|
|
|
setEnableModalOpen(false);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<DisableTwoFactorModal
|
|
|
|
open={disableModalOpen}
|
|
|
|
onOpenChange={() => setDisableModalOpen(!disableModalOpen)}
|
|
|
|
onDisable={() => {
|
|
|
|
setDisableModalOpen(false);
|
2022-11-10 23:40:01 +00:00
|
|
|
utils.viewer.me.invalidate();
|
2022-08-30 19:46:52 +00:00
|
|
|
}}
|
|
|
|
onCancel={() => {
|
|
|
|
setDisableModalOpen(false);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
TwoFactorAuthView.getLayout = getLayout;
|
|
|
|
|
|
|
|
export default TwoFactorAuthView;
|