forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
393 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/twenty-front/src/modules/favorites/components/FavoritesFolders.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { useState } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import { IconFolder } from 'twenty-ui'; | ||
|
||
import { CurrentWorkspaceMemberFavorites } from '@/favorites/components/CurrentWorkspaceMemberFavorites'; | ||
import { FavoriteFolderHotkeyScope } from '@/favorites/constants/FavoriteFolderRightIconDropdownHotkeyScope'; | ||
import { useFavoriteFolders } from '@/favorites/hooks/useFavoriteFolders'; | ||
import { isFavoriteFolderCreatingState } from '@/favorites/states/isFavoriteFolderCreatingState'; | ||
import { NavigationDrawerInput } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerInput'; | ||
|
||
type FavoriteFoldersProps = { | ||
isNavigationSectionOpen: boolean; | ||
}; | ||
|
||
export const FavoriteFolders = ({ | ||
isNavigationSectionOpen, | ||
}: FavoriteFoldersProps) => { | ||
const [activeFolderId, setActiveFolderId] = useState<string | null>(null); | ||
const [folderName, setFolderName] = useState(''); | ||
|
||
const { createFolder, favoritesByFolder } = useFavoriteFolders(); | ||
const [isFavoriteFolderCreating, setIsFavoriteFolderCreating] = | ||
useRecoilState(isFavoriteFolderCreatingState); | ||
|
||
const handleFolderNameChange = (value: string) => { | ||
setFolderName(value); | ||
}; | ||
|
||
const handleSubmitFolder = async (value: string) => { | ||
if (!value) return false; | ||
|
||
setIsFavoriteFolderCreating(false); | ||
setFolderName(''); | ||
await createFolder(value); | ||
return true; | ||
}; | ||
|
||
const handleClickOutside = async ( | ||
event: MouseEvent | TouchEvent, | ||
value: string, | ||
) => { | ||
if (!value) { | ||
setIsFavoriteFolderCreating(false); | ||
return; | ||
} | ||
|
||
setIsFavoriteFolderCreating(false); | ||
setFolderName(''); | ||
await createFolder(value); | ||
}; | ||
|
||
const handleCancel = () => { | ||
setFolderName(''); | ||
setIsFavoriteFolderCreating(false); | ||
}; | ||
|
||
if (!isNavigationSectionOpen) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
{isFavoriteFolderCreating && ( | ||
<NavigationDrawerInput | ||
Icon={IconFolder} | ||
value={folderName} | ||
onChange={handleFolderNameChange} | ||
onSubmit={handleSubmitFolder} | ||
onCancel={handleCancel} | ||
onClickOutside={handleClickOutside} | ||
hotkeyScope={FavoriteFolderHotkeyScope.FavoriteFolderNavigationInput} | ||
/> | ||
)} | ||
{favoritesByFolder.map((folder) => ( | ||
<CurrentWorkspaceMemberFavorites | ||
key={folder.folderId} | ||
folder={folder} | ||
isGroup={favoritesByFolder.length > 1} | ||
isOpen={activeFolderId === folder.folderId} | ||
onToggle={(folderId) => { | ||
setActiveFolderId((currentId) => | ||
currentId === folderId ? null : folderId, | ||
); | ||
}} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.