🧭 centered, illustrated load-error, not-found and 404 states
Browse files at this commit233723f818be8d05de4950b0a4e942cd2189b0aaParent: c0aa428- feat
- 🧭 centered, illustrated load-error, not-found and 404 states
12 changed files +323 -66
- src/assets/illustrations/README.md +1 -0
- src/assets/illustrations/server-down.svg +1 -0
- src/components/layout/page-center.tsx +33 -0
- src/components/layout/record-not-found.tsx +17 -19
- src/components/layout/route-error.test.tsx +37 -0
- src/components/layout/route-error.tsx +106 -19
- src/components/system/not-found-page.tsx +29 -26
- src/components/ui/empty-state.tsx +17 -2
- src/i18n/locales/en.ts +27 -0
- src/i18n/locales/tr.ts +27 -0
- src/i18n/messages.ts +27 -0
- src/lib/illustrations.ts +1 -0
src/assets/illustrations/README.mdmodified+1 -0
| @@ -26,5 +26,6 @@ Files are kept exactly as downloaded (`https://cdn.undraw.co/illustrations/<slug | |||
| 26 | | payments.svg | payments_nbqu | | 26 | | payments.svg | payments_nbqu | |
| 27 | | people.svg | group-project_kow1 | | 27 | | people.svg | group-project_kow1 | |
| 28 | | schedule.svg | schedule_ry1w | | 28 | | schedule.svg | schedule_ry1w | |
| 29 | +| server-down.svg | server-down_lxs9 | | ||
| 29 | | whiteboard.svg | blank-canvas_a6x5 | | 30 | | whiteboard.svg | blank-canvas_a6x5 | |
| 30 | | work.svg | time-management_4ss6 | | 31 | | work.svg | time-management_4ss6 | |
src/assets/illustrations/server-down.svgadded+1 -0
| @@ -0,0 +1 @@ | |||
| 1 | +<svg id="aa03ddf9-f8f2-4819-a4ce-be9b0a220741" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" width="1119.60911" height="699" viewBox="0 0 1119.60911 699"><title>server down</title><circle cx="292.60911" cy="213" r="213" fill="#f2f2f2"/><path d="M31.39089,151.64237c0,77.49789,48.6181,140.20819,108.70073,140.20819" transform="translate(-31.39089 -100.5)" fill="#2f2e41"/><path d="M140.09162,291.85056c0-78.36865,54.255-141.78356,121.30372-141.78356" transform="translate(-31.39089 -100.5)" fill="#6c63ff"/><path d="M70.77521,158.66768c0,73.61476,31.00285,133.18288,69.31641,133.18288" transform="translate(-31.39089 -100.5)" fill="#6c63ff"/><path d="M140.09162,291.85056c0-100.13772,62.7103-181.16788,140.20819-181.16788" transform="translate(-31.39089 -100.5)" fill="#2f2e41"/><path d="M117.22379,292.83905s15.41555-.47479,20.06141-3.783,23.713-7.2585,24.86553-1.95278,23.16671,26.38821,5.76263,26.5286-40.43935-2.711-45.07627-5.53549S117.22379,292.83905,117.22379,292.83905Z" transform="translate(-31.39089 -100.5)" fill="#a8a8a8"/><path d="M168.224,311.78489c-17.40408.14042-40.43933-2.71094-45.07626-5.53548-3.53126-2.151-4.93843-9.86945-5.40926-13.43043-.32607.014-.51463.02-.51463.02s.97638,12.43276,5.61331,15.2573,27.67217,5.67589,45.07626,5.53547c5.02386-.04052,6.7592-1.82793,6.66391-4.47526C173.87935,310.756,171.96329,311.75474,168.224,311.78489Z" transform="translate(-31.39089 -100.5)" opacity="0.2"/><ellipse cx="198.60911" cy="424.5" rx="187" ry="25.43993" fill="#3f3d56"/><ellipse cx="198.60911" cy="424.5" rx="157" ry="21.35866" opacity="0.1"/><ellipse cx="836.60911" cy="660.5" rx="283" ry="38.5" fill="#3f3d56"/><ellipse cx="310.60911" cy="645.5" rx="170" ry="23.12721" fill="#3f3d56"/><path d="M494,726.5c90,23,263-30,282-90" transform="translate(-31.39089 -100.5)" fill="none" stroke="#2f2e41" stroke-miterlimit="10" stroke-width="2"/><path d="M341,359.5s130-36,138,80-107,149-17,172" transform="translate(-31.39089 -100.5)" fill="none" stroke="#2f2e41" stroke-miterlimit="10" stroke-width="2"/><path d="M215.40233,637.78332s39.0723-10.82,41.47675,24.04449-32.15951,44.78287-5.10946,51.69566" transform="translate(-31.39089 -100.5)" fill="none" stroke="#2f2e41" stroke-miterlimit="10" stroke-width="2"/><path d="M810.09554,663.73988,802.218,714.03505s-38.78182,20.60284-11.51335,21.20881,155.73324,0,155.73324,0,24.84461,0-14.54318-21.81478l-7.87756-52.719Z" transform="translate(-31.39089 -100.5)" fill="#2f2e41"/><path d="M785.21906,734.69812c6.193-5.51039,16.9989-11.252,16.9989-11.252l7.87756-50.2952,113.9216.10717,7.87756,49.582c9.185,5.08711,14.8749,8.987,18.20362,11.97818,5.05882-1.15422,10.58716-5.44353-18.20362-21.38921l-7.87756-52.719-113.9216,3.02983L802.218,714.03506S769.62985,731.34968,785.21906,734.69812Z" transform="translate(-31.39089 -100.5)" opacity="0.1"/><rect x="578.43291" y="212.68859" width="513.25314" height="357.51989" rx="18.04568" fill="#2f2e41"/><rect x="595.70294" y="231.77652" width="478.71308" height="267.83694" fill="#3f3d56"/><circle cx="835.05948" cy="223.29299" r="3.02983" fill="#f2f2f2"/><path d="M1123.07694,621.32226V652.6628a18.04341,18.04341,0,0,1-18.04568,18.04568H627.86949A18.04341,18.04341,0,0,1,609.8238,652.6628V621.32226Z" transform="translate(-31.39089 -100.5)" fill="#2f2e41"/><polygon points="968.978 667.466 968.978 673.526 642.968 673.526 642.968 668.678 643.417 667.466 651.452 645.651 962.312 645.651 968.978 667.466" fill="#2f2e41"/><path d="M1125.828,762.03359c-.59383,2.539-2.83591,5.21743-7.90178,7.75032-18.179,9.08949-55.1429-2.42386-55.1429-2.42386s-28.4804-4.84773-28.4804-17.573a22.72457,22.72457,0,0,1,2.49658-1.48459c7.64294-4.04351,32.98449-14.02122,77.9177.42248a18.73921,18.73921,0,0,1,8.54106,5.59715C1125.07908,756.45353,1126.50669,759.15715,1125.828,762.03359Z" transform="translate(-31.39089 -100.5)" fill="#2f2e41"/><path d="M1125.828,762.03359c-22.251,8.526-42.0843,9.1622-62.43871-4.975-10.26507-7.12617-19.59089-8.88955-26.58979-8.75618,7.64294-4.04351,32.98449-14.02122,77.9177.42248a18.73921,18.73921,0,0,1,8.54106,5.59715C1125.07908,756.45353,1126.50669,759.15715,1125.828,762.03359Z" transform="translate(-31.39089 -100.5)" opacity="0.1"/><ellipse cx="1066.53846" cy="654.13477" rx="7.87756" ry="2.42386" fill="#f2f2f2"/><circle cx="835.05948" cy="545.66686" r="11.51335" fill="#f2f2f2"/><polygon points="968.978 667.466 968.978 673.526 642.968 673.526 642.968 668.678 643.417 667.466 968.978 667.466" opacity="0.1"/><rect x="108.60911" y="159" width="208" height="242" fill="#2f2e41"/><rect x="87.60911" y="135" width="250" height="86" fill="#3f3d56"/><rect x="87.60911" y="237" width="250" height="86" fill="#3f3d56"/><rect x="87.60911" y="339" width="250" height="86" fill="#3f3d56"/><rect x="271.60911" y="150" width="16" height="16" fill="#6c63ff" opacity="0.4"/><rect x="294.60911" y="150" width="16" height="16" fill="#6c63ff" opacity="0.8"/><rect x="317.60911" y="150" width="16" height="16" fill="#6c63ff"/><rect x="271.60911" y="251" width="16" height="16" fill="#6c63ff" opacity="0.4"/><rect x="294.60911" y="251" width="16" height="16" fill="#6c63ff" opacity="0.8"/><rect x="317.60911" y="251" width="16" height="16" fill="#6c63ff"/><rect x="271.60911" y="352" width="16" height="16" fill="#6c63ff" opacity="0.4"/><rect x="294.60911" y="352" width="16" height="16" fill="#6c63ff" opacity="0.8"/><rect x="317.60911" y="352" width="16" height="16" fill="#6c63ff"/><circle cx="316.60911" cy="538" r="79" fill="#2f2e41"/><rect x="280.60911" y="600" width="24" height="43" fill="#2f2e41"/><rect x="328.60911" y="600" width="24" height="43" fill="#2f2e41"/><ellipse cx="300.60911" cy="643.5" rx="20" ry="7.5" fill="#2f2e41"/><ellipse cx="348.60911" cy="642.5" rx="20" ry="7.5" fill="#2f2e41"/><circle cx="318.60911" cy="518" r="27" fill="#fff"/><circle cx="318.60911" cy="518" r="9" fill="#3f3d56"/><path d="M271.36733,565.03228c-6.37889-28.56758,14.01185-57.43392,45.544-64.47477s62.2651,10.41,68.644,38.9776-14.51861,39.10379-46.05075,46.14464S277.74622,593.59986,271.36733,565.03228Z" transform="translate(-31.39089 -100.5)" fill="#6c63ff"/><ellipse cx="417.21511" cy="611.34365" rx="39.5" ry="12.40027" transform="translate(-238.28665 112.98044) rotate(-23.17116)" fill="#2f2e41"/><ellipse cx="269.21511" cy="664.34365" rx="39.5" ry="12.40027" transform="translate(-271.07969 59.02084) rotate(-23.17116)" fill="#2f2e41"/><path d="M394,661.5c0,7.732-19.90861,23-42,23s-43-14.268-43-22,20.90861-6,43-6S394,653.768,394,661.5Z" transform="translate(-31.39089 -100.5)" fill="#fff"/></svg> | ||
| \ No newline at end of file | \ No newline at end of file | ||
src/components/layout/page-center.tsxadded+33 -0
| @@ -0,0 +1,33 @@ | |||
| 1 | +import type { JSX } from "solid-js"; | ||
| 2 | +import { currentLocale } from "@/api/client"; | ||
| 3 | +import { formatMessage, messageFor, type MessageKey } from "@/i18n/messages"; | ||
| 4 | +import { cn } from "@/lib/cn"; | ||
| 5 | + | ||
| 6 | +/** Card sizing shared by the full-page states (load failure, record not found). */ | ||
| 7 | +export const PAGE_STATE_CARD = "min-h-[420px] gap-6 px-6 py-10 sm:px-10 sm:py-12"; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Text for the full-page states. They can render from the router's error | ||
| 11 | + * component, above the i18n provider, so they read the loaded dictionary | ||
| 12 | + * directly instead of `useT()` (the boot awaits the stored locale first). | ||
| 13 | + */ | ||
| 14 | +export function pageStateText(key: MessageKey, vars?: Record<string, string | number>): string { | ||
| 15 | + return formatMessage(messageFor(currentLocale(), key) ?? key, vars); | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Fills the content column under the shell header and centers a full-page | ||
| 20 | + * state on both axes, capped at a comfortable reading width. | ||
| 21 | + */ | ||
| 22 | +export function PageCenter(props: { children: JSX.Element; alert?: boolean; class?: string }) { | ||
| 23 | + return ( | ||
| 24 | + // Below lg: no header, but the shell's page title, 1.5rem top padding and | ||
| 25 | + // the tab bar + quick-action clearance (up to 9rem) at the bottom. | ||
| 26 | + // lg+: the 49px header plus the column's py-6. | ||
| 27 | + <div class="flex min-h-[calc(100dvh-13rem)] w-full items-center justify-center lg:min-h-[calc(100dvh-49px-3rem)]"> | ||
| 28 | + <div role={props.alert ? "alert" : undefined} class={cn("w-full max-w-[600px]", props.class)}> | ||
| 29 | + {props.children} | ||
| 30 | + </div> | ||
| 31 | + </div> | ||
| 32 | + ); | ||
| 33 | +} | ||
src/components/layout/record-not-found.tsxmodified+17 -19
| @@ -1,37 +1,35 @@ | |||
| 1 | import { Link, useLocation, useRouter } from "@tanstack/solid-router"; | 1 | import { Link, useLocation, useRouter } from "@tanstack/solid-router"; |
| 2 | -import { currentLocale } from "@/api/client"; | ||
| 3 | import { buttonVariants } from "@/components/ui/button"; | 2 | import { buttonVariants } from "@/components/ui/button"; |
| 4 | import { EmptyState } from "@/components/ui/empty-state"; | 3 | import { EmptyState } from "@/components/ui/empty-state"; |
| 4 | +import { PAGE_STATE_CARD, PageCenter, pageStateText as tt } from "@/components/layout/page-center"; | ||
| 5 | import { cn } from "@/lib/cn"; | 5 | import { cn } from "@/lib/cn"; |
| 6 | import { listPathFor } from "@/lib/record-list-path"; | 6 | import { listPathFor } from "@/lib/record-list-path"; |
| 7 | 7 | ||
| 8 | /** | 8 | /** |
| 9 | * What a detail page shows when its record does not exist (a 404 — deleted, | 9 | * What a detail page shows when its record does not exist (a 404 — deleted, |
| 10 | * or a bad link): there is nothing to retry, so it offers the way back to the | 10 | * or a bad link): there is nothing to retry, so it offers the way back to the |
| 11 | - * list instead. Also rendered by the router's error fallback, which can sit | 11 | + * list instead. Centered in the content column like the route error view. |
| 12 | - * above the i18n provider, hence the client's bilingual-fallback idiom. | 12 | + * Also rendered by the router's error fallback, which can sit above the i18n |
| 13 | + * provider, hence `pageStateText` instead of `useT()`. | ||
| 13 | */ | 14 | */ |
| 14 | export function RecordNotFound(props: { backTo?: string }) { | 15 | export function RecordNotFound(props: { backTo?: string }) { |
| 15 | const router = useRouter(); | 16 | const router = useRouter(); |
| 16 | const location = useLocation(); | 17 | const location = useLocation(); |
| 17 | - const tr = () => currentLocale() === "tr"; | ||
| 18 | const backTo = () => | 18 | const backTo = () => |
| 19 | props.backTo ?? listPathFor(location().pathname, (path) => path in router.routesByPath); | 19 | props.backTo ?? listPathFor(location().pathname, (path) => path in router.routesByPath); |
| 20 | return ( | 20 | return ( |
| 21 | - <EmptyState | 21 | + <PageCenter> |
| 22 | - kind="search" | 22 | + <EmptyState |
| 23 | - class="mx-auto w-full max-w-[640px]" | 23 | + kind="search" |
| 24 | - title={tr() ? "Kayıt bulunamadı" : "Record not found"} | 24 | + class={PAGE_STATE_CARD} |
| 25 | - description={ | 25 | + title={tt("errors.recordNotFound.title")} |
| 26 | - tr() | 26 | + description={tt("errors.recordNotFound.description")} |
| 27 | - ? "Bu kayıt silinmiş ya da bağlantı hatalı olabilir." | 27 | + action={ |
| 28 | - : "This record may have been deleted, or the link is wrong." | 28 | + <Link to={backTo()} class={cn(buttonVariants({ variant: "outline", size: "sm" }), "h-9 rounded-lg px-4")}> |
| 29 | - } | 29 | + {backTo() === "/" ? tt("errors.recordNotFound.backHome") : tt("errors.recordNotFound.backToList")} |
| 30 | - action={ | 30 | + </Link> |
| 31 | - <Link to={backTo()} class={cn(buttonVariants({ variant: "outline", size: "sm" }), "h-9 rounded-lg px-4")}> | 31 | + } |
| 32 | - {backTo() === "/" ? (tr() ? "Ana sayfaya dön" : "Back to home") : tr() ? "Listeye dön" : "Back to the list"} | 32 | + /> |
| 33 | - </Link> | 33 | + </PageCenter> |
| 34 | - } | ||
| 35 | - /> | ||
| 36 | ); | 34 | ); |
| 37 | } | 35 | } |
src/components/layout/route-error.test.tsxmodified+37 -0
| @@ -73,3 +73,40 @@ test("a 404 shows not-found with a way back to the list, not a retry", async () | |||
| 73 | expect(back.getAttribute("href")).toBe("/courses"); | 73 | expect(back.getAttribute("href")).toBe("/courses"); |
| 74 | expect(screen.queryByRole("button")).toBeNull(); | 74 | expect(screen.queryByRole("button")).toBeNull(); |
| 75 | }); | 75 | }); |
| 76 | + | ||
| 77 | +test("a rate-limited page is centered with an illustration, waits out retry-after and names the cause", async () => { | ||
| 78 | + const { ApiError } = await import("@/api/client"); | ||
| 79 | + const root = createRootRoute({ component: () => <Outlet /> }); | ||
| 80 | + const page = createRoute({ | ||
| 81 | + getParentRoute: () => root, | ||
| 82 | + path: "/exams", | ||
| 83 | + component: () => { | ||
| 84 | + throw new ApiError(429, "too many requests", 15, null, "rate_limited"); | ||
| 85 | + }, | ||
| 86 | + }); | ||
| 87 | + const router = createRouter({ | ||
| 88 | + routeTree: root.addChildren([page]), | ||
| 89 | + history: createMemoryHistory({ initialEntries: ["/exams"] }), | ||
| 90 | + defaultErrorComponent: RouteErrorFallback, | ||
| 91 | + }); | ||
| 92 | + | ||
| 93 | + render(() => <RouterProvider router={router} />); | ||
| 94 | + | ||
| 95 | + const alert = await screen.findByRole("alert"); | ||
| 96 | + expect(alert.querySelector(".illustration")).toBeTruthy(); | ||
| 97 | + expect(screen.getByText(/^(This page could not load|Bu sayfa yüklenemedi)$/)).toBeTruthy(); | ||
| 98 | + expect(screen.getByText(/^(Try again in 15s\.|15 sn sonra tekrar dene\.)$/)).toBeTruthy(); | ||
| 99 | + | ||
| 100 | + // Retrying before retry-after only earns another 429. | ||
| 101 | + const retry = screen.getByRole("button") as HTMLButtonElement; | ||
| 102 | + expect(retry.disabled).toBe(true); | ||
| 103 | + expect(retry.textContent).toMatch(/15/); | ||
| 104 | + | ||
| 105 | + // The technical details carry the real fields of the error. | ||
| 106 | + const details = alert.querySelector("dl")!; | ||
| 107 | + expect(details.textContent).toContain("429"); | ||
| 108 | + expect(details.textContent).toContain("rate_limited"); | ||
| 109 | + expect(details.textContent).toContain("/exams"); | ||
| 110 | + expect(details.textContent).toContain("too many requests"); | ||
| 111 | + expect(details.textContent).toMatch(/rate limited|hız sınırı/); | ||
| 112 | +}); | ||
src/components/layout/route-error.tsxmodified+106 -19
| @@ -1,8 +1,12 @@ | |||
| 1 | -import type { ErrorComponentProps } from "@tanstack/solid-router"; | 1 | +import { useLocation, type ErrorComponentProps } from "@tanstack/solid-router"; |
| 2 | -import { currentLocale, formatApiError } from "@/api/client"; | 2 | +import { createSignal, For, onCleanup } from "solid-js"; |
| 3 | +import { ApiError, formatApiError } from "@/api/client"; | ||
| 3 | import { Button } from "@/components/ui/button"; | 4 | import { Button } from "@/components/ui/button"; |
| 4 | -import { IconAlert } from "@/components/ui/icons"; | 5 | +import { EmptyState } from "@/components/ui/empty-state"; |
| 6 | +import { IconChevronDown } from "@/components/ui/icons"; | ||
| 7 | +import { PAGE_STATE_CARD, PageCenter, pageStateText as tt } from "@/components/layout/page-center"; | ||
| 5 | import { RecordNotFound } from "@/components/layout/record-not-found"; | 8 | import { RecordNotFound } from "@/components/layout/record-not-found"; |
| 9 | +import type { MessageKey } from "@/i18n/messages"; | ||
| 6 | import { isNotFoundError } from "@/lib/record-list-path"; | 10 | import { isNotFoundError } from "@/lib/record-list-path"; |
| 7 | 11 | ||
| 8 | /** | 12 | /** |
| @@ -12,26 +16,109 @@ import { isNotFoundError } from "@/lib/record-list-path"; | |||
| 12 | * Without it the throw reached the app-wide boundary and replaced everything | 16 | * Without it the throw reached the app-wide boundary and replaced everything |
| 13 | * with a full-screen 500. | 17 | * with a full-screen 500. |
| 14 | * | 18 | * |
| 15 | - * It can also render for the root route, above the i18n provider, so it uses | 19 | + * It can also render for the root route, above the i18n provider, so its |
| 16 | - * the client's bilingual-fallback idiom instead of `t(...)`. | 20 | + * text comes from `pageStateText` instead of `useT()`. |
| 17 | */ | 21 | */ |
| 18 | export function RouteErrorFallback(props: ErrorComponentProps) { | 22 | export function RouteErrorFallback(props: ErrorComponentProps) { |
| 19 | - const tr = () => currentLocale() === "tr"; | ||
| 20 | // A missing record is an answer, not a failure: retrying a 404 changes nothing. | 23 | // A missing record is an answer, not a failure: retrying a 404 changes nothing. |
| 21 | - if (isNotFoundError(props.error)) return <RecordNotFound />; | 24 | + if (isNotFoundError(props.error)) { |
| 25 | + return <RecordNotFound />; | ||
| 26 | + } | ||
| 22 | console.error("Route render error:", props.error); | 27 | console.error("Route render error:", props.error); |
| 28 | + return <PageLoadError error={props.error} reset={props.reset} />; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +function errorKind(err: unknown): MessageKey { | ||
| 32 | + if (err instanceof ApiError) { | ||
| 33 | + if (err.status === 429) return "errors.pageLoad.kind.rateLimited"; | ||
| 34 | + if (err.status === 403 && err.module != null) return "errors.pageLoad.kind.moduleOff"; | ||
| 35 | + if (err.status === 401) return "errors.pageLoad.kind.unauthorized"; | ||
| 36 | + if (err.status === 403) return "errors.pageLoad.kind.forbidden"; | ||
| 37 | + if (err.status === 408) return "errors.pageLoad.kind.timeout"; | ||
| 38 | + if (err.status === 503) return "errors.pageLoad.kind.unavailable"; | ||
| 39 | + if (err.status >= 500) return "errors.pageLoad.kind.server"; | ||
| 40 | + return "errors.pageLoad.kind.request"; | ||
| 41 | + } | ||
| 42 | + // fetch() rejects with a TypeError when the request never got an answer. | ||
| 43 | + if (err instanceof TypeError && /fetch|network|load failed/i.test(err.message)) { | ||
| 44 | + return typeof navigator !== "undefined" && navigator.onLine === false | ||
| 45 | + ? "errors.pageLoad.kind.offline" | ||
| 46 | + : "errors.pageLoad.kind.network"; | ||
| 47 | + } | ||
| 48 | + return "errors.pageLoad.kind.render"; | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +function rawMessage(err: unknown): string { | ||
| 52 | + if (err instanceof ApiError) return err.message; | ||
| 53 | + if (err instanceof Error) return err.message ? `${err.name}: ${err.message}` : err.name; | ||
| 54 | + return String(err); | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +function PageLoadError(props: { error: unknown; reset: () => void }) { | ||
| 58 | + const location = useLocation(); | ||
| 59 | + const api = props.error instanceof ApiError ? props.error : null; | ||
| 60 | + | ||
| 61 | + // A rate-limited or unavailable answer says when a retry can work; retrying | ||
| 62 | + // sooner only earns another refusal, so the button waits it out. | ||
| 63 | + const [wait, setWait] = createSignal( | ||
| 64 | + api && (api.status === 429 || api.status === 503) && api.retryAfter != null ? Math.max(0, Math.ceil(api.retryAfter)) : 0, | ||
| 65 | + ); | ||
| 66 | + if (wait() > 0) { | ||
| 67 | + const timer = setInterval(() => { | ||
| 68 | + setWait((s) => { | ||
| 69 | + const next = Math.max(0, s - 1); | ||
| 70 | + if (next === 0) clearInterval(timer); | ||
| 71 | + return next; | ||
| 72 | + }); | ||
| 73 | + }, 1000); | ||
| 74 | + onCleanup(() => clearInterval(timer)); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + const rows = (): { label: string; value: string; mono?: boolean }[] => { | ||
| 78 | + const list: { label: string; value: string; mono?: boolean }[] = []; | ||
| 79 | + list.push({ label: tt("errors.pageLoad.kind"), value: tt(errorKind(props.error)) }); | ||
| 80 | + if (api) list.push({ label: tt("errors.pageLoad.status"), value: String(api.status), mono: true }); | ||
| 81 | + if (api?.code) list.push({ label: tt("errors.pageLoad.code"), value: api.code, mono: true }); | ||
| 82 | + if (api?.module) list.push({ label: tt("errors.pageLoad.module"), value: api.module, mono: true }); | ||
| 83 | + if (api?.retryAfter != null) | ||
| 84 | + list.push({ label: tt("errors.pageLoad.retryAfter"), value: tt("errors.pageLoad.seconds", { seconds: api.retryAfter }) }); | ||
| 85 | + list.push({ label: tt("errors.pageLoad.page"), value: location().href, mono: true }); | ||
| 86 | + const raw = rawMessage(props.error).trim(); | ||
| 87 | + if (raw) list.push({ label: tt("errors.pageLoad.message"), value: raw, mono: true }); | ||
| 88 | + return list; | ||
| 89 | + }; | ||
| 90 | + | ||
| 23 | return ( | 91 | return ( |
| 24 | - <div role="alert" class="mx-auto flex w-full max-w-[520px] flex-col items-center gap-4 rounded-xl border border-border-line bg-surface-base px-6 py-10 text-center"> | 92 | + <PageCenter alert> |
| 25 | - <span class="flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10 text-destructive-text"> | 93 | + <EmptyState |
| 26 | - <IconAlert class="h-5 w-5" /> | 94 | + kind="error" |
| 27 | - </span> | 95 | + class={PAGE_STATE_CARD} |
| 28 | - <div class="space-y-1.5"> | 96 | + title={tt("errors.pageLoad.title")} |
| 29 | - <p class="text-base font-semibold text-text-strong">{tr() ? "Bu sayfa yüklenemedi" : "This page could not load"}</p> | 97 | + description={formatApiError(props.error)} |
| 30 | - <p class="text-sm text-text-subtle">{formatApiError(props.error)}</p> | 98 | + action={ |
| 31 | - </div> | 99 | + <div class="flex w-full flex-col items-center gap-5"> |
| 32 | - <Button type="button" size="sm" class="h-9 px-4" onClick={() => props.reset()}> | 100 | + <Button type="button" size="sm" class="h-9 rounded-lg px-4" disabled={wait() > 0} onClick={() => props.reset()}> |
| 33 | - {tr() ? "Tekrar dene" : "Try again"} | 101 | + {wait() > 0 ? tt("errors.pageLoad.retryIn", { seconds: wait() }) : tt("errors.pageLoad.retry")} |
| 34 | - </Button> | 102 | + </Button> |
| 35 | - </div> | 103 | + <details class="group w-full rounded-lg border border-border-hairline bg-surface-tint/60 text-left"> |
| 104 | + <summary class="flex cursor-pointer list-none items-center justify-between gap-3 rounded-lg px-4 py-2.5 text-sm font-medium text-text-strong outline-hidden focus-visible:ring-2 focus-visible:ring-ring [&::-webkit-details-marker]:hidden"> | ||
| 105 | + <span>{tt("errors.pageLoad.details")}</span> | ||
| 106 | + <IconChevronDown class="h-4 w-4 shrink-0 text-text-subtle transition-transform group-open:rotate-180" /> | ||
| 107 | + </summary> | ||
| 108 | + <dl class="grid grid-cols-1 gap-x-4 gap-y-1 border-t border-border-hairline px-4 py-3 text-xs sm:grid-cols-[max-content_1fr] sm:gap-y-2"> | ||
| 109 | + <For each={rows()}> | ||
| 110 | + {(row) => ( | ||
| 111 | + <> | ||
| 112 | + <dt class="pt-1 font-medium text-text-subtle sm:pt-0">{row.label}</dt> | ||
| 113 | + <dd class={row.mono ? "break-all font-mono text-text-strong" : "text-text-strong"}>{row.value}</dd> | ||
| 114 | + </> | ||
| 115 | + )} | ||
| 116 | + </For> | ||
| 117 | + </dl> | ||
| 118 | + </details> | ||
| 119 | + </div> | ||
| 120 | + } | ||
| 121 | + /> | ||
| 122 | + </PageCenter> | ||
| 36 | ); | 123 | ); |
| 37 | } | 124 | } |
src/components/system/not-found-page.tsxmodified+29 -26
| @@ -1,37 +1,40 @@ | |||
| 1 | import { Link } from "@tanstack/solid-router"; | 1 | import { Link } from "@tanstack/solid-router"; |
| 2 | import { Button } from "@/components/ui/button"; | 2 | import { Button } from "@/components/ui/button"; |
| 3 | -import { IconChevronLeft, IconHome, IconSearch } from "@/components/ui/icons"; | 3 | +import { EmptyState } from "@/components/ui/empty-state"; |
| 4 | +import { IconChevronLeft, IconHome } from "@/components/ui/icons"; | ||
| 5 | +import { PAGE_STATE_CARD, PageCenter } from "@/components/layout/page-center"; | ||
| 4 | import { useGoBack } from "@/lib/use-go-back"; | 6 | import { useGoBack } from "@/lib/use-go-back"; |
| 5 | import { useT } from "@/stores/preferences-context"; | 7 | import { useT } from "@/stores/preferences-context"; |
| 6 | 8 | ||
| 9 | +/** The router's 404: same centered, illustrated card as a missing record. */ | ||
| 7 | export function NotFoundPage() { | 10 | export function NotFoundPage() { |
| 8 | const t = useT(); | 11 | const t = useT(); |
| 9 | const goBack = useGoBack(); | 12 | const goBack = useGoBack(); |
| 10 | return ( | 13 | return ( |
| 11 | - <div class="flex min-h-[60vh] items-center justify-center px-4 py-16"> | 14 | + <PageCenter> |
| 12 | - <div class="w-full max-w-[420px] space-y-5 rounded-xl border border-border-line bg-surface-base p-8 text-center shadow-[0_10px_24px_-4px_rgba(0,0,0,0.10)]"> | 15 | + <EmptyState |
| 13 | - <div class="mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-surface-tint text-text-subtle"> | 16 | + kind="search" |
| 14 | - <IconSearch class="h-6 w-6" /> | 17 | + class={PAGE_STATE_CARD} |
| 15 | - </div> | 18 | + eyebrow="404" |
| 16 | - <div class="space-y-2"> | 19 | + pageHeading |
| 17 | - <p class="text-4xl font-semibold tracking-tight text-text-strong">404</p> | 20 | + title={t("common.notFound")} |
| 18 | - <h1 class="text-base font-semibold text-text-strong">{t("common.notFound")}</h1> | 21 | + description={t("errors.notFoundDescription")} |
| 19 | - <p class="text-sm leading-[21px] text-text-subtle">{t("errors.notFoundDescription")}</p> | 22 | + action={ |
| 20 | - </div> | 23 | + <div class="flex flex-wrap items-center justify-center gap-2"> |
| 21 | - <div class="flex items-center justify-center gap-2 pt-1"> | 24 | + <Button type="button" variant="outline" size="sm" class="h-9 rounded-lg px-4" onClick={goBack}> |
| 22 | - <Button type="button" variant="outline" onClick={goBack}> | 25 | + <IconChevronLeft class="mr-1 h-4 w-4" /> |
| 23 | - <IconChevronLeft class="mr-1 h-4 w-4" /> | 26 | + {t("common.back")} |
| 24 | - {t("common.back")} | 27 | + </Button> |
| 25 | - </Button> | 28 | + <Link |
| 26 | - <Link | 29 | + to="/" |
| 27 | - to="/" | 30 | + class="inline-flex h-9 items-center justify-center gap-1.5 whitespace-nowrap rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90" |
| 28 | - class="inline-flex h-9 items-center justify-center gap-1.5 whitespace-nowrap rounded-lg bg-primary px-3 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90" | 31 | + > |
| 29 | - > | 32 | + <IconHome class="mr-1 h-4 w-4" /> |
| 30 | - <IconHome class="mr-1 h-4 w-4" /> | 33 | + {t("common.goHome")} |
| 31 | - {t("common.goHome")} | 34 | + </Link> |
| 32 | - </Link> | 35 | + </div> |
| 33 | - </div> | 36 | + } |
| 34 | - </div> | 37 | + /> |
| 35 | - </div> | 38 | + </PageCenter> |
| 36 | ); | 39 | ); |
| 37 | } | 40 | } |
src/components/ui/empty-state.tsxmodified+17 -2
| @@ -1,4 +1,5 @@ | |||
| 1 | import { Show } from "solid-js"; | 1 | import { Show } from "solid-js"; |
| 2 | +import { Dynamic } from "solid-js/web"; | ||
| 2 | import type { JSX } from "solid-js"; | 3 | import type { JSX } from "solid-js"; |
| 3 | import { Illustration } from "@/components/ui/illustration"; | 4 | import { Illustration } from "@/components/ui/illustration"; |
| 4 | import { cn } from "@/lib/cn"; | 5 | import { cn } from "@/lib/cn"; |
| @@ -19,7 +20,8 @@ export type EmptyStateKind = | |||
| 19 | | "schedule" | 20 | | "schedule" |
| 20 | | "whiteboard" | 21 | | "whiteboard" |
| 21 | | "work" | 22 | | "work" |
| 22 | - | "coming-soon"; | 23 | + | "coming-soon" |
| 24 | + | "error"; | ||
| 23 | 25 | ||
| 24 | const KIND_ILLUSTRATION: Record<EmptyStateKind, IllustrationName> = { | 26 | const KIND_ILLUSTRATION: Record<EmptyStateKind, IllustrationName> = { |
| 25 | default: "empty", | 27 | default: "empty", |
| @@ -37,11 +39,16 @@ const KIND_ILLUSTRATION: Record<EmptyStateKind, IllustrationName> = { | |||
| 37 | whiteboard: "whiteboard", | 39 | whiteboard: "whiteboard", |
| 38 | work: "work", | 40 | work: "work", |
| 39 | "coming-soon": "coming-soon", | 41 | "coming-soon": "coming-soon", |
| 42 | + error: "server-down", | ||
| 40 | }; | 43 | }; |
| 41 | 44 | ||
| 42 | /** Empty panel with a theme-tinted illustration matching what is missing. */ | 45 | /** Empty panel with a theme-tinted illustration matching what is missing. */ |
| 43 | export function EmptyState(props: { | 46 | export function EmptyState(props: { |
| 44 | title: string; | 47 | title: string; |
| 48 | + /** Small line above the title, e.g. the "404" of the not-found page. */ | ||
| 49 | + eyebrow?: string; | ||
| 50 | + /** Render the title as the page's h1 (full-page states that own the page). */ | ||
| 51 | + pageHeading?: boolean; | ||
| 45 | description?: string; | 52 | description?: string; |
| 46 | kind?: EmptyStateKind; | 53 | kind?: EmptyStateKind; |
| 47 | /** A way out, e.g. "clear search" under a no-results panel. */ | 54 | /** A way out, e.g. "clear search" under a no-results panel. */ |
| @@ -60,7 +67,15 @@ export function EmptyState(props: { | |||
| 60 | <Illustration name={KIND_ILLUSTRATION[kind()]} class="h-32 w-48 sm:h-36 sm:w-56" /> | 67 | <Illustration name={KIND_ILLUSTRATION[kind()]} class="h-32 w-48 sm:h-36 sm:w-56" /> |
| 61 | 68 | ||
| 62 | <div class="space-y-1.5"> | 69 | <div class="space-y-1.5"> |
| 63 | - <p class="text-lg font-semibold leading-7 tracking-[-0.015em] text-text-strong">{props.title}</p> | 70 | + <Show when={props.eyebrow}> |
| 71 | + <p class="text-3xl font-semibold tracking-tight text-text-strong">{props.eyebrow}</p> | ||
| 72 | + </Show> | ||
| 73 | + <Dynamic | ||
| 74 | + component={props.pageHeading ? "h1" : "p"} | ||
| 75 | + class="text-lg font-semibold leading-7 tracking-[-0.015em] text-text-strong" | ||
| 76 | + > | ||
| 77 | + {props.title} | ||
| 78 | + </Dynamic> | ||
| 64 | <Show when={props.description}> | 79 | <Show when={props.description}> |
| 65 | <p class="mx-auto max-w-[420px] text-sm leading-[21px] text-text-subtle">{props.description}</p> | 80 | <p class="mx-auto max-w-[420px] text-sm leading-[21px] text-text-subtle">{props.description}</p> |
| 66 | </Show> | 81 | </Show> |
src/i18n/locales/en.tsmodified+27 -0
| @@ -383,6 +383,33 @@ export const en: Dict = { | |||
| 383 | "notifications.unreadCount": "{count} unread", | 383 | "notifications.unreadCount": "{count} unread", |
| 384 | "errors.notFoundDescription": "The page you're looking for may have moved or been deleted.", | 384 | "errors.notFoundDescription": "The page you're looking for may have moved or been deleted.", |
| 385 | "errors.accessDeniedDescription": "Your role can't view this section. Ask an administrator if you need access.", | 385 | "errors.accessDeniedDescription": "Your role can't view this section. Ask an administrator if you need access.", |
| 386 | + "errors.pageLoad.title": "This page could not load", | ||
| 387 | + "errors.pageLoad.retry": "Try again", | ||
| 388 | + "errors.pageLoad.retryIn": "Try again ({seconds}s)", | ||
| 389 | + "errors.pageLoad.details": "Technical details", | ||
| 390 | + "errors.pageLoad.status": "HTTP status", | ||
| 391 | + "errors.pageLoad.kind": "Cause", | ||
| 392 | + "errors.pageLoad.code": "Error code", | ||
| 393 | + "errors.pageLoad.module": "Module", | ||
| 394 | + "errors.pageLoad.retryAfter": "Retry after", | ||
| 395 | + "errors.pageLoad.seconds": "{seconds}s", | ||
| 396 | + "errors.pageLoad.page": "Page", | ||
| 397 | + "errors.pageLoad.message": "Raw message", | ||
| 398 | + "errors.pageLoad.kind.rateLimited": "Too many requests (rate limited)", | ||
| 399 | + "errors.pageLoad.kind.moduleOff": "Module switched off for the school", | ||
| 400 | + "errors.pageLoad.kind.unauthorized": "Session is not valid", | ||
| 401 | + "errors.pageLoad.kind.forbidden": "No permission", | ||
| 402 | + "errors.pageLoad.kind.timeout": "Request timed out", | ||
| 403 | + "errors.pageLoad.kind.unavailable": "Service temporarily unavailable", | ||
| 404 | + "errors.pageLoad.kind.server": "Server error", | ||
| 405 | + "errors.pageLoad.kind.request": "Request rejected", | ||
| 406 | + "errors.pageLoad.kind.offline": "No internet connection", | ||
| 407 | + "errors.pageLoad.kind.network": "Could not reach the server", | ||
| 408 | + "errors.pageLoad.kind.render": "Page error in the app", | ||
| 409 | + "errors.recordNotFound.title": "Record not found", | ||
| 410 | + "errors.recordNotFound.description": "This record may have been deleted, or the link is wrong.", | ||
| 411 | + "errors.recordNotFound.backToList": "Back to the list", | ||
| 412 | + "errors.recordNotFound.backHome": "Back to home", | ||
| 386 | "network.offlineTitle": "You're offline", | 413 | "network.offlineTitle": "You're offline", |
| 387 | "network.offlineDescription": "Some actions won't complete until your connection returns.", | 414 | "network.offlineDescription": "Some actions won't complete until your connection returns.", |
| 388 | "network.reconnect": "Reconnect", | 415 | "network.reconnect": "Reconnect", |
src/i18n/locales/tr.tsmodified+27 -0
| @@ -379,6 +379,33 @@ export const tr: Dict = { | |||
| 379 | "notifications.unreadCount": "{count} okunmamış", | 379 | "notifications.unreadCount": "{count} okunmamış", |
| 380 | "errors.notFoundDescription": "Aradığın sayfa taşınmış ya da silinmiş olabilir.", | 380 | "errors.notFoundDescription": "Aradığın sayfa taşınmış ya da silinmiş olabilir.", |
| 381 | "errors.accessDeniedDescription": "Rolün bu bölümü görüntülemeye yetkili değil. Gerekliyse kurum yöneticinden yetki iste.", | 381 | "errors.accessDeniedDescription": "Rolün bu bölümü görüntülemeye yetkili değil. Gerekliyse kurum yöneticinden yetki iste.", |
| 382 | + "errors.pageLoad.title": "Bu sayfa yüklenemedi", | ||
| 383 | + "errors.pageLoad.retry": "Tekrar dene", | ||
| 384 | + "errors.pageLoad.retryIn": "Tekrar dene ({seconds} sn)", | ||
| 385 | + "errors.pageLoad.details": "Teknik ayrıntı", | ||
| 386 | + "errors.pageLoad.status": "HTTP durumu", | ||
| 387 | + "errors.pageLoad.kind": "Sebep", | ||
| 388 | + "errors.pageLoad.code": "Hata kodu", | ||
| 389 | + "errors.pageLoad.module": "Modül", | ||
| 390 | + "errors.pageLoad.retryAfter": "Bekleme süresi", | ||
| 391 | + "errors.pageLoad.seconds": "{seconds} sn", | ||
| 392 | + "errors.pageLoad.page": "Sayfa", | ||
| 393 | + "errors.pageLoad.message": "Ham mesaj", | ||
| 394 | + "errors.pageLoad.kind.rateLimited": "Çok fazla istek (hız sınırı)", | ||
| 395 | + "errors.pageLoad.kind.moduleOff": "Modül okulda kapalı", | ||
| 396 | + "errors.pageLoad.kind.unauthorized": "Oturum geçersiz", | ||
| 397 | + "errors.pageLoad.kind.forbidden": "Yetki yok", | ||
| 398 | + "errors.pageLoad.kind.timeout": "İstek zaman aşımına uğradı", | ||
| 399 | + "errors.pageLoad.kind.unavailable": "Servis geçici olarak kullanılamıyor", | ||
| 400 | + "errors.pageLoad.kind.server": "Sunucu hatası", | ||
| 401 | + "errors.pageLoad.kind.request": "İstek reddedildi", | ||
| 402 | + "errors.pageLoad.kind.offline": "İnternet bağlantısı yok", | ||
| 403 | + "errors.pageLoad.kind.network": "Sunucuya ulaşılamadı", | ||
| 404 | + "errors.pageLoad.kind.render": "Uygulamada sayfa hatası", | ||
| 405 | + "errors.recordNotFound.title": "Kayıt bulunamadı", | ||
| 406 | + "errors.recordNotFound.description": "Bu kayıt silinmiş ya da bağlantı hatalı olabilir.", | ||
| 407 | + "errors.recordNotFound.backToList": "Listeye dön", | ||
| 408 | + "errors.recordNotFound.backHome": "Ana sayfaya dön", | ||
| 382 | "network.offlineTitle": "Bağlantın koptu", | 409 | "network.offlineTitle": "Bağlantın koptu", |
| 383 | "network.offlineDescription": "Bağlantı geri gelene kadar bazı işlemler tamamlanmayabilir.", | 410 | "network.offlineDescription": "Bağlantı geri gelene kadar bazı işlemler tamamlanmayabilir.", |
| 384 | "network.reconnect": "Yeniden bağlan", | 411 | "network.reconnect": "Yeniden bağlan", |
src/i18n/messages.tsmodified+27 -0
| @@ -588,6 +588,33 @@ export type MessageKey = | |||
| 588 | | "network.offlineTitle" | 588 | | "network.offlineTitle" |
| 589 | | "network.offlineDescription" | 589 | | "network.offlineDescription" |
| 590 | | "network.reconnect" | 590 | | "network.reconnect" |
| 591 | + | "errors.pageLoad.title" | ||
| 592 | + | "errors.pageLoad.retry" | ||
| 593 | + | "errors.pageLoad.retryIn" | ||
| 594 | + | "errors.pageLoad.details" | ||
| 595 | + | "errors.pageLoad.status" | ||
| 596 | + | "errors.pageLoad.kind" | ||
| 597 | + | "errors.pageLoad.code" | ||
| 598 | + | "errors.pageLoad.module" | ||
| 599 | + | "errors.pageLoad.retryAfter" | ||
| 600 | + | "errors.pageLoad.seconds" | ||
| 601 | + | "errors.pageLoad.page" | ||
| 602 | + | "errors.pageLoad.message" | ||
| 603 | + | "errors.pageLoad.kind.rateLimited" | ||
| 604 | + | "errors.pageLoad.kind.moduleOff" | ||
| 605 | + | "errors.pageLoad.kind.unauthorized" | ||
| 606 | + | "errors.pageLoad.kind.forbidden" | ||
| 607 | + | "errors.pageLoad.kind.timeout" | ||
| 608 | + | "errors.pageLoad.kind.unavailable" | ||
| 609 | + | "errors.pageLoad.kind.server" | ||
| 610 | + | "errors.pageLoad.kind.request" | ||
| 611 | + | "errors.pageLoad.kind.offline" | ||
| 612 | + | "errors.pageLoad.kind.network" | ||
| 613 | + | "errors.pageLoad.kind.render" | ||
| 614 | + | "errors.recordNotFound.title" | ||
| 615 | + | "errors.recordNotFound.description" | ||
| 616 | + | "errors.recordNotFound.backToList" | ||
| 617 | + | "errors.recordNotFound.backHome" | ||
| 591 | | "parents.title" | 618 | | "parents.title" |
| 592 | | "parents.subtitle" | 619 | | "parents.subtitle" |
| 593 | | "common.loading" | 620 | | "common.loading" |
src/lib/illustrations.tsmodified+1 -0
| @@ -21,6 +21,7 @@ export type IllustrationName = | |||
| 21 | | "payments" | 21 | | "payments" |
| 22 | | "people" | 22 | | "people" |
| 23 | | "schedule" | 23 | | "schedule" |
| 24 | + | "server-down" | ||
| 24 | | "whiteboard" | 25 | | "whiteboard" |
| 25 | | "work"; | 26 | | "work"; |
| 26 | 27 | ||