Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 22:53:48 +00:00
co-authored by renee-png
parent be8229c39f
commit 8766376abd
+19 -10
View File
@@ -53,6 +53,7 @@ import {
} from "date-fns";
import { toast } from "sonner";
import { cn } from "@/lib/utils";
import { estWallTimeToUTC, formatInEST, toESTDate } from "@/lib/tz";
export const Route = createFileRoute("/calendar/")({
component: CalendarPage,
@@ -164,7 +165,7 @@ function CalendarPage() {
supabase
.from("events")
.select(
"id,title,start_at,end_at,all_day,event_type,case_id,client_id,location,description,created_by",
"id,title,start_at,end_at,all_day,event_type,case_id,client_id,location,description,created_by,assigned_to",
)
.gte("start_at", `${winStart}T00:00:00`)
.lte("start_at", `${winEnd}T23:59:59`)
@@ -204,7 +205,8 @@ function CalendarPage() {
const evts: Evt[] = [];
for (const e of eventsRes.data ?? []) {
const owner = e.created_by ? profileMap.get(e.created_by) : null;
const ownerId = (e.assigned_to as string | null) ?? e.created_by ?? null;
const owner = ownerId ? profileMap.get(ownerId) : null;
const c = e.case_id ? caseMap.get(e.case_id) : null;
const clientId = e.client_id ?? c?.client_id ?? null;
const cl = clientId ? clientMap.get(clientId) : null;
@@ -220,7 +222,7 @@ function CalendarPage() {
case_label: c ? `${c.case_number} — ${c.title}` : null,
client_id: clientId,
client_label: cl?.name ?? null,
owner_id: e.created_by,
owner_id: ownerId,
owner_name: owner?.full_name ?? null,
location: e.location ?? null,
description: e.description ?? null,
@@ -361,12 +363,14 @@ function CalendarPage() {
setEditingId(evt.id);
setFTitle(evt.title);
setFType((EVENT_TYPE_MAP[evt.event_type] ? evt.event_type : "other") as EventTypeKey);
const dt = parseISO(evt.start);
setFStart(dt);
// Convert UTC timestamp into the EST wall-clock so the date pickers and
// HH:mm inputs reflect what the user originally entered (in EST).
const estStart = toESTDate(evt.start);
setFStart(estStart);
setFAllDay(evt.all_day);
if (!evt.all_day) {
setFStartTime(format(dt, "HH:mm"));
setFEndTime(evt.end ? format(parseISO(evt.end), "HH:mm") : format(dt, "HH:mm"));
setFStartTime(formatInEST(evt.start, "HH:mm"));
setFEndTime(evt.end ? formatInEST(evt.end, "HH:mm") : formatInEST(evt.start, "HH:mm"));
}
setFCase(evt.case_id ?? "none");
setFClient(evt.client_id ?? "none");
@@ -383,8 +387,12 @@ function CalendarPage() {
}
setSaving(true);
const dateStr = format(fStart, "yyyy-MM-dd");
const startISO = fAllDay ? `${dateStr}T00:00:00` : `${dateStr}T${fStartTime}:00`;
const endISO = fAllDay ? null : `${dateStr}T${fEndTime}:00`;
// Times are entered as EST wall-clock; convert to a UTC ISO for storage so
// Postgres `timestamptz` records the correct instant regardless of browser TZ.
const startISO = fAllDay
? estWallTimeToUTC(dateStr, "00:00")
: estWallTimeToUTC(dateStr, fStartTime);
const endISO = fAllDay ? null : estWallTimeToUTC(dateStr, fEndTime);
const ownerId = fAssignee === "self" ? user.id : fAssignee;
const payload = {
@@ -397,11 +405,12 @@ function CalendarPage() {
client_id: fClient === "none" ? null : fClient,
location: fLocation.trim() || null,
description: fNotes.trim() || null,
assigned_to: ownerId,
};
const { error } = editingId
? await supabase.from("events").update(payload).eq("id", editingId)
: await supabase.from("events").insert({ ...payload, created_by: ownerId });
: await supabase.from("events").insert({ ...payload, created_by: user.id });
setSaving(false);
if (error) {
toast.error(error.message);