🗓️ 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 | 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 | 142 | it("handles unknown messages with sentence case", () => { |
| 128 | 143 | expect(formatApiErrorMessage("custom error occurred", "en")).toBe("Custom error occurred"); |
| 129 | 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 | 78 | en: "This note already has the maximum number of files.", |
| 79 | 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 | 93 | "course not found": { |
| 82 | 94 | en: "Course not found.", |
| 83 | 95 | tr: "Ders bulunamadı.", |
src/lib/format.tsmodified+8 -0
| @@ -8,6 +8,14 @@ export function formatDateTime(ms: number | null | undefined, locale: Locale = " | ||
| 8 | 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 | 19 | /** Convert datetime-local input value to unix ms, or null if empty. */ |
| 12 | 20 | export function localInputToMs(value: string): number | null { |
| 13 | 21 | if (!value) return null; |
src/pages/appointments-page.tsxmodified+27 -13
| @@ -35,7 +35,7 @@ import { appointmentStatusClass, appointmentStatusDotClass, appointmentStatusLab | ||
| 35 | 35 | import { cn } from "@/lib/cn"; |
| 36 | 36 | import { createFlash } from "@/lib/flash"; |
| 37 | 37 | import { createNow } from "@/lib/create-now"; |
| 38 | -import { formatDateTime } from "@/lib/format"; | |
| 38 | +import { formatDate, formatDateTime } from "@/lib/format"; | |
| 39 | 39 | import { personLabel } from "@/lib/person"; |
| 40 | 40 | import { hasMinRole } from "@/lib/roles"; |
| 41 | 41 | import { useAuth } from "@/stores/auth-context"; |
| @@ -119,6 +119,19 @@ function AppointmentsContent() { | ||
| 119 | 119 | sameDay(starts, ends) |
| 120 | 120 | ? `${formatDateTime(starts, locale())} – ${timeOnly(ends)}` |
| 121 | 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 | 135 | const statusBadge = (status: AppointmentStatus) => ( |
| 123 | 136 | <Badge variant="outline" class={cn("w-28 justify-center rounded-full", appointmentStatusClass(status))}> |
| 124 | 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 | 165 | id: "time", |
| 153 | 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" }, | |
| 155 | - cell: (cell) => timeWindow(cell.row.original.starts_at, cell.row.original.ends_at), | |
| 167 | + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, | |
| 168 | + cell: (cell) => timeCell(cell.row.original.starts_at, cell.row.original.ends_at), | |
| 156 | 169 | }, |
| 157 | 170 | { |
| 158 | 171 | id: "note", |
| @@ -221,12 +234,12 @@ function AppointmentsContent() { | ||
| 221 | 234 | { |
| 222 | 235 | id: "time", |
| 223 | 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 | 238 | cell: (cell) => ( |
| 226 | - <div> | |
| 227 | - <div>{timeWindow(cell.row.original.starts_at, cell.row.original.ends_at)}</div> | |
| 239 | + <div class="flex flex-col gap-0.5"> | |
| 240 | + {timeCell(cell.row.original.starts_at, cell.row.original.ends_at)} | |
| 228 | 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 | 243 | </Show> |
| 231 | 244 | </div> |
| 232 | 245 | ), |
| @@ -274,8 +287,8 @@ function AppointmentsContent() { | ||
| 274 | 287 | { |
| 275 | 288 | id: "time", |
| 276 | 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" }, | |
| 278 | - cell: (cell) => timeWindow(cell.row.original.starts_at, cell.row.original.ends_at), | |
| 290 | + meta: { headerClass: "w-44", cellClass: "align-top pr-4" }, | |
| 291 | + cell: (cell) => timeCell(cell.row.original.starts_at, cell.row.original.ends_at), | |
| 279 | 292 | }, |
| 280 | 293 | { |
| 281 | 294 | id: "note", |
| @@ -307,12 +320,13 @@ function AppointmentsContent() { | ||
| 307 | 320 | { |
| 308 | 321 | id: "time", |
| 309 | 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 | 324 | cell: (cell) => ( |
| 312 | - <div> | |
| 313 | - <div>{timeWindow(cell.row.original.starts_at, cell.row.original.ends_at)}</div> | |
| 325 | + <div class="flex flex-col gap-0.5"> | |
| 326 | + {timeCell(cell.row.original.starts_at, cell.row.original.ends_at)} | |
| 314 | 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 | 330 | </Show> |
| 317 | 331 | </div> |
| 318 | 332 | ), |