2022-10-19 09:33:40 +00:00
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-04 15:40:46 +00:00
|
|
|
import { Button } from "@calcom/ui/components";
|
|
|
|
import { Label, Form } from "@calcom/ui/components/form";
|
|
|
|
import { Switch, Skeleton, showToast } from "@calcom/ui/v2/core";
|
2022-10-19 09:33:40 +00:00
|
|
|
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();
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data: user } = trpc.viewer.me.useQuery();
|
|
|
|
const mutation = trpc.viewer.updateProfile.useMutation({
|
2022-10-19 09:33:40 +00:00
|
|
|
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 (
|
|
|
|
<>
|
|
|
|
<Meta title="Impersonation Settings" description="" />
|
|
|
|
<Form
|
|
|
|
form={formMethods}
|
|
|
|
handleSubmit={({ disableImpersonation }) => {
|
|
|
|
mutation.mutate({ disableImpersonation });
|
2022-11-10 23:40:01 +00:00
|
|
|
utils.viewer.me.invalidate();
|
2022-10-19 09:33:40 +00:00
|
|
|
}}>
|
|
|
|
<div className="flex space-x-3">
|
|
|
|
<Switch
|
|
|
|
{...formMethods.register("disableImpersonation")}
|
|
|
|
defaultChecked={!user?.disableImpersonation}
|
|
|
|
onCheckedChange={(e) => {
|
|
|
|
setValue("disableImpersonation", !e);
|
|
|
|
}}
|
|
|
|
fitToHeight={true}
|
|
|
|
/>
|
|
|
|
<div className="flex flex-col">
|
|
|
|
<Skeleton as={Label} className="text-sm font-semibold leading-none text-black">
|
|
|
|
{t("user_impersonation_heading")}
|
|
|
|
</Skeleton>
|
|
|
|
<Skeleton as="p" className="-mt-2 text-sm leading-normal text-gray-600">
|
|
|
|
{t("user_impersonation_description")}
|
|
|
|
</Skeleton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Button color="primary" className="mt-8" type="submit" disabled={isSubmitting || mutation.isLoading}>
|
|
|
|
{t("update")}
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ProfileImpersonationView.getLayout = getLayout;
|
|
|
|
|
|
|
|
export default ProfileImpersonationView;
|