You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{useRouter}from"next/router";import{z}from"zod";importNoSSRfrom"@calcom/core/components/NoSSR";import{getParserWithGeneric}from"@calcom/prisma/zod-utils";import{trpc}from"@calcom/trpc/react";import{Meta,showToast}from"@calcom/ui";import{getLayout}from"../../../settings/layouts/SettingsLayout";importLicenseRequiredfrom"../../common/components/v2/LicenseRequired";import{UserForm}from"../components/UserForm";import{userBodySchema}from"../schemas/userBodySchema";constuserIdSchema=z.object({id: z.coerce.number()});constUsersEditPage=()=>{constrouter=useRouter();constinput=userIdSchema.safeParse(router.query);if(!input.success)return<div>Invalid input</div>;return<UsersEditViewuserId={input.data.id}/>;};constUsersEditView=({ userId }: {userId: number})=>{constrouter=useRouter();const[data]=trpc.viewer.users.get.useSuspenseQuery({ userId });const{ user }=data;constutils=trpc.useContext();constmutation=trpc.viewer.users.update.useMutation({onSuccess: async()=>{awaitutils.viewer.users.list.invalidate();awaitutils.viewer.users.get.invalidate();showToast("User updated successfully","success");router.replace(`${router.asPath.split("/users/")[0]}/users`);},onError: (err)=>{console.error(err.message);showToast("There has been an error updating this user.","error");},});return(<LicenseRequired><Metatitle={`Editing user: ${user.username}`}description="Here you can edit a current user."/><NoSSR><UserFormkey={JSON.stringify(user)}onSubmit={(values)=>{constparser=getParserWithGeneric(userBodySchema);constparsedValues=parser(values);constdata: Partial<typeofparsedValues&{userId: number}>={
...parsedValues,userId: user.id,};// TODO: Add support for avatar in the APIdeletedata.avatar;// Don't send username if it's the same as the current oneif(user.username===data.username)deletedata.username;mutation.mutate(data);}}defaultValues={user}/></NoSSR></LicenseRequired>);};UsersEditPage.getLayout=getLayout;exportdefaultUsersEditPage;
https://api.github.com/OperationSTART/cal/blob/05726ec94ce419190d158dc33080a82c54a15e02/packages/features/ee/users/pages/users-edit-view.tsx#L55