b470cb21a1
## Summary This PR upgrades Apollo Client from v3.10.0 to v4 and refactors error handling patterns across the codebase to use a new centralized `useSnackBarOnQueryError` hook. ## Key Changes - **Dependency Update**: Upgraded `@apollo/client` from `^3.10.0` to `^3.11.0` in root package.json - **New Hook**: Added `useSnackBarOnQueryError` hook for centralized Apollo query error handling with snack bar notifications - **Error Handling Refactor**: Updated 100+ files to use the new error handling pattern: - Removed direct `ApolloError` imports where no longer needed - Replaced manual error handling logic with `useSnackBarOnQueryError` hook - Simplified error handling in hooks and components across multiple modules - **GraphQL Codegen**: Updated codegen configuration files to work with Apollo Client v3.11.0 - **Type Definitions**: Added TypeScript declaration file for `apollo-upload-client` module - **Test Updates**: Updated test files to reflect new error handling patterns ## Notable Implementation Details - The new `useSnackBarOnQueryError` hook provides a consistent way to handle Apollo query errors with automatic snack bar notifications - Changes span across multiple feature areas: auth, object records, settings, workflows, billing, and more - All changes maintain backward compatibility while improving code maintainability and reducing duplication - Jest configuration updated to work with the new Apollo Client version https://claude.ai/code/session_019WGZ6Rd7sEHuBg9sTrXRqJ --------- Co-authored-by: Claude <noreply@anthropic.com>
72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
import { usePrefetchedNavigationMenuItemsData } from '@/navigation-menu-item/hooks/usePrefetchedNavigationMenuItemsData';
|
|
import { CoreObjectNameSingular } from 'twenty-shared/types';
|
|
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { useMutation } from '@apollo/client/react';
|
|
import { CreateNavigationMenuItemDocument } from '~/generated-metadata/graphql';
|
|
import { usePrefetchedFavoritesData } from './usePrefetchedFavoritesData';
|
|
import { usePrefetchedFavoritesFoldersData } from './usePrefetchedFavoritesFoldersData';
|
|
|
|
export const useCreateFavoriteFolder = () => {
|
|
const { createOneRecord: createFavoriteFolder } = useCreateOneRecord({
|
|
objectNameSingular: CoreObjectNameSingular.FavoriteFolder,
|
|
});
|
|
|
|
const { currentWorkspaceMemberId } = usePrefetchedFavoritesData();
|
|
const { favoriteFolders } = usePrefetchedFavoritesFoldersData();
|
|
const { navigationMenuItems } = usePrefetchedNavigationMenuItemsData();
|
|
|
|
const [createNavigationMenuItemMutation] = useMutation(
|
|
CreateNavigationMenuItemDocument,
|
|
{
|
|
refetchQueries: ['FindManyNavigationMenuItems'],
|
|
},
|
|
);
|
|
|
|
const createNewFavoriteFolder = async (name: string): Promise<void> => {
|
|
if (!name || !currentWorkspaceMemberId) {
|
|
return;
|
|
}
|
|
|
|
const maxPosition = Math.max(
|
|
...favoriteFolders.map((folder) => folder.position),
|
|
0,
|
|
);
|
|
|
|
await createFavoriteFolder({
|
|
name,
|
|
position: maxPosition + 1,
|
|
});
|
|
|
|
const folderNavigationMenuItems = navigationMenuItems.filter(
|
|
(item) =>
|
|
isDefined(item.name) &&
|
|
!item.folderId &&
|
|
!item.targetRecordId &&
|
|
!item.targetObjectMetadataId &&
|
|
!item.viewId &&
|
|
item.userWorkspaceId === currentWorkspaceMemberId,
|
|
);
|
|
|
|
const maxNavigationMenuItemPosition = Math.max(
|
|
...folderNavigationMenuItems.map((item) => item.position),
|
|
0,
|
|
);
|
|
|
|
await createNavigationMenuItemMutation({
|
|
variables: {
|
|
input: {
|
|
name,
|
|
targetRecordId: null,
|
|
targetObjectMetadataId: null,
|
|
userWorkspaceId: currentWorkspaceMemberId,
|
|
folderId: null,
|
|
position: maxNavigationMenuItemPosition + 1,
|
|
},
|
|
},
|
|
});
|
|
};
|
|
|
|
return { createNewFavoriteFolder };
|
|
};
|