Chore: Duplicate certain user fields to workspaceMember (#1514)
* Move certain user fields to workspaceMember Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Merge main Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Update the generated GraphQL Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Update hooks Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> * Rework typing * Fix tests * Remove console logs --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: chiazokam <chiazokamecheta@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -20,6 +20,33 @@ export const USER_QUERY_FRAGMENT = gql`
|
||||
logo
|
||||
inviteHash
|
||||
}
|
||||
assignedActivities {
|
||||
id
|
||||
title
|
||||
}
|
||||
authoredActivities {
|
||||
id
|
||||
title
|
||||
}
|
||||
authoredAttachments {
|
||||
id
|
||||
name
|
||||
type
|
||||
}
|
||||
settings {
|
||||
id
|
||||
colorScheme
|
||||
locale
|
||||
}
|
||||
companies {
|
||||
id
|
||||
name
|
||||
domainName
|
||||
}
|
||||
comments {
|
||||
id
|
||||
body
|
||||
}
|
||||
}
|
||||
settings {
|
||||
id
|
||||
|
||||
@ -60,7 +60,21 @@ export function useAuth() {
|
||||
throw new Error('No verify result');
|
||||
}
|
||||
|
||||
setCurrentUser(verifyResult.data?.verify.user);
|
||||
if (!verifyResult.data?.verify.user.workspaceMember) {
|
||||
throw new Error('No workspace member');
|
||||
}
|
||||
|
||||
if (!verifyResult.data?.verify.user.workspaceMember.settings) {
|
||||
throw new Error('No settings');
|
||||
}
|
||||
|
||||
setCurrentUser({
|
||||
...verifyResult.data?.verify.user,
|
||||
workspaceMember: {
|
||||
...verifyResult.data?.verify.user.workspaceMember,
|
||||
settings: verifyResult.data?.verify.user.workspaceMember.settings,
|
||||
},
|
||||
});
|
||||
setTokenPair(verifyResult.data?.verify.tokens);
|
||||
|
||||
return verifyResult.data?.verify;
|
||||
|
||||
@ -1,8 +1,32 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
import { GetCurrentUserQuery } from '~/generated/graphql';
|
||||
import {
|
||||
User,
|
||||
UserSettings,
|
||||
Workspace,
|
||||
WorkspaceMember,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
export type CurrentUser = GetCurrentUserQuery['currentUser'];
|
||||
export type CurrentUser = Pick<
|
||||
User,
|
||||
| 'id'
|
||||
| 'email'
|
||||
| 'displayName'
|
||||
| 'firstName'
|
||||
| 'lastName'
|
||||
| 'avatarUrl'
|
||||
| 'canImpersonate'
|
||||
| 'supportUserHash'
|
||||
> & {
|
||||
workspaceMember: Pick<WorkspaceMember, 'id' | 'allowImpersonation'> & {
|
||||
workspace: Pick<
|
||||
Workspace,
|
||||
'id' | 'displayName' | 'domainName' | 'inviteHash' | 'logo'
|
||||
>;
|
||||
settings: Pick<UserSettings, 'id' | 'colorScheme' | 'locale'>;
|
||||
};
|
||||
settings: Pick<UserSettings, 'id' | 'colorScheme' | 'locale'>;
|
||||
};
|
||||
|
||||
export const currentUserState = atom<CurrentUser | null>({
|
||||
key: 'currentUserState',
|
||||
|
||||
Reference in New Issue
Block a user