"use client"; import { useState } from "react"; import { useCreateTrip, useUpdateTrip } from "@/lib/hooks"; import type { TripRow } from "@/lib/hooks"; export function CreateTripModal({ trip, onClose, }: { trip?: TripRow; onClose: () => void; }) { const isEdit = !!trip; const [name, setName] = useState(trip?.name ?? ""); const [description, setDescription] = useState(trip?.description ?? ""); const [startDate, setStartDate] = useState(trip?.start_date?.slice(0, 10) ?? ""); const [endDate, setEndDate] = useState(trip?.end_date?.slice(0, 10) ?? ""); const [color, setColor] = useState(trip?.color ?? "#6366f1"); const [archived, setArchived] = useState(trip?.archived ?? false); const [error, setError] = useState(""); const createTrip = useCreateTrip(); const updateTrip = useUpdateTrip(); const isPending = createTrip.isPending || updateTrip.isPending; async function handleSave() { setError(""); if (!name.trim()) { setError("Name is required"); return; } try { if (isEdit) { await updateTrip.mutateAsync({ id: trip!.id, name: name.trim(), description: description || null, start_date: startDate || null, end_date: endDate || null, color, archived, }); } else { await createTrip.mutateAsync({ name: name.trim(), description: description || null, start_date: startDate || null, end_date: endDate || null, color, archived, }); } onClose(); } catch (e) { setError(e instanceof Error ? e.message : "Failed to save"); } } return (
e.stopPropagation()} >

{isEdit ? "Edit Trip" : "New Trip"}

setName(e.target.value)} placeholder="e.g. Europe 2026" className="w-full bg-zinc-800 border border-zinc-700 rounded px-2 py-1.5 text-sm focus:outline-none focus:border-zinc-500" />