diff --git a/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataItemsLoadEffect.tsx b/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataItemsLoadEffect.tsx index aeb16de86a66..6130ecf9d1d8 100644 --- a/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataItemsLoadEffect.tsx +++ b/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataItemsLoadEffect.tsx @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import { useRecoilCallback, useRecoilValue } from 'recoil'; +import { useRecoilState, useRecoilValue } from 'recoil'; import { useIsLogged } from '@/auth/hooks/useIsLogged'; import { currentUserState } from '@/auth/states/currentUserState'; @@ -21,31 +21,30 @@ export const ObjectMetadataItemsLoadEffect = () => { skip: !isLoggedIn, }); - const updateObjectMetadataItems = useRecoilCallback( - ({ set, snapshot }) => - () => { - const toSetObjectMetadataItems = - isUndefinedOrNull(currentUser) || - currentWorkspace?.activationStatus !== - WorkspaceActivationStatus.Active - ? generatedMockObjectMetadataItems - : newObjectMetadataItems; - - if ( - !isDeeplyEqual( - snapshot.getLoadable(objectMetadataItemsState).getValue(), - toSetObjectMetadataItems, - ) - ) { - set(objectMetadataItemsState, toSetObjectMetadataItems); - } - }, - [currentUser, currentWorkspace?.activationStatus, newObjectMetadataItems], + console.log('a', newObjectMetadataItems); + + const [objectMetadataItems, setObjectMetadataItems] = useRecoilState( + objectMetadataItemsState, ); useEffect(() => { - updateObjectMetadataItems(); - }, [updateObjectMetadataItems]); + const toSetObjectMetadataItems = + isUndefinedOrNull(currentUser) || + currentWorkspace?.activationStatus !== WorkspaceActivationStatus.Active + ? generatedMockObjectMetadataItems + : newObjectMetadataItems; + + console.log(toSetObjectMetadataItems); + if (!isDeeplyEqual(objectMetadataItems, toSetObjectMetadataItems)) { + setObjectMetadataItems(toSetObjectMetadataItems); + } + }, [ + currentUser, + currentWorkspace?.activationStatus, + newObjectMetadataItems, + objectMetadataItems, + setObjectMetadataItems, + ]); return <>; }; diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneFieldMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneFieldMetadataItem.ts index bd49c6343e3a..7af63b78b586 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneFieldMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneFieldMetadataItem.ts @@ -1,5 +1,4 @@ import { ApolloClient, useMutation } from '@apollo/client'; -import { getOperationName } from '@apollo/client/utilities'; import { CreateFieldInput, @@ -8,7 +7,6 @@ import { } from '~/generated-metadata/graphql'; import { CREATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations'; -import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries'; import { v4 } from 'uuid'; import { useApolloMetadataClient } from './useApolloMetadataClient'; @@ -30,8 +28,6 @@ export const useCreateOneFieldMetadataItem = () => { field: input, }, }, - awaitRefetchQueries: true, - refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''], optimisticResponse: { createOneField: { ...input, diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneObjectMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneObjectMetadataItem.ts index 5853500c6ba2..7680bdc6b0f7 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneObjectMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneObjectMetadataItem.ts @@ -1,5 +1,4 @@ import { ApolloClient, useApolloClient, useMutation } from '@apollo/client'; -import { getOperationName } from '@apollo/client/utilities'; import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; import { useFindManyRecordsQuery } from '@/object-record/hooks/useFindManyRecordsQuery'; @@ -10,7 +9,6 @@ import { } from '~/generated-metadata/graphql'; import { CREATE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations'; -import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries'; import { v4 } from 'uuid'; import { useApolloMetadataClient } from './useApolloMetadataClient'; @@ -35,18 +33,18 @@ export const useCreateOneObjectMetadataItem = () => { variables: { input: { object: input }, }, - awaitRefetchQueries: true, - refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''], optimisticResponse: { createOneObject: { ...input, createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + labelIdentifierFieldMetadataId: '', + imageIdentifierFieldMetadataId: '', __typename: 'object', id: v4(), dataSourceId: '', isCustom: false, - isActive: false, - updatedAt: undefined, + isActive: true, }, }, }); diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneFieldMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneFieldMetadataItem.ts index a7f116495739..e0d9e2c20766 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneFieldMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneFieldMetadataItem.ts @@ -1,5 +1,4 @@ import { ApolloClient, useMutation } from '@apollo/client'; -import { getOperationName } from '@apollo/client/utilities'; import { DeleteOneFieldMetadataItemMutation, @@ -7,7 +6,6 @@ import { } from '~/generated-metadata/graphql'; import { DELETE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations'; -import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries'; import { useApolloMetadataClient } from './useApolloMetadataClient'; @@ -29,7 +27,6 @@ export const useDeleteOneFieldMetadataItem = () => { idToDelete, }, awaitRefetchQueries: true, - refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''], optimisticResponse: { deleteOneField: { id: idToDelete, diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneObjectMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneObjectMetadataItem.ts index aa00e0d9552b..ffe42ee6be2b 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneObjectMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneObjectMetadataItem.ts @@ -1,5 +1,4 @@ import { ApolloClient, useMutation } from '@apollo/client'; -import { getOperationName } from '@apollo/client/utilities'; import { DeleteOneObjectMetadataItemMutation, @@ -7,7 +6,6 @@ import { } from '~/generated-metadata/graphql'; import { DELETE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations'; -import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries'; import { useApolloMetadataClient } from './useApolloMetadataClient'; @@ -28,8 +26,6 @@ export const useDeleteOneObjectMetadataItem = () => { variables: { idToDelete, }, - awaitRefetchQueries: true, - refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''], optimisticResponse: { deleteOneObject: { id: idToDelete, diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useUpdateOneFieldMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useUpdateOneFieldMetadataItem.ts index c7c5c2ec9073..89917f005621 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useUpdateOneFieldMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useUpdateOneFieldMetadataItem.ts @@ -1,5 +1,4 @@ import { useMutation } from '@apollo/client'; -import { getOperationName } from '@apollo/client/utilities'; import { FieldMetadataType, @@ -8,7 +7,6 @@ import { } from '~/generated-metadata/graphql'; import { UPDATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations'; -import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries'; import { useApolloMetadataClient } from './useApolloMetadataClient'; @@ -46,8 +44,6 @@ export const useUpdateOneFieldMetadataItem = () => { label: updatePayload.label ?? undefined, }, }, - awaitRefetchQueries: true, - refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''], optimisticResponse: { updateOneField: { id: fieldMetadataIdToUpdate, diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useUpdateOneObjectMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useUpdateOneObjectMetadataItem.ts index fcc18ea60ef2..ac74c26ffdc6 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useUpdateOneObjectMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useUpdateOneObjectMetadataItem.ts @@ -1,5 +1,4 @@ import { useMutation } from '@apollo/client'; -import { getOperationName } from '@apollo/client/utilities'; import { UpdateOneObjectInput, @@ -8,7 +7,6 @@ import { } from '~/generated-metadata/graphql'; import { UPDATE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations'; -import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries'; import { useApolloMetadataClient } from './useApolloMetadataClient'; @@ -35,8 +33,6 @@ export const useUpdateOneObjectMetadataItem = () => { idToUpdate, updatePayload, }, - awaitRefetchQueries: true, - refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''], optimisticResponse: { updateOneObject: { id: idToUpdate,