🗓️ stacked slot date/time cell + localized overlap errors
Browse files at this commit8bba96b9545914e0205716c7fa6538b8f7fde0b3Parent: e70073f- fix
- 🗓️ stacked slot date/time cell + localized overlap errors
4 changed files +62 -13
- src/api/__tests__/client/client.test.ts +15 -0
- src/api/client/client.ts +12 -0
- src/lib/format.ts +8 -0
- src/pages/appointments-page.tsx +27 -13
src/api/__tests__/client/client.test.tsmodified+15 -0
| @@ -124,6 +124,21 @@ describe("client", () => { | |||
| 124 | expect(formatApiErrorMessage("forbidden", "tr")).toBe("Bu işlem için yetkin yok."); | 124 | expect(formatApiErrorMessage("forbidden", "tr")).toBe("Bu işlem için yetkin yok."); |
| 125 | }); | 125 | }); |
| 126 | 126 | ||
| 127 | + it("localizes slot-overlap conflicts (no half-English fallback)", () => { | ||
| 128 | + // exact backend strings (lowercase) must map, not fall through to "İşlem tamamlanamadı: <english>" | ||
| 129 | + expect(formatApiErrorMessage("this time overlaps a slot you have already published", "tr")).toBe( | ||
| 130 | + "Bu zaman aralığı, daha önce yayınladığın bir müsaitlikle çakışıyor.", | ||
| 131 | + ); | ||
| 132 | + expect(formatApiErrorMessage("a repeated slot overlaps one you have already published", "tr")).toBe( | ||
| 133 | + "Tekrarlanan müsaitliklerden biri, daha önce yayınladığın bir müsaitlikle çakışıyor.", | ||
| 134 | + ); | ||
| 135 | + expect(formatApiErrorMessage("the repeated slots overlap each other", "en")).toBe("The repeated slots overlap each other."); | ||
| 136 | + // a 409 ApiError carrying the backend message resolves the same way | ||
| 137 | + expect(formatApiError(new ApiError(409, "this time overlaps a slot you have already published"), "tr")).toBe( | ||
| 138 | + "Bu zaman aralığı, daha önce yayınladığın bir müsaitlikle çakışıyor.", | ||
| 139 | + ); | ||
| 140 | + }); | ||
| 141 | + | ||
| 127 | it("handles unknown messages with sentence case", () => { | 142 | it("handles unknown messages with sentence case", () => { |
| 128 | expect(formatApiErrorMessage("custom error occurred", "en")).toBe("Custom error occurred"); | 143 | expect(formatApiErrorMessage("custom error occurred", "en")).toBe("Custom error occurred"); |
| 129 | expect(formatApiErrorMessage("custom error occurred", "tr")).toBe("İşlem tamamlanamadı: Custom error occurred"); | 144 | expect(formatApiErrorMessage("custom error occurred", "tr")).toBe("İşlem tamamlanamadı: Custom error occurred"); |
src/api/client/client.tsmodified+12 -0
| @@ -78,6 +78,18 @@ const API_ERROR_MESSAGES: Record<string, Record<Locale, string>> = { | |||
| 78 | en: "This note already has the maximum number of files.", | 78 | en: "This note already has the maximum number of files.", |
| 79 | tr: "Bu notta en fazla dosya sayısına ulaşılmış.", | 79 | tr: "Bu notta en fazla dosya sayısına ulaşılmış.", |
| 80 | }, | 80 | }, |
| 81 | + "this time overlaps a slot you have already published": { | ||
| 82 | + en: "This time overlaps a slot you already published.", | ||
| 83 | + tr: "Bu zaman aralığı, daha önce yayınladığın bir müsaitlikle çakışıyor.", | ||
| 84 | + }, | ||
| 85 | + "a repeated slot overlaps one you have already published": { | ||
| 86 | + en: "One of the repeated slots overlaps a slot you already published.", | ||
| 87 | + tr: "Tekrarlanan müsaitliklerden biri, daha önce yayınladığın bir müsaitlikle çakışıyor.", | ||
| 88 | + }, | ||
| 89 | + "the repeated slots overlap each other": { | ||
| 90 | + en: "The repeated slots overlap each other.", | ||
| 91 | + tr: "Tekrarlanan müsaitlikler birbiriyle çakışıyor.", | ||
| 92 | + }, | ||
| 81 | "course not found": { | 93 | "course not found": { |
| 82 | en: "Course not found.", | 94 | en: "Course not found.", |
| 83 | tr: "Ders bulunamadı.", | 95 | tr: "Ders bulunamadı.", |
src/lib/format.tsmodified+8 -0
| @@ -8,6 +8,14 @@ export function formatDateTime(ms: number | null | undefined, locale: Locale = " | |||
| 8 | }).format(new Date(ms)); | 8 | }).format(new Date(ms)); |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | +/** Date only, no time — for stacked date/time cells. */ | ||
| 12 | +export function formatDate(ms: number | null | undefined, locale: Locale = "en"): string { | ||
| 13 | + if (ms == null) return "—"; | ||
| 14 | + return new Intl.DateTimeFormat(locale === "tr" ? "tr-TR" : "en-US", { | ||
| 15 | + dateStyle: "medium", | ||
| 16 | + }).format(new Date(ms)); | ||
| 17 | +} | ||
| 18 | + | ||
| 11 | /** Convert datetime-local input value to unix ms, or null if empty. */ | 19 | /** Convert datetime-local input value to unix ms, or null if empty. */ |
| 12 | export function localInputToMs(value: string): number | null { | 20 | export function localInputToMs(value: string): number | null { |
| 13 | if (!value) return null; | 21 | if (!value) return null; |
src/pages/appointments-page.tsxmodified+27 -13
| @@ -35,7 +35,7 @@ import { appointmentStatusClass, appointmentStatusDotClass, appointmentStatusLab | |||
| 35 | import { cn } from "@/lib/cn"; | 35 | import { cn } from "@/lib/cn"; |
| 36 | import { createFlash } from "@/lib/flash"; | 36 | import { createFlash } from "@/lib/flash"; |
| 37 | import { createNow } from "@/lib/create-now"; | 37 | import { createNow } from "@/lib/create-now"; |
| 38 | -import { formatDateTime } from "@/lib/format"; | 38 | +import { formatDate, formatDateTime } from "@/lib/format"; |
| 39 | import { personLabel } from "@/lib/person"; | 39 | import { personLabel } from "@/lib/person"; |
| 40 | import { hasMinRole } from "@/lib/roles"; | 40 | import { hasMinRole } from "@/lib/roles"; |
| 41 | import { useAuth } from "@/stores/auth-context"; | 41 | import { useAuth } from "@/stores/auth-context"; |
| @@ -119,6 +119,19 @@ function AppointmentsContent() { | |||
| 119 | sameDay(starts, ends) | 119 | sameDay(starts, ends) |
| 120 | ? `${formatDateTime(starts, locale())} – ${timeOnly(ends)}` | 120 | ? `${formatDateTime(starts, locale())} – ${timeOnly(ends)}` |
| 121 | : `${formatDateTime(starts, locale())} — ${formatDateTime(ends, locale())}`; | 121 | : `${formatDateTime(starts, locale())} — ${formatDateTime(ends, locale())}`; |
| 122 | + // Stacked date/time cell: date on top, clock range below (tabular-nums so | ||
| 123 | + // digits line up across rows). Same-day windows show one date; cross-day | ||
| 124 | + // spells out the end date on the second line. | ||
| 125 | + const timeCell = (starts: number | null, ends: number | null) => ( | ||
| 126 | + <div class="mono flex flex-col text-xs leading-tight tabular-nums"> | ||
| 127 | + <span class="text-foreground">{formatDate(starts, locale())}</span> | ||
| 128 | + <span class="text-muted-foreground"> | ||
| 129 | + {sameDay(starts, ends) | ||
| 130 | + ? `${timeOnly(starts)} – ${timeOnly(ends)}` | ||
| 131 | + : `${timeOnly(starts)} → ${formatDate(ends, locale())} ${timeOnly(ends)}`} | ||
| 132 | + </span> | ||
| 133 | + </div> | ||
| 134 | + ); | ||
| 122 | const statusBadge = (status: AppointmentStatus) => ( | 135 | const statusBadge = (status: AppointmentStatus) => ( |
| 123 | <Badge variant="outline" class={cn("w-28 justify-center rounded-full", appointmentStatusClass(status))}> | 136 | <Badge variant="outline" class={cn("w-28 justify-center rounded-full", appointmentStatusClass(status))}> |
| 124 | <span class={cn("mr-1.5 h-1.5 w-1.5 rounded-full", appointmentStatusDotClass(status))} /> | 137 | <span class={cn("mr-1.5 h-1.5 w-1.5 rounded-full", appointmentStatusDotClass(status))} /> |
| @@ -151,8 +164,8 @@ function AppointmentsContent() { | |||
| 151 | { | 164 | { |
| 152 | id: "time", | 165 | id: "time", |
| 153 | header: t("appointments.time"), | 166 | header: t("appointments.time"), |
| 154 | - meta: { headerClass: "w-56", cellClass: "mono text-xs text-muted-foreground align-top whitespace-normal break-words pr-4" }, | 167 | + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, |
| 155 | - cell: (cell) => timeWindow(cell.row.original.starts_at, cell.row.original.ends_at), | 168 | + cell: (cell) => timeCell(cell.row.original.starts_at, cell.row.original.ends_at), |
| 156 | }, | 169 | }, |
| 157 | { | 170 | { |
| 158 | id: "note", | 171 | id: "note", |
| @@ -221,12 +234,12 @@ function AppointmentsContent() { | |||
| 221 | { | 234 | { |
| 222 | id: "time", | 235 | id: "time", |
| 223 | header: t("appointments.time"), | 236 | header: t("appointments.time"), |
| 224 | - meta: { headerClass: "w-56", cellClass: "mono text-xs text-muted-foreground align-top whitespace-normal break-words pr-4" }, | 237 | + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, |
| 225 | cell: (cell) => ( | 238 | cell: (cell) => ( |
| 226 | - <div> | 239 | + <div class="flex flex-col gap-0.5"> |
| 227 | - <div>{timeWindow(cell.row.original.starts_at, cell.row.original.ends_at)}</div> | 240 | + {timeCell(cell.row.original.starts_at, cell.row.original.ends_at)} |
| 228 | <Show when={hasProposal(cell.row.original) && cell.row.original.status === "pending"}> | 241 | <Show when={hasProposal(cell.row.original) && cell.row.original.status === "pending"}> |
| 229 | - <div class="text-info">{t("appointments.rescheduleProposed")}</div> | 242 | + <div class="text-info text-xs">{t("appointments.rescheduleProposed")}</div> |
| 230 | </Show> | 243 | </Show> |
| 231 | </div> | 244 | </div> |
| 232 | ), | 245 | ), |
| @@ -274,8 +287,8 @@ function AppointmentsContent() { | |||
| 274 | { | 287 | { |
| 275 | id: "time", | 288 | id: "time", |
| 276 | header: t("appointments.time"), | 289 | header: t("appointments.time"), |
| 277 | - meta: { headerClass: "w-56", cellClass: "mono text-xs text-muted-foreground align-top whitespace-normal break-words pr-4" }, | 290 | + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, |
| 278 | - cell: (cell) => timeWindow(cell.row.original.starts_at, cell.row.original.ends_at), | 291 | + cell: (cell) => timeCell(cell.row.original.starts_at, cell.row.original.ends_at), |
| 279 | }, | 292 | }, |
| 280 | { | 293 | { |
| 281 | id: "note", | 294 | id: "note", |
| @@ -307,12 +320,13 @@ function AppointmentsContent() { | |||
| 307 | { | 320 | { |
| 308 | id: "time", | 321 | id: "time", |
| 309 | header: t("appointments.time"), | 322 | header: t("appointments.time"), |
| 310 | - meta: { headerClass: "w-56", cellClass: "mono text-xs text-muted-foreground align-top whitespace-normal break-words pr-4" }, | 323 | + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, |
| 311 | cell: (cell) => ( | 324 | cell: (cell) => ( |
| 312 | - <div> | 325 | + <div class="flex flex-col gap-0.5"> |
| 313 | - <div>{timeWindow(cell.row.original.starts_at, cell.row.original.ends_at)}</div> | 326 | + {timeCell(cell.row.original.starts_at, cell.row.original.ends_at)} |
| 314 | <Show when={hasProposal(cell.row.original) && cell.row.original.status === "pending"}> | 327 | <Show when={hasProposal(cell.row.original) && cell.row.original.status === "pending"}> |
| 315 | - <div class="text-info">{t("appointments.proposedTime")}: {timeWindow(cell.row.original.proposed_starts_at, cell.row.original.proposed_ends_at)}</div> | 328 | + <div class="text-info text-xs">{t("appointments.proposedTime")}:</div> |
| 329 | + {timeCell(cell.row.original.proposed_starts_at, cell.row.original.proposed_ends_at)} | ||
| 316 | </Show> | 330 | </Show> |
| 317 | </div> | 331 | </div> |
| 318 | ), | 332 | ), |