add firstname and lastname on current user state and sync it while cr… (#12781)
…eating profile and pass it to cal.com's embed
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { User } from '~/generated/graphql';
|
||||
import { createState } from 'twenty-ui/utilities';
|
||||
import { User } from '~/generated/graphql';
|
||||
|
||||
export type CurrentUser = Pick<
|
||||
User,
|
||||
@ -10,6 +10,8 @@ export type CurrentUser = Pick<
|
||||
| 'canImpersonate'
|
||||
| 'onboardingStatus'
|
||||
| 'userVars'
|
||||
| 'firstName'
|
||||
| 'lastName'
|
||||
>;
|
||||
|
||||
export const currentUserState = createState<CurrentUser | null>({
|
||||
|
||||
@ -24,6 +24,8 @@ const mockCurrentUser = {
|
||||
canImpersonate: false,
|
||||
onboardingStatus: OnboardingStatus.COMPLETED,
|
||||
userVars: {},
|
||||
firstName: 'fake-first-name',
|
||||
lastName: 'fake-last-name',
|
||||
};
|
||||
|
||||
const mockBilling: Billing = {
|
||||
|
||||
@ -64,6 +64,7 @@ export const BookCall = () => {
|
||||
layout: 'month_view',
|
||||
theme: theme.name === 'light' ? 'light' : 'dark',
|
||||
email: currentUser?.email ?? '',
|
||||
name: `${currentUser?.firstName} ${currentUser?.lastName}`,
|
||||
}}
|
||||
/>
|
||||
</StyledScrollWrapper>
|
||||
|
||||
@ -2,12 +2,13 @@ import styled from '@emotion/styled';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Controller, SubmitHandler, useForm } from 'react-hook-form';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { useRecoilState, useSetRecoilState } from 'recoil';
|
||||
import { Key } from 'ts-key-enum';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { SubTitle } from '@/auth/components/SubTitle';
|
||||
import { Title } from '@/auth/components/Title';
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
|
||||
@ -62,6 +63,7 @@ export const CreateProfile = () => {
|
||||
const [currentWorkspaceMember, setCurrentWorkspaceMember] = useRecoilState(
|
||||
currentWorkspaceMemberState,
|
||||
);
|
||||
const setCurrentUser = useSetRecoilState(currentUserState);
|
||||
const { updateOneRecord } = useUpdateOneRecord<WorkspaceMember>({
|
||||
objectNameSingular: CoreObjectNameSingular.WorkspaceMember,
|
||||
});
|
||||
@ -115,6 +117,18 @@ export const CreateProfile = () => {
|
||||
}
|
||||
return current;
|
||||
});
|
||||
|
||||
setCurrentUser((current) => {
|
||||
if (isDefined(current)) {
|
||||
return {
|
||||
...current,
|
||||
firstName: data.firstName,
|
||||
lastName: data.lastName,
|
||||
};
|
||||
}
|
||||
return current;
|
||||
});
|
||||
|
||||
setNextOnboardingStatus();
|
||||
} catch (error: any) {
|
||||
enqueueSnackBar(error?.message, {
|
||||
@ -127,6 +141,7 @@ export const CreateProfile = () => {
|
||||
setNextOnboardingStatus,
|
||||
enqueueSnackBar,
|
||||
setCurrentWorkspaceMember,
|
||||
setCurrentUser,
|
||||
updateOneRecord,
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user