# Introduction This PR is highly related to previous optimistic cache refactor: https://github.com/twentyhq/twenty/pull/9881 Here we've added some logic within the `triggerUpdateRelationsOptimisticEffect` which will now run if given recordInput `deletedAt` field is defined. If deletion, we will iterate over all the fields searching for `RELATION` for which deletion might implies necessity to detach the relation ## Known troubleshooting ( also on main )  We might have to refactor the `prefillRecord` to spread and overrides`inputValue` over defaultOne as inputValue could be a partial one for more info please a look to # Conclusion Any suggestions are welcomed ! fixes https://github.com/twentyhq/twenty/issues/9580 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
|
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
|
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 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,
|
|
});
|
|
};
|
|
|
|
return { createNewFavoriteFolder };
|
|
};
|