import { useForm } from "react-hook-form"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Button } from "@calcom/ui/components"; import { Label, Form } from "@calcom/ui/components/form"; import { Switch, Skeleton, showToast } from "@calcom/ui/v2/core"; import Meta from "@calcom/ui/v2/core/Meta"; import { getLayout } from "@calcom/ui/v2/core/layouts/SettingsLayout"; const ProfileImpersonationView = () => { const { t } = useLocale(); const utils = trpc.useContext(); const { data: user } = trpc.useQuery(["viewer.me"]); const mutation = trpc.useMutation("viewer.updateProfile", { onSuccess: () => { showToast(t("profile_updated_successfully"), "success"); }, onError: (error) => { showToast(`${t("error")}, ${error.message}`, "error"); }, }); const formMethods = useForm<{ disableImpersonation: boolean }>({ defaultValues: { disableImpersonation: user?.disableImpersonation, }, }); const { formState: { isSubmitting }, setValue, } = formMethods; return ( <>
{ mutation.mutate({ disableImpersonation }); utils.invalidateQueries(["viewer.me"]); }}>
{ setValue("disableImpersonation", !e); }} fitToHeight={true} />
{t("user_impersonation_heading")} {t("user_impersonation_description")}
); }; ProfileImpersonationView.getLayout = getLayout; export default ProfileImpersonationView;