1 import { getUnixTime } from 'date-fns';
2 import { c } from 'ttag';
4 import { ButtonLike } from '@proton/atoms';
5 import { AppLink, Icon, ReloadSpinner, Tooltip } from '@proton/components';
6 import { getLinkToCalendarEvent } from '@proton/shared/lib/calendar/helper';
7 import { fromUTCDate, toLocalDate } from '@proton/shared/lib/date/timezone';
8 import type { CalendarEvent, CalendarEventSharedData } from '@proton/shared/lib/interfaces/calendar';
9 import noop from '@proton/utils/noop';
15 interface EditButtonProps extends BaseProps {
19 export const PopoverEditButton = ({ showButton, loading, onEdit }: EditButtonProps) => {
25 <Tooltip title={c('Edit event button tooltip').t`Edit event`}>
27 data-testid="event-popover:edit"
34 <Icon name="pen" alt={c('Edit event button tooltip').t`Edit event`} />
40 interface DeleteButtonProps extends BaseProps {
44 export const PopoverDeleteButton = ({ showButton, loading, onDelete }: DeleteButtonProps) => {
50 <Tooltip title={c('Delete event button tooltip').t`Delete event`}>
52 data-testid="event-popover:delete"
54 onClick={loading ? noop : onDelete}
59 <Icon name="trash" alt={c('Delete event button tooltip').t`Delete event`} />
65 interface DuplicateButtonProps extends BaseProps {
66 onDuplicate?: () => void;
69 export const PopoverDuplicateButton = ({ showButton, loading, onDuplicate }: DuplicateButtonProps) => {
75 <Tooltip title={c('Duplicate event button tooltip').t`Duplicate event`}>
77 data-testid="event-popover:duplicate"
84 <Icon name="squares" alt={c('Duplicate event button tooltip').t`Duplicate event`} />
90 interface ReloadButtonProps extends BaseProps {
91 onRefresh: () => void;
94 const PopoverRefreshButton = ({ showButton, loading, onRefresh }: ReloadButtonProps) => {
100 <Tooltip title={c('Reload event button tooltip').t`Reload event`}>
102 data-testid="event-popover:refresh"
104 onClick={loading ? noop : onRefresh}
108 <ReloadSpinner refreshing={loading} alt={c('Reload event button tooltip').t`Reload event`} />
114 interface PopoverViewButtonProps extends BaseProps {
115 isSearchView: boolean;
117 eventData?: CalendarEvent | CalendarEventSharedData;
118 onViewClick: () => void;
120 export const PopoverViewButton = ({
126 }: PopoverViewButtonProps) => {
133 getLinkToCalendarEvent({
134 calendarID: eventData.CalendarID,
135 eventID: eventData.ID,
136 recurrenceID: getUnixTime(toLocalDate(fromUTCDate(start))),
139 const viewText = isSearchView
140 ? c('View event button tooltip').t`Navigate to event`
141 : c('View event button tooltip').t`Open in a new tab`;
144 <Tooltip title={viewText}>
146 <ButtonLike data-testid="event-popover:open" shape="ghost" onClick={onViewClick} icon size="small">
147 <Icon name="arrow-out-square" size={3.5} alt={viewText} />
151 data-testid="event-popover:open-in-new-tab"
154 className="mr-2 button button-small button-ghost-weak button-for-icon"
156 <Icon name="arrow-out-square" size={3.5} alt={viewText} />
163 interface EventReloadErrorActionProps {
164 showDeleteButton: boolean;
165 showReloadButton: boolean;
166 loadingDelete: boolean;
167 loadingRefresh: boolean;
168 onDelete: () => void;
169 onRefresh: () => Promise<void>;
171 export const EventReloadErrorAction = ({
178 }: EventReloadErrorActionProps) => {
181 {showReloadButton && (
182 <div className="flex flex-nowrap justify-end">
183 <PopoverRefreshButton
184 loading={loadingRefresh}
185 showButton={showReloadButton}
186 onRefresh={onRefresh}
190 {showDeleteButton && (
191 <div className="flex flex-nowrap justify-end">
192 <PopoverDeleteButton showButton={showDeleteButton} loading={loadingDelete} onDelete={onDelete} />