diff --git a/src/api/__tests__/client/client.test.ts b/src/api/__tests__/client/client.test.ts index 3e45c50..e98fd62 100644 --- a/src/api/__tests__/client/client.test.ts +++ b/src/api/__tests__/client/client.test.ts @@ -124,6 +124,21 @@ describe("client", () => { expect(formatApiErrorMessage("forbidden", "tr")).toBe("Bu işlem için yetkin yok."); }); + it("localizes slot-overlap conflicts (no half-English fallback)", () => { + // exact backend strings (lowercase) must map, not fall through to "İşlem tamamlanamadı: " + expect(formatApiErrorMessage("this time overlaps a slot you have already published", "tr")).toBe( + "Bu zaman aralığı, daha önce yayınladığın bir müsaitlikle çakışıyor.", + ); + expect(formatApiErrorMessage("a repeated slot overlaps one you have already published", "tr")).toBe( + "Tekrarlanan müsaitliklerden biri, daha önce yayınladığın bir müsaitlikle çakışıyor.", + ); + expect(formatApiErrorMessage("the repeated slots overlap each other", "en")).toBe("The repeated slots overlap each other."); + // a 409 ApiError carrying the backend message resolves the same way + expect(formatApiError(new ApiError(409, "this time overlaps a slot you have already published"), "tr")).toBe( + "Bu zaman aralığı, daha önce yayınladığın bir müsaitlikle çakışıyor.", + ); + }); + it("handles unknown messages with sentence case", () => { expect(formatApiErrorMessage("custom error occurred", "en")).toBe("Custom error occurred"); expect(formatApiErrorMessage("custom error occurred", "tr")).toBe("İşlem tamamlanamadı: Custom error occurred"); diff --git a/src/api/client/client.ts b/src/api/client/client.ts index 19a2432..0e477d7 100644 --- a/src/api/client/client.ts +++ b/src/api/client/client.ts @@ -78,6 +78,18 @@ const API_ERROR_MESSAGES: Record> = { en: "This note already has the maximum number of files.", tr: "Bu notta en fazla dosya sayısına ulaşılmış.", }, + "this time overlaps a slot you have already published": { + en: "This time overlaps a slot you already published.", + tr: "Bu zaman aralığı, daha önce yayınladığın bir müsaitlikle çakışıyor.", + }, + "a repeated slot overlaps one you have already published": { + en: "One of the repeated slots overlaps a slot you already published.", + tr: "Tekrarlanan müsaitliklerden biri, daha önce yayınladığın bir müsaitlikle çakışıyor.", + }, + "the repeated slots overlap each other": { + en: "The repeated slots overlap each other.", + tr: "Tekrarlanan müsaitlikler birbiriyle çakışıyor.", + }, "course not found": { en: "Course not found.", tr: "Ders bulunamadı.", diff --git a/src/lib/format.ts b/src/lib/format.ts index 2b05094..1fd4f7a 100644 --- a/src/lib/format.ts +++ b/src/lib/format.ts @@ -8,6 +8,14 @@ export function formatDateTime(ms: number | null | undefined, locale: Locale = " }).format(new Date(ms)); } +/** Date only, no time — for stacked date/time cells. */ +export function formatDate(ms: number | null | undefined, locale: Locale = "en"): string { + if (ms == null) return "—"; + return new Intl.DateTimeFormat(locale === "tr" ? "tr-TR" : "en-US", { + dateStyle: "medium", + }).format(new Date(ms)); +} + /** Convert datetime-local input value to unix ms, or null if empty. */ export function localInputToMs(value: string): number | null { if (!value) return null; diff --git a/src/pages/appointments-page.tsx b/src/pages/appointments-page.tsx index ffadfdd..08289d6 100644 --- a/src/pages/appointments-page.tsx +++ b/src/pages/appointments-page.tsx @@ -35,7 +35,7 @@ import { appointmentStatusClass, appointmentStatusDotClass, appointmentStatusLab import { cn } from "@/lib/cn"; import { createFlash } from "@/lib/flash"; import { createNow } from "@/lib/create-now"; -import { formatDateTime } from "@/lib/format"; +import { formatDate, formatDateTime } from "@/lib/format"; import { personLabel } from "@/lib/person"; import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; @@ -119,6 +119,19 @@ function AppointmentsContent() { sameDay(starts, ends) ? `${formatDateTime(starts, locale())} – ${timeOnly(ends)}` : `${formatDateTime(starts, locale())} — ${formatDateTime(ends, locale())}`; + // Stacked date/time cell: date on top, clock range below (tabular-nums so + // digits line up across rows). Same-day windows show one date; cross-day + // spells out the end date on the second line. + const timeCell = (starts: number | null, ends: number | null) => ( +
+ {formatDate(starts, locale())} + + {sameDay(starts, ends) + ? `${timeOnly(starts)} – ${timeOnly(ends)}` + : `${timeOnly(starts)} → ${formatDate(ends, locale())} ${timeOnly(ends)}`} + +
+ ); const statusBadge = (status: AppointmentStatus) => ( @@ -151,8 +164,8 @@ function AppointmentsContent() { { id: "time", header: t("appointments.time"), - meta: { headerClass: "w-56", cellClass: "mono text-xs text-muted-foreground align-top whitespace-normal break-words pr-4" }, - cell: (cell) => timeWindow(cell.row.original.starts_at, cell.row.original.ends_at), + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, + cell: (cell) => timeCell(cell.row.original.starts_at, cell.row.original.ends_at), }, { id: "note", @@ -221,12 +234,12 @@ function AppointmentsContent() { { id: "time", header: t("appointments.time"), - meta: { headerClass: "w-56", cellClass: "mono text-xs text-muted-foreground align-top whitespace-normal break-words pr-4" }, + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, cell: (cell) => ( -
-
{timeWindow(cell.row.original.starts_at, cell.row.original.ends_at)}
+
+ {timeCell(cell.row.original.starts_at, cell.row.original.ends_at)} -
{t("appointments.rescheduleProposed")}
+
{t("appointments.rescheduleProposed")}
), @@ -274,8 +287,8 @@ function AppointmentsContent() { { id: "time", header: t("appointments.time"), - meta: { headerClass: "w-56", cellClass: "mono text-xs text-muted-foreground align-top whitespace-normal break-words pr-4" }, - cell: (cell) => timeWindow(cell.row.original.starts_at, cell.row.original.ends_at), + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, + cell: (cell) => timeCell(cell.row.original.starts_at, cell.row.original.ends_at), }, { id: "note", @@ -307,12 +320,13 @@ function AppointmentsContent() { { id: "time", header: t("appointments.time"), - meta: { headerClass: "w-56", cellClass: "mono text-xs text-muted-foreground align-top whitespace-normal break-words pr-4" }, + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, cell: (cell) => ( -
-
{timeWindow(cell.row.original.starts_at, cell.row.original.ends_at)}
+
+ {timeCell(cell.row.original.starts_at, cell.row.original.ends_at)} -
{t("appointments.proposedTime")}: {timeWindow(cell.row.original.proposed_starts_at, cell.row.original.proposed_ends_at)}
+
{t("appointments.proposedTime")}:
+ {timeCell(cell.row.original.proposed_starts_at, cell.row.original.proposed_ends_at)}
),