Merge branch 'IDTEAM-1.26.0' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / calendar / settingsRoutes.ts
blob525a56a614092c0d164ddc8070c93d874f29358c
1 import { getSlugFromApp } from '@proton/shared/lib/apps/slugHelper';
2 import { CALENDAR_SETTINGS_ROUTE } from '@proton/shared/lib/calendar/constants';
3 import { APPS } from '@proton/shared/lib/constants';
4 import { validateBase64string } from '@proton/shared/lib/helpers/encoding';
6 interface GetPathOptions {
7     fullPath?: boolean;
8     sectionId?: string;
11 const getPathWithOptions = (relativePath: string, options?: GetPathOptions) => {
12     const { fullPath, sectionId } = options || {};
14     let path = `${relativePath}`;
16     if (fullPath) {
17         path = `/${getSlugFromApp(APPS.PROTONCALENDAR)}${path}`;
18     }
20     if (sectionId) {
21         path = `${path}#${sectionId}`;
22     }
24     return path;
27 export const getGeneralSettingsPath = (options?: GetPathOptions) => {
28     return getPathWithOptions(CALENDAR_SETTINGS_ROUTE.GENERAL, options);
31 export const getCalendarsSettingsPath = (options?: GetPathOptions) => {
32     return getPathWithOptions(CALENDAR_SETTINGS_ROUTE.CALENDARS, options);
35 export const getInteroperabilityOperationsPath = (options?: GetPathOptions) => {
36     return getPathWithOptions(CALENDAR_SETTINGS_ROUTE.INTEROPS, options);
39 export const getCalendarSubpagePath = (calendarID: string, options?: GetPathOptions) => {
40     return getPathWithOptions(`${getCalendarsSettingsPath()}/${calendarID}`, options);
43 export const getIsCalendarSubpage = (pathname: string, calendarsSectionTo: string) => {
44     // The calendar subpage is accessed via /calendar/calendars/calendarId
45     const calendarsSectionPath = `/${getSlugFromApp(APPS.PROTONCALENDAR)}${calendarsSectionTo}`;
47     const regexString = `^${calendarsSectionPath}/(.*)`.replaceAll('/', '\\/');
48     const match = (new RegExp(regexString).exec(pathname) || [])[1];
49     if (!match) {
50         return false;
51     }
53     return validateBase64string(match, true);