1 import { c } from 'ttag';
3 import { BRAND_NAME, MAIL_SHORT_APP_NAME } from '../constants';
4 import type { VisualCalendar } from '../interfaces/calendar';
5 import { getOwnedPersonalCalendars } from './calendar';
6 import { MAX_CALENDARS_FREE, MAX_CALENDARS_PAID } from './constants';
8 export const getHasUserReachedCalendarsLimit = (calendars: VisualCalendar[], isFreeUser: boolean) => {
9 const ownedPersonalCalendars = getOwnedPersonalCalendars(calendars);
10 const maxPersonalCalendars = isFreeUser ? MAX_CALENDARS_FREE : MAX_CALENDARS_PAID;
12 // we enforce users to have at least one owned personal calendar
13 const isCalendarsLimitReached = calendars.length >= maxPersonalCalendars && ownedPersonalCalendars.length > 0;
16 isCalendarsLimitReached,
17 isOtherCalendarsLimitReached:
18 isCalendarsLimitReached || calendars.length - ownedPersonalCalendars.length >= maxPersonalCalendars - 1,
22 export const getCalendarsLimitReachedText = (isFreeUser: boolean) => {
23 const maxReachedText = c('Limit of calendars reached')
24 .t`You've reached the maximum number of calendars available in your plan.`;
25 const addNewCalendarText = isFreeUser
26 ? c('Limit of calendars reached')
27 .t`To add a new calendar, remove another calendar or upgrade your ${BRAND_NAME} plan to a ${MAIL_SHORT_APP_NAME} paid plan.`
28 : c('Limit of calendars reached').t`To add a new calendar, remove an existing one.`;
33 combinedText: `${maxReachedText} ${addNewCalendarText}`,
37 export const willUserReachCalendarsLimit = (
38 calendars: VisualCalendar[],
39 calendarsToCreateCount: number,
42 const maxCalendars = isFreeUser ? MAX_CALENDARS_FREE : MAX_CALENDARS_PAID;
43 const isCalendarsLimitReached = calendars.length + calendarsToCreateCount > maxCalendars;
45 return isCalendarsLimitReached;