import { CalendarDays, Check, ChevronLeft, RefreshCw, type LucideIcon } from 'lucide-react' import { useId, useState, type ReactNode } from 'react' import { useNavigate } from 'react-router' import { Button } from '../ui/Button.tsx' import buttonStyles from '../ui/Button.module.css' import { Card } from '../ui/Card.tsx' import { ErrorBanner } from '../ui/ErrorBanner.tsx' import { Icon } from '../ui/Icon.tsx' import { IconButton } from '../ui/IconButton.tsx' import { Select } from '../ui/Select.tsx' import { Skeleton } from '../ui/Skeleton.tsx' import { GOOGLE_CONNECT_PATH, useChooseGoogleCalendar, useDisconnectGoogle, useGoogleCalendars, useGoogleConnection, type GoogleConnection, } from './calendarApi.ts' import styles from './CalendarSettingsPage.module.css' import { Confirm } from './LeaveGuard.tsx' // Settings · Google Calendar: connect the household's Google account, choose // the calendar Push to Calendar writes the week's dinners to, and // disconnect. A grant Google has refused shows a grape banner asking to // reconnect, and nothing that needs Google is offered until then. export function CalendarSettingsPage() { const connection = useGoogleConnection() return (
Push to Calendar adds one event per dinner. It is one-way: edits made in Google Calendar do not come back.
{connection.isPending &&Settings
Connect the household's Google account to push each week's plan to one of its calendars.
{connection.calendar_name === null ? 'No calendar chosen. Choose one once Google Calendar is reconnected.' : `Dinners go to ${connection.calendar_name} once Google Calendar is reconnected.`}
{error}
}Nothing can be pushed to Calendar until you connect again.
This Google account has no calendar MealQuest can add dinners to.
} const listed = calendars.data.some((calendar) => calendar.id === connection.calendar_id) const value = choose.isPending ? choose.variables : listed ? connection.calendar_id! : '' return ( <> {connection.calendar_id === null &&Choose the calendar to push dinners to.
} {connection.calendar_id !== null && !listed && ({connection.calendar_name} was deleted or MealQuest can no longer add dinners to it. Choose another calendar.
)}{choose.isPending && 'Saving…'}
{choose.isError && (Not saved: {choose.error.message}
)}After choosing another calendar, the next push writes the whole week there. Dinners already pushed stay where they are.
> ) } // Disconnect revokes MealQuest's access at Google, after asking. function Disconnect({ calendar }: { calendar: string | null }) { const [confirming, setConfirming] = useState(false) const disconnect = useDisconnectGoogle() return ( <>