1 import { c } from 'ttag';
3 import { EasySwitchOauthImportButton, EasySwitchProvider } from '@proton/activation';
4 import { EASY_SWITCH_SOURCES, ImportProvider, ImportType } from '@proton/activation/src/interface';
5 import { Href } from '@proton/atoms';
6 import Alert from '@proton/components/components/alert/Alert';
7 import PrimaryButton from '@proton/components/components/button/PrimaryButton';
8 import useModalState from '@proton/components/components/modalTwo/useModalState';
9 import SettingsParagraph from '@proton/components/containers/account/SettingsParagraph';
10 import SettingsSection from '@proton/components/containers/account/SettingsSection';
11 import { getProbablyActiveCalendars, getWritableCalendars } from '@proton/shared/lib/calendar/calendar';
12 import { IMPORT_CALENDAR_FAQ_URL } from '@proton/shared/lib/calendar/constants';
13 import { CALENDAR_APP_NAME } from '@proton/shared/lib/constants';
14 import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
15 import type { UserModel } from '@proton/shared/lib/interfaces';
16 import type { VisualCalendar } from '@proton/shared/lib/interfaces/calendar';
17 import { useFlag } from '@proton/unleash';
19 import { ImportModal } from '../importModal';
22 calendars: VisualCalendar[];
23 initialCalendar?: VisualCalendar;
27 const CalendarImportSection = ({ calendars, initialCalendar, user }: Props) => {
28 const { hasNonDelinquentScope } = user;
29 const isImporterInMaintenance = useFlag('MaintenanceImporter');
31 const activeWritableCalendars = getWritableCalendars(getProbablyActiveCalendars(calendars));
32 const hasActiveCalendars = !!activeWritableCalendars.length;
34 const [importModal, setIsImportModalOpen, renderImportModal] = useModalState();
36 const handleManualImport = () => setIsImportModalOpen(true);
40 {renderImportModal && initialCalendar && (
42 isOpen={importModal.open}
43 initialCalendar={initialCalendar}
49 {hasNonDelinquentScope && !hasActiveCalendars ? (
50 <Alert className="mb-4" type="warning">
51 {c('Info').t`You need to have an active personal calendar to import your events from ICS.`}
56 {c('Calendar import section description')
57 .t`You can import ICS files from another calendar to ${CALENDAR_APP_NAME}. This lets you quickly import one event or your entire agenda.`}
59 <Href href={getKnowledgeBaseUrl(IMPORT_CALENDAR_FAQ_URL)}>{c('Knowledge base link label')
60 .t`Here's how`}</Href>
63 {!isImporterInMaintenance && (
65 <EasySwitchOauthImportButton
67 source={EASY_SWITCH_SOURCES.CALENDAR_WEB_SETTINGS}
68 defaultCheckedTypes={[ImportType.CALENDAR]}
69 displayOn={'GoogleCalendar'}
70 provider={ImportProvider.GOOGLE}
77 onClick={handleManualImport}
78 disabled={!hasNonDelinquentScope || !hasActiveCalendars}
80 {c('Action').t`Import from ICS`}
86 export default CalendarImportSection;