Files
twenty/packages/twenty-front/src/modules/favorites/components/FavoritesFolders.tsx
Paul Rastoin 4a4e65fe4a [REFACTOR] Twenty UI multi barrel (#11301)
# Introduction
closes https://github.com/twentyhq/core-team-issues/issues/591
Same than for `twenty-shared` made in
https://github.com/twentyhq/twenty/pull/11083.

## TODO
- [x] Manual migrate twenty-website twenty-ui imports

## What's next:
- Generate barrel and migration script factorization within own package
+ tests
- Refactoring using preconstruct ? TimeBox
- Lint circular dependencies
- Lint import from barrel and forbid them

### Preconstruct
We need custom rollup plugins addition, but preconstruct does not expose
its rollup configuration. It might be possible to handle this using the
babel overrides. But was a big tunnel.
We could give it a try afterwards ! ( allowing cjs interop and stuff
like that )
Stuck to vite lib app

Closed related PRs:
- https://github.com/twentyhq/twenty/pull/11294
- https://github.com/twentyhq/twenty/pull/11203
2025-04-03 09:47:55 +00:00

90 lines
2.9 KiB
TypeScript

import { CurrentWorkspaceMemberFavorites } from '@/favorites/components/CurrentWorkspaceMemberFavorites';
import { FavoriteFolderHotkeyScope } from '@/favorites/constants/FavoriteFolderRightIconDropdownHotkeyScope';
import { useCreateFavoriteFolder } from '@/favorites/hooks/useCreateFavoriteFolder';
import { useFavoritesByFolder } from '@/favorites/hooks/useFavoritesByFolder';
import { isFavoriteFolderCreatingState } from '@/favorites/states/isFavoriteFolderCreatingState';
import { NavigationDrawerAnimatedCollapseWrapper } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerAnimatedCollapseWrapper';
import { NavigationDrawerInput } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerInput';
import { useState } from 'react';
import { useRecoilState } from 'recoil';
import { IconFolder } from 'twenty-ui/display';
type FavoriteFoldersProps = {
isNavigationSectionOpen: boolean;
};
export const FavoriteFolders = ({
isNavigationSectionOpen,
}: FavoriteFoldersProps) => {
const [newFolderName, setNewFolderName] = useState('');
const { favoritesByFolder } = useFavoritesByFolder();
const { createNewFavoriteFolder } = useCreateFavoriteFolder();
const [isFavoriteFolderCreating, setIsFavoriteFolderCreating] =
useRecoilState(isFavoriteFolderCreatingState);
const handleFavoriteFolderNameChange = (value: string) => {
setNewFolderName(value);
};
const handleSubmitFavoriteFolderCreation = async (value: string) => {
if (value === '') return;
setIsFavoriteFolderCreating(false);
setNewFolderName('');
await createNewFavoriteFolder(value);
return true;
};
const handleClickOutside = async (
_event: MouseEvent | TouchEvent,
value: string,
) => {
if (!value) {
setIsFavoriteFolderCreating(false);
return;
}
setIsFavoriteFolderCreating(false);
setNewFolderName('');
await createNewFavoriteFolder(value);
};
const handleCancelFavoriteFolderCreation = () => {
setNewFolderName('');
setIsFavoriteFolderCreating(false);
};
if (!isNavigationSectionOpen) {
return null;
}
return (
<>
{isFavoriteFolderCreating && (
<NavigationDrawerAnimatedCollapseWrapper>
<NavigationDrawerInput
Icon={IconFolder}
value={newFolderName}
onChange={handleFavoriteFolderNameChange}
onSubmit={handleSubmitFavoriteFolderCreation}
onCancel={handleCancelFavoriteFolderCreation}
onClickOutside={handleClickOutside}
hotkeyScope={
FavoriteFolderHotkeyScope.FavoriteFolderNavigationInput
}
/>
</NavigationDrawerAnimatedCollapseWrapper>
)}
{favoritesByFolder.map((folder) => (
<CurrentWorkspaceMemberFavorites
key={folder.folderId}
folder={folder}
isGroup={favoritesByFolder.length > 1}
/>
))}
</>
);
};