1 import { c } from 'ttag';
3 import { Button, Scroll } from '@proton/atoms';
4 import Info from '@proton/components/components/link/Info';
5 import Loader from '@proton/components/components/loader/Loader';
6 import useModalState from '@proton/components/components/modalTwo/useModalState';
7 import MailUpsellButton from '@proton/components/components/upsell/MailUpsellButton';
8 import LabelsUpsellModal from '@proton/components/components/upsell/modal/types/LabelsUpsellModal';
9 import SettingsLayout from '@proton/components/containers/account/SettingsLayout';
10 import SettingsLayoutLeft from '@proton/components/containers/account/SettingsLayoutLeft';
11 import SettingsLayoutRight from '@proton/components/containers/account/SettingsLayoutRight';
12 import SettingsSection from '@proton/components/containers/account/SettingsSection';
13 import { useLoading } from '@proton/hooks';
14 import { orderAllFolders } from '@proton/shared/lib/api/labels';
15 import { MAIL_UPSELL_PATHS } from '@proton/shared/lib/constants';
16 import { hasReachedFolderLimit } from '@proton/shared/lib/helpers/folder';
18 import { useApi, useEventManager, useFolders, useMailSettings, useNotifications, useUser } from '../../hooks';
19 import FolderTreeViewList from './FolderTreeViewList';
20 import ToggleEnableFolderColor from './ToggleEnableFolderColor';
21 import ToggleInheritParentFolderColor from './ToggleInheritParentFolderColor';
22 import EditLabelModal from './modals/EditLabelModal';
24 function ScrollWrapper({ children, scroll }: { children: JSX.Element; scroll?: boolean }) {
26 <Scroll className="overflow-hidden pb-2 h-custom" style={{ '--h-custom': '50rem' }}>
34 export default function FoldersSection() {
35 const [user] = useUser();
36 const [folders = [], loadingFolders] = useFolders();
37 const [mailSettings] = useMailSettings();
38 const [loading, withLoading] = useLoading();
39 const { call } = useEventManager();
41 const { createNotification } = useNotifications();
43 const canCreateFolder = !hasReachedFolderLimit(user, folders);
45 const [editLabelProps, setEditLabelModalOpen] = useModalState();
46 const [upsellModalProps, handleUpsellModalDisplay, renderUpsellModal] = useModalState();
48 const handleSortAllFolders = async () => {
49 await api(orderAllFolders());
51 createNotification({ text: c('Success message after sorting folders').t`Folders sorted` });
62 <label htmlFor="folder-colors" className="text-semibold">
63 {c('Label').t`Use folder colors`}
66 <SettingsLayoutRight isToggleContainer>
67 <ToggleEnableFolderColor id="folder-colors" />
68 </SettingsLayoutRight>
71 {mailSettings?.EnableFolderColor ? (
74 <label htmlFor="parent-folder-color" className="text-semibold">
75 <span className="mr-1">{c('Label').t`Inherit color from parent folder`}</span>
77 title={c('Info - folder colouring feature')
78 .t`When enabled, sub-folders inherit the color of the parent folder.`}
82 <SettingsLayoutRight isToggleContainer>
83 <ToggleInheritParentFolderColor id="parent-folder-color" />
84 </SettingsLayoutRight>
88 <div className="flex gap-4 my-7 folders-action">
90 <Button color="norm" onClick={() => setEditLabelModalOpen(true)}>
91 {c('Action').t`Add folder`}
95 onClick={() => handleUpsellModalDisplay(true)}
96 text={c('Action').t`Get more folders`}
102 title={c('Title').t`Sort folders alphabetically`}
104 onClick={() => withLoading(handleSortAllFolders())}
106 {c('Action').t`Sort`}
112 // 17 is the number of elements before we have more than 50rem, will be replaced soon by a fix in scroll component
113 <ScrollWrapper scroll={folders.length > 17}>
114 <FolderTreeViewList items={folders} />
118 <EditLabelModal {...editLabelProps} type="folder" />
120 {renderUpsellModal && (
122 modalProps={upsellModalProps}
123 feature={MAIL_UPSELL_PATHS.UNLIMITED_FOLDERS}