[WIP] Whole FE migrated (#2517)
* Wip * WIP * Removed concole log * Add relations to workspace init (#2511) * Add relations to workspace init * remove logs * update prefill * add missing isSystem * comment relation fields * Migrate v2 core models to graphql schema (#2509) * migrate v2 core models to graphql schema * Migrate to new workspace member schema * Continue work * migrated-main * Finished accountOwner nested field integration on companies * Introduce bug * Fix --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com> Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
@ -1,13 +1,14 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useQuery } from '@apollo/client';
|
||||
|
||||
import { useFilteredSearchEntityQuery } from '@/search/hooks/useFilteredSearchEntityQuery';
|
||||
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
|
||||
import { useFilteredSearchEntityQueryV2 } from '@/search/hooks/useFilteredSearchEntityQueryV2';
|
||||
import { IconUserCircle } from '@/ui/display/icon';
|
||||
import { SingleEntitySelect } from '@/ui/input/relation-picker/components/SingleEntitySelect';
|
||||
import { relationPickerSearchFilterScopedState } from '@/ui/input/relation-picker/states/relationPickerSearchFilterScopedState';
|
||||
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
|
||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||
import { useSearchUserQuery } from '~/generated/graphql';
|
||||
|
||||
export type UserPickerProps = {
|
||||
userId: string;
|
||||
@ -18,7 +19,7 @@ export type UserPickerProps = {
|
||||
};
|
||||
|
||||
type UserForSelect = EntityForSelect & {
|
||||
entityType: Entity.User;
|
||||
entityType: Entity.WorkspaceMember;
|
||||
};
|
||||
|
||||
export const UserPicker = ({
|
||||
@ -35,29 +36,39 @@ export const UserPicker = ({
|
||||
setRelationPickerSearchFilter(initialSearchFilter ?? '');
|
||||
}, [initialSearchFilter, setRelationPickerSearchFilter]);
|
||||
|
||||
const users = useFilteredSearchEntityQuery({
|
||||
queryHook: useSearchUserQuery,
|
||||
const { findManyQuery } = useFindOneObjectMetadataItem({
|
||||
objectNamePlural: 'workspaceMembersV2',
|
||||
});
|
||||
|
||||
const useFindManyWorkspaceMembers = () => useQuery(findManyQuery, {});
|
||||
|
||||
// TODO: put workspace member
|
||||
const users = useFilteredSearchEntityQueryV2({
|
||||
queryHook: useFindManyWorkspaceMembers,
|
||||
filters: [
|
||||
{
|
||||
fieldNames: ['firstName', 'lastName'],
|
||||
filter: relationPickerSearchFilter,
|
||||
},
|
||||
],
|
||||
orderByField: 'firstName',
|
||||
mappingFunction: (user) => ({
|
||||
entityType: Entity.User,
|
||||
id: user.id,
|
||||
name: user.displayName,
|
||||
orderByField: '',
|
||||
mappingFunction: (workspaceMember) => ({
|
||||
entityType: Entity.WorkspaceMember,
|
||||
id: workspaceMember.id,
|
||||
name: workspaceMember.firstName,
|
||||
avatarType: 'rounded',
|
||||
avatarUrl: user.avatarUrl ?? '',
|
||||
originalEntity: user,
|
||||
avatarUrl: '',
|
||||
originalEntity: workspaceMember,
|
||||
}),
|
||||
selectedIds: userId ? [userId] : [],
|
||||
objectNamePlural: 'workspaceMembersV2',
|
||||
});
|
||||
|
||||
const handleEntitySelected = async (
|
||||
selectedUser: UserForSelect | null | undefined,
|
||||
) => {
|
||||
console.log({
|
||||
users,
|
||||
});
|
||||
|
||||
const handleEntitySelected = async (selectedUser: any | null | undefined) => {
|
||||
onSubmit(selectedUser ?? null);
|
||||
};
|
||||
|
||||
|
||||
@ -1,29 +1,71 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
import { useGetCurrentUserQuery } from '~/generated/graphql';
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
||||
import { FIND_ONE_WORKSPACE_MEMBER_V2 } from '@/object-record/graphql/queries/findOneWorkspaceMember';
|
||||
import {
|
||||
useGetCurrentUserQuery,
|
||||
useGetCurrentWorkspaceQuery,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
export const UserProvider = ({ children }: React.PropsWithChildren) => {
|
||||
const [, setCurrentUser] = useRecoilState(currentUserState);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isWorkspaceMemberLoading, setIsWorkspaceMemberLoading] =
|
||||
useState(true);
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
const { data, loading } = useGetCurrentUserQuery();
|
||||
const setCurrentUser = useSetRecoilState(currentUserState);
|
||||
const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState);
|
||||
const setCurrentWorkspaceMember = useSetRecoilState(
|
||||
currentWorkspaceMemberState,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
setIsLoading(false);
|
||||
}
|
||||
if (data?.currentUser?.workspaceMember?.settings) {
|
||||
setCurrentUser({
|
||||
...data.currentUser,
|
||||
workspaceMember: {
|
||||
...data.currentUser.workspaceMember,
|
||||
settings: data.currentUser.workspaceMember.settings,
|
||||
const { data: userData, loading: userLoading } = useGetCurrentUserQuery({
|
||||
onCompleted: async (data) => {
|
||||
const workspaceMember = await apolloClient.query({
|
||||
query: FIND_ONE_WORKSPACE_MEMBER_V2,
|
||||
variables: {
|
||||
filter: {
|
||||
userId: { eq: data.currentUser.id },
|
||||
},
|
||||
},
|
||||
});
|
||||
setCurrentWorkspaceMember(
|
||||
workspaceMember.data.workspaceMembersV2.edges[0].node,
|
||||
);
|
||||
setIsWorkspaceMemberLoading(false);
|
||||
},
|
||||
onError: () => {
|
||||
setIsWorkspaceMemberLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
const { data: workspaceData, loading: workspaceLoading } =
|
||||
useGetCurrentWorkspaceQuery();
|
||||
|
||||
useEffect(() => {
|
||||
if (!userLoading && !workspaceLoading && !isWorkspaceMemberLoading) {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [setCurrentUser, data, isLoading, loading]);
|
||||
if (userData?.currentUser) {
|
||||
setCurrentUser(userData.currentUser);
|
||||
}
|
||||
if (workspaceData?.currentWorkspace) {
|
||||
setCurrentWorkspace(workspaceData.currentWorkspace);
|
||||
}
|
||||
}, [
|
||||
setCurrentUser,
|
||||
isLoading,
|
||||
userLoading,
|
||||
workspaceLoading,
|
||||
userData?.currentUser,
|
||||
workspaceData?.currentWorkspace,
|
||||
setCurrentWorkspace,
|
||||
isWorkspaceMemberLoading,
|
||||
]);
|
||||
|
||||
return isLoading ? <></> : <>{children}</>;
|
||||
};
|
||||
|
||||
@ -5,52 +5,6 @@ export const UPDATE_USER = gql`
|
||||
updateUser(data: $data, where: $where) {
|
||||
id
|
||||
email
|
||||
displayName
|
||||
firstName
|
||||
lastName
|
||||
avatarUrl
|
||||
workspaceMember {
|
||||
id
|
||||
workspace {
|
||||
id
|
||||
domainName
|
||||
displayName
|
||||
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
|
||||
locale
|
||||
colorScheme
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -4,16 +4,7 @@ export const GET_CURRENT_USER = gql`
|
||||
query GetCurrentUser {
|
||||
currentUser {
|
||||
...userFieldsFragment
|
||||
avatarUrl
|
||||
canImpersonate
|
||||
workspaceMember {
|
||||
...workspaceMemberFieldsFragment
|
||||
}
|
||||
settings {
|
||||
id
|
||||
locale
|
||||
colorScheme
|
||||
}
|
||||
supportUserHash
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user