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 {
11 const getPathWithOptions = (relativePath: string, options?: GetPathOptions) => {
12 const { fullPath, sectionId } = options || {};
14 let path = `${relativePath}`;
17 path = `/${getSlugFromApp(APPS.PROTONCALENDAR)}${path}`;
21 path = `${path}#${sectionId}`;
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];
53 return validateBase64string(match, true);