feat(calendar): expose an accessible calendar picker
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
type CalendarPickerAuth = {
|
||||
tenant: { id: string };
|
||||
active_tenant?: { id: string };
|
||||
};
|
||||
|
||||
export type CalendarPickerOption = {
|
||||
id: string;
|
||||
name: string;
|
||||
is_default: boolean;
|
||||
};
|
||||
|
||||
export const CALENDAR_PICKER_READ_SCOPE = "calendar:calendar:read";
|
||||
|
||||
export function calendarPickerOptions<TCalendar extends CalendarPickerOption>(calendars: TCalendar[]): TCalendar[] {
|
||||
return [...calendars].sort((left, right) => {
|
||||
if (left.is_default !== right.is_default) return left.is_default ? -1 : 1;
|
||||
const nameDelta = left.name.localeCompare(right.name, undefined, { sensitivity: "base" });
|
||||
return nameDelta !== 0 ? nameDelta : left.id.localeCompare(right.id);
|
||||
});
|
||||
}
|
||||
|
||||
export function calendarPickerTenantId(auth: CalendarPickerAuth): string {
|
||||
return (auth.active_tenant ?? auth.tenant).id;
|
||||
}
|
||||
Reference in New Issue
Block a user