import React from 'react'; import { Modal, View, Text, Pressable, StyleSheet } from 'react-native'; import { Repeat, Trash2 } from '../icons'; import { radius, spacing, typography, type ThemePalette } from '../../theme/tokens'; import { useColors } from '../../theme/colors'; import { useLocaleStore } from '../../stores/locale-store'; import { Button } from '..'; import { MODAL_ORIENTATIONS } from '../../lib/modal-orientations'; export type RecurrenceEditScope = 'this' | 'this_and_future' | 'all'; interface RecurrenceScopeDialogProps { visible: boolean; actionType: 'edit' | 'delete' | 'rsvp'; onSelect: (scope: RecurrenceEditScope) => void; onClose: () => void; } const OPTIONS: { value: RecurrenceEditScope; key: string; fallback: string }[] = [ { value: 'this', key: 'calendar.recurrence_scope.this_event', fallback: 'This event only' }, { value: 'this_and_future', key: 'calendar.recurrence_scope.this_and_future', fallback: 'This and following events' }, { value: 'all', key: 'calendar.recurrence_scope.all_events', fallback: 'All events' }, ]; export function RecurrenceScopeDialog({ visible, actionType, onSelect, onClose, }: RecurrenceScopeDialogProps) { const c = useColors(); const styles = React.useMemo(() => makeStyles(c), [c]); const t = useLocaleStore((s) => s.t); const [selected, setSelected] = React.useState('this'); const isDelete = actionType === 'delete'; const isRsvp = actionType === 'rsvp'; // An attendee cannot split the organizer's series, so an answer covers // one occurrence or all of them (webmail #1086). const options = isRsvp ? OPTIONS.filter((opt) => opt.value !== 'this_and_future') : OPTIONS; React.useEffect(() => { if (visible) setSelected('this'); }, [visible]); return ( {isDelete ? ( ) : ( )} {isDelete ? t('calendar.recurrence_scope.delete_title', 'Delete recurring event') : isRsvp ? t('calendar.recurrence_scope.rsvp_title', 'Respond to recurring event') : t('calendar.recurrence_scope.edit_title', 'Edit recurring event')} {isRsvp ? t( 'calendar.recurrence_scope.rsvp_description', 'This is a recurring event. Which events does your response apply to?', ) : t( 'calendar.recurrence_scope.description', 'This is a recurring event. Which events would you like to modify?', )} {options.map((opt) => { const active = selected === opt.value; return ( setSelected(opt.value)} > {active && } {t(opt.key, opt.fallback)} ); })} ); } function makeStyles(c: ThemePalette) { return StyleSheet.create({ backdrop: { flex: 1, backgroundColor: 'rgba(0,0,0,0.5)', justifyContent: 'center', alignItems: 'center', padding: spacing.lg, }, dialog: { width: '100%', maxWidth: 400, backgroundColor: c.background, borderWidth: 1, borderColor: c.border, borderRadius: radius.lg, padding: spacing.xxl, gap: spacing.lg, }, header: { flexDirection: 'row', gap: spacing.md, alignItems: 'flex-start' }, iconBadge: { width: 40, height: 40, borderRadius: radius.full, alignItems: 'center', justifyContent: 'center', }, iconBadgeDanger: { backgroundColor: c.errorBg }, iconBadgePrimary: { backgroundColor: c.primaryBg }, headerText: { flex: 1 }, title: { ...typography.h3, color: c.text }, description: { ...typography.body, color: c.textMuted, marginTop: 4 }, options: { gap: spacing.xs }, option: { flexDirection: 'row', alignItems: 'center', gap: spacing.md, paddingHorizontal: spacing.md, paddingVertical: spacing.sm, borderRadius: radius.sm, borderWidth: 1, borderColor: 'transparent', }, optionActive: { backgroundColor: c.primaryBg, borderColor: c.primary }, radio: { width: 18, height: 18, borderRadius: 9, borderWidth: 1.5, borderColor: c.border, alignItems: 'center', justifyContent: 'center', }, radioActive: { borderColor: c.primary }, radioDot: { width: 8, height: 8, borderRadius: 4, backgroundColor: c.primary, }, optionLabel: { ...typography.body, color: c.text, flex: 1 }, footer: { flexDirection: 'row', justifyContent: 'flex-end', gap: spacing.md, }, }); }