Removing Prisma and Grapql-nestjs-prisma resolvers (#2574)
* Some cleaning * Fix seeds * Fix all sign in, sign up flow and apiKey optimistic rendering * Fix
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
import { useFilteredSearchEntityQuery } from '@/search/hooks/useFilteredSearchEntityQuery';
|
||||
import { useQuery } from '@apollo/client';
|
||||
|
||||
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
|
||||
import { useFilteredSearchEntityQueryV2 } from '@/search/hooks/useFilteredSearchEntityQueryV2';
|
||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||
import { ObjectFilterDropdownEntitySearchSelect } from '@/ui/object/object-filter-dropdown/components/ObjectFilterDropdownEntitySearchSelect';
|
||||
import { useFilter } from '@/ui/object/object-filter-dropdown/hooks/useFilter';
|
||||
import { useSearchUserQuery } from '~/generated/graphql';
|
||||
|
||||
export const FilterDropdownUserSearchSelect = () => {
|
||||
const {
|
||||
@ -10,31 +12,40 @@ export const FilterDropdownUserSearchSelect = () => {
|
||||
objectFilterDropdownSelectedEntityId,
|
||||
} = useFilter();
|
||||
|
||||
const usersForSelect = useFilteredSearchEntityQuery({
|
||||
queryHook: useSearchUserQuery,
|
||||
const { findManyQuery } = useFindOneObjectMetadataItem({
|
||||
objectNameSingular: 'workspaceMember',
|
||||
});
|
||||
|
||||
const useFindManyWorkspaceMembers = (options: any) =>
|
||||
useQuery(findManyQuery, options);
|
||||
|
||||
const workspaceMembers = useFilteredSearchEntityQueryV2({
|
||||
queryHook: useFindManyWorkspaceMembers,
|
||||
filters: [
|
||||
{
|
||||
fieldNames: ['firstName', 'lastName'],
|
||||
fieldNames: ['name.firstName', 'name.lastName'],
|
||||
filter: objectFilterDropdownSearchInput,
|
||||
},
|
||||
],
|
||||
orderByField: 'lastName',
|
||||
mappingFunction: (user) => ({
|
||||
id: user.id,
|
||||
entityType: Entity.User,
|
||||
name: `${user.displayName}`,
|
||||
orderByField: 'createdAt',
|
||||
mappingFunction: (workspaceMember) => ({
|
||||
entityType: Entity.WorkspaceMember,
|
||||
id: workspaceMember.id,
|
||||
name:
|
||||
workspaceMember.name.firstName + ' ' + workspaceMember.name.lastName,
|
||||
avatarType: 'rounded',
|
||||
avatarUrl: user.avatarUrl ?? '',
|
||||
originalEntity: user,
|
||||
avatarUrl: '',
|
||||
originalEntity: workspaceMember,
|
||||
}),
|
||||
selectedIds: objectFilterDropdownSelectedEntityId
|
||||
? [objectFilterDropdownSelectedEntityId]
|
||||
: [],
|
||||
objectNamePlural: 'workspaceMembers',
|
||||
});
|
||||
|
||||
return (
|
||||
<ObjectFilterDropdownEntitySearchSelect
|
||||
entitiesForSelect={usersForSelect}
|
||||
entitiesForSelect={workspaceMembers}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@ -1,80 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useQuery } from '@apollo/client';
|
||||
|
||||
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';
|
||||
|
||||
export type UserPickerProps = {
|
||||
userId: string;
|
||||
onSubmit: (newUser: EntityForSelect | null) => void;
|
||||
onCancel?: () => void;
|
||||
width?: number;
|
||||
initialSearchFilter?: string | null;
|
||||
};
|
||||
|
||||
export const UserPicker = ({
|
||||
userId,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
width,
|
||||
initialSearchFilter,
|
||||
}: UserPickerProps) => {
|
||||
const [relationPickerSearchFilter, setRelationPickerSearchFilter] =
|
||||
useRecoilScopedState(relationPickerSearchFilterScopedState);
|
||||
|
||||
useEffect(() => {
|
||||
setRelationPickerSearchFilter(initialSearchFilter ?? '');
|
||||
}, [initialSearchFilter, setRelationPickerSearchFilter]);
|
||||
|
||||
const { findManyQuery } = useFindOneObjectMetadataItem({
|
||||
objectNameSingular: 'workspaceMemberV2',
|
||||
});
|
||||
|
||||
const useFindManyWorkspaceMembers = (options: any) =>
|
||||
useQuery(findManyQuery, options);
|
||||
|
||||
const workspaceMembers = useFilteredSearchEntityQueryV2({
|
||||
queryHook: useFindManyWorkspaceMembers,
|
||||
filters: [
|
||||
{
|
||||
fieldNames: ['name.firstName', 'name.lastName'],
|
||||
filter: relationPickerSearchFilter,
|
||||
},
|
||||
],
|
||||
orderByField: 'createdAt',
|
||||
mappingFunction: (workspaceMember) => ({
|
||||
entityType: Entity.WorkspaceMember,
|
||||
id: workspaceMember.id,
|
||||
name:
|
||||
workspaceMember.name.firstName + ' ' + workspaceMember.name.lastName,
|
||||
avatarType: 'rounded',
|
||||
avatarUrl: '',
|
||||
originalEntity: workspaceMember,
|
||||
}),
|
||||
selectedIds: userId ? [userId] : [],
|
||||
objectNamePlural: 'workspaceMembersV2',
|
||||
});
|
||||
|
||||
const handleEntitySelected = async (selectedUser: any | null | undefined) => {
|
||||
onSubmit(selectedUser ?? null);
|
||||
};
|
||||
|
||||
return (
|
||||
<SingleEntitySelect
|
||||
EmptyIcon={IconUserCircle}
|
||||
emptyLabel="No Owner"
|
||||
entitiesToSelect={workspaceMembers.entitiesToSelect}
|
||||
loading={workspaceMembers.loading}
|
||||
onCancel={onCancel}
|
||||
onEntitySelected={handleEntitySelected}
|
||||
selectedEntity={workspaceMembers.selectedEntities[0]}
|
||||
width={width}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@ -1,21 +1,14 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
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';
|
||||
import { ColorScheme } from '@/workspace-member/types/WorkspaceMember';
|
||||
import { useGetCurrentUserQuery } from '~/generated/graphql';
|
||||
|
||||
export const UserProvider = ({ children }: React.PropsWithChildren) => {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isWorkspaceMemberLoading, setIsWorkspaceMemberLoading] =
|
||||
useState(true);
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
const setCurrentUser = useSetRecoilState(currentUserState);
|
||||
const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState);
|
||||
@ -23,48 +16,28 @@ export const UserProvider = ({ children }: React.PropsWithChildren) => {
|
||||
currentWorkspaceMemberState,
|
||||
);
|
||||
|
||||
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();
|
||||
const { data: userData, loading: userLoading } = useGetCurrentUserQuery({});
|
||||
|
||||
useEffect(() => {
|
||||
if (!userLoading && !workspaceLoading && !isWorkspaceMemberLoading) {
|
||||
if (!userLoading) {
|
||||
setIsLoading(false);
|
||||
}
|
||||
if (userData?.currentUser) {
|
||||
if (userData?.currentUser?.workspaceMember) {
|
||||
setCurrentUser(userData.currentUser);
|
||||
}
|
||||
if (workspaceData?.currentWorkspace) {
|
||||
setCurrentWorkspace(workspaceData.currentWorkspace);
|
||||
setCurrentWorkspace(userData.currentUser.defaultWorkspace);
|
||||
const workspaceMember = userData.currentUser.workspaceMember;
|
||||
setCurrentWorkspaceMember({
|
||||
...workspaceMember,
|
||||
colorScheme: (workspaceMember.colorScheme as ColorScheme) ?? 'Light',
|
||||
});
|
||||
}
|
||||
}, [
|
||||
setCurrentUser,
|
||||
isLoading,
|
||||
userLoading,
|
||||
workspaceLoading,
|
||||
userData?.currentUser,
|
||||
workspaceData?.currentWorkspace,
|
||||
setCurrentWorkspace,
|
||||
isWorkspaceMemberLoading,
|
||||
setCurrentWorkspaceMember,
|
||||
userData?.currentUser,
|
||||
]);
|
||||
|
||||
return isLoading ? <></> : <>{children}</>;
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const USER_FIELDS_FRAGMENT = gql`
|
||||
fragment userFieldsFragment on User {
|
||||
id
|
||||
email
|
||||
displayName
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
`;
|
||||
@ -0,0 +1,30 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const USER_QUERY_FRAGMENT = gql`
|
||||
fragment UserQueryFragment on User {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
canImpersonate
|
||||
supportUserHash
|
||||
workspaceMember {
|
||||
id
|
||||
name {
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
colorScheme
|
||||
avatarUrl
|
||||
locale
|
||||
allowImpersonation
|
||||
}
|
||||
defaultWorkspace {
|
||||
id
|
||||
displayName
|
||||
logo
|
||||
domainName
|
||||
inviteHash
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -2,7 +2,7 @@ import { gql } from '@apollo/client';
|
||||
|
||||
export const DELETE_USER_ACCOUNT = gql`
|
||||
mutation DeleteUserAccount {
|
||||
deleteUserAccount {
|
||||
deleteUser {
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const REMOVE_PROFILE_PICTURE = gql`
|
||||
mutation RemoveProfilePicture($where: UserWhereUniqueInput!) {
|
||||
updateUser(data: { avatarUrl: null }, where: $where) {
|
||||
id
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -1,10 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const UPDATE_ALLOW_IMPERSONATION = gql`
|
||||
mutation UpdateAllowImpersonation($allowImpersonation: Boolean!) {
|
||||
allowImpersonation(allowImpersonation: $allowImpersonation) {
|
||||
id
|
||||
allowImpersonation
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -1,10 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const UPDATE_USER = gql`
|
||||
mutation UpdateUser($data: UserUpdateInput!, $where: UserWhereUniqueInput!) {
|
||||
updateUser(data: $data, where: $where) {
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -1,6 +1,6 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const UPDATE_PROFILE_PICTURE = gql`
|
||||
export const UPLOAD_PROFILE_PICTURE = gql`
|
||||
mutation UploadProfilePicture($file: Upload!) {
|
||||
uploadProfilePicture(file: $file)
|
||||
}
|
||||
@ -3,9 +3,30 @@ import { gql } from '@apollo/client';
|
||||
export const GET_CURRENT_USER = gql`
|
||||
query GetCurrentUser {
|
||||
currentUser {
|
||||
...userFieldsFragment
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
canImpersonate
|
||||
supportUserHash
|
||||
workspaceMember {
|
||||
id
|
||||
name {
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
colorScheme
|
||||
avatarUrl
|
||||
locale
|
||||
allowImpersonation
|
||||
}
|
||||
defaultWorkspace {
|
||||
id
|
||||
displayName
|
||||
logo
|
||||
domainName
|
||||
inviteHash
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const GET_USERS = gql`
|
||||
query GetUsers {
|
||||
findManyUser {
|
||||
...userFieldsFragment
|
||||
}
|
||||
}
|
||||
`;
|
||||
Reference in New Issue
Block a user