mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-24 20:42:05 +03:00
Fix use object metadata item (#7297)
Fixes a bug which happened during workspace creation and remove duplicated code
This commit is contained in:
parent
9d36493cf0
commit
9f477129e2
@ -16,7 +16,7 @@ export const ObjectMetadataItemsLoadEffect = () => {
|
||||
const currentWorkspace = useRecoilValue(currentWorkspaceState);
|
||||
const isLoggedIn = useIsLogged();
|
||||
|
||||
const { objectMetadataItems: newObjectMetadataItems, loading } =
|
||||
const { objectMetadataItems: newObjectMetadataItems } =
|
||||
useFindManyObjectMetadataItems({
|
||||
skip: !isLoggedIn,
|
||||
});
|
||||
@ -31,16 +31,12 @@ export const ObjectMetadataItemsLoadEffect = () => {
|
||||
currentWorkspace?.activationStatus !== WorkspaceActivationStatus.Active
|
||||
? generatedMockObjectMetadataItems
|
||||
: newObjectMetadataItems;
|
||||
if (
|
||||
!loading &&
|
||||
!isDeeplyEqual(objectMetadataItems, toSetObjectMetadataItems)
|
||||
) {
|
||||
if (!isDeeplyEqual(objectMetadataItems, toSetObjectMetadataItems)) {
|
||||
setObjectMetadataItems(toSetObjectMetadataItems);
|
||||
}
|
||||
}, [
|
||||
currentUser,
|
||||
currentWorkspace?.activationStatus,
|
||||
loading,
|
||||
newObjectMetadataItems,
|
||||
objectMetadataItems,
|
||||
setObjectMetadataItems,
|
||||
|
@ -1,37 +1,23 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
||||
import { ObjectMetadataItemNotFoundError } from '@/object-metadata/errors/ObjectMetadataNotFoundError';
|
||||
import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector';
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
import { WorkspaceActivationStatus } from '~/generated/graphql';
|
||||
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/objectMetadataItems';
|
||||
import { ObjectMetadataItemIdentifier } from '../types/ObjectMetadataItemIdentifier';
|
||||
|
||||
export const useObjectMetadataItem = ({
|
||||
objectNameSingular,
|
||||
}: ObjectMetadataItemIdentifier) => {
|
||||
const currentWorkspace = useRecoilValue(currentWorkspaceState);
|
||||
|
||||
let objectMetadataItem = useRecoilValue(
|
||||
const objectMetadataItem = useRecoilValue(
|
||||
objectMetadataItemFamilySelector({
|
||||
objectName: objectNameSingular,
|
||||
objectNameType: 'singular',
|
||||
}),
|
||||
);
|
||||
|
||||
let objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
||||
|
||||
if (currentWorkspace?.activationStatus !== WorkspaceActivationStatus.Active) {
|
||||
objectMetadataItem =
|
||||
generatedMockObjectMetadataItems.find(
|
||||
(objectMetadataItem) =>
|
||||
objectMetadataItem.nameSingular === objectNameSingular,
|
||||
) ?? null;
|
||||
objectMetadataItems = generatedMockObjectMetadataItems;
|
||||
}
|
||||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
||||
|
||||
if (!isDefined(objectMetadataItem)) {
|
||||
throw new ObjectMetadataItemNotFoundError(
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
import { RecoilRoot } from 'recoil';
|
||||
|
||||
import { ClientConfigProviderEffect } from '@/client-config/components/ClientConfigProviderEffect';
|
||||
import { ObjectMetadataItemsProvider } from '@/object-metadata/components/ObjectMetadataItemsProvider';
|
||||
import { ApolloMetadataClientMockedProvider } from '@/object-metadata/hooks/__mocks__/ApolloMetadataClientProvider';
|
||||
import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
|
||||
import { UserProviderEffect } from '@/users/components/UserProviderEffect';
|
||||
@ -77,11 +76,9 @@ const Providers = () => {
|
||||
<HelmetProvider>
|
||||
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
|
||||
<IconsProvider>
|
||||
<ObjectMetadataItemsProvider>
|
||||
<PrefetchDataProvider>
|
||||
<Outlet />
|
||||
</PrefetchDataProvider>
|
||||
</ObjectMetadataItemsProvider>
|
||||
<PrefetchDataProvider>
|
||||
<Outlet />
|
||||
</PrefetchDataProvider>
|
||||
</IconsProvider>
|
||||
</SnackBarProviderScope>
|
||||
</HelmetProvider>
|
||||
|
Loading…
Reference in New Issue
Block a user