✨ empty-state CTAs and save flash banners
Browse files at this commitf1d34524f55ae2241aade905eadb3bf40a7d5ba5Parent: d6c0195- feat
- ✨ empty-state CTAs and save flash banners
9 changed files +155 -21
- src/components/notes/note-list.tsx +10 -5
- src/components/ui/alert.tsx +6 -4
- src/components/ui/empty-state.tsx +28 -0
- src/i18n/messages.ts +9 -0
- src/lib/flash.ts +13 -0
- src/pages/courses-page.tsx +24 -2
- src/pages/events-page.tsx +18 -3
- src/pages/exams-page.tsx +25 -2
- src/pages/notes-page.tsx +22 -5
src/components/notes/note-list.tsxmodified+10 -5
| @@ -1,11 +1,14 @@ | |||
| 1 | -import { For, Show, createSignal } from "solid-js"; | 1 | +import { For, Show, createSignal, type JSX } from "solid-js"; |
| 2 | import type { Note } from "@/api/types"; | 2 | import type { Note } from "@/api/types"; |
| 3 | import { NoteCard } from "@/components/notes/note-card"; | 3 | import { NoteCard } from "@/components/notes/note-card"; |
| 4 | import { NoteReaderPanel } from "@/components/notes/note-reader-panel"; | 4 | import { NoteReaderPanel } from "@/components/notes/note-reader-panel"; |
| 5 | +import { EmptyState } from "@/components/ui/empty-state"; | ||
| 5 | 6 | ||
| 6 | export function NoteList(props: { | 7 | export function NoteList(props: { |
| 7 | notes: Note[]; | 8 | notes: Note[]; |
| 8 | - emptyLabel?: string; | 9 | + emptyTitle: string; |
| 10 | + emptyDescription?: string; | ||
| 11 | + emptyAction?: JSX.Element; | ||
| 9 | onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>; | 12 | onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>; |
| 10 | onDelete: (id: string) => Promise<void>; | 13 | onDelete: (id: string) => Promise<void>; |
| 11 | }) { | 14 | }) { |
| @@ -16,9 +19,11 @@ export function NoteList(props: { | |||
| 16 | <Show | 19 | <Show |
| 17 | when={props.notes.length > 0} | 20 | when={props.notes.length > 0} |
| 18 | fallback={ | 21 | fallback={ |
| 19 | - <div class="flex min-h-[12rem] items-center justify-center rounded-lg border border-dashed border-border/80 bg-muted/20 px-6 text-center text-sm text-muted-foreground"> | 22 | + <EmptyState |
| 20 | - {props.emptyLabel ?? ""} | 23 | + title={props.emptyTitle} |
| 21 | - </div> | 24 | + description={props.emptyDescription} |
| 25 | + action={props.emptyAction} | ||
| 26 | + /> | ||
| 22 | } | 27 | } |
| 23 | > | 28 | > |
| 24 | <ul class="grid grid-cols-2 gap-3 xl:grid-cols-3"> | 29 | <ul class="grid grid-cols-2 gap-3 xl:grid-cols-3"> |
src/components/ui/alert.tsxmodified+6 -4
| @@ -2,16 +2,18 @@ import type { ComponentProps, ParentProps } from "solid-js"; | |||
| 2 | import { splitProps } from "solid-js"; | 2 | import { splitProps } from "solid-js"; |
| 3 | import { cn } from "@/lib/cn"; | 3 | import { cn } from "@/lib/cn"; |
| 4 | 4 | ||
| 5 | -export function Alert(props: ParentProps<ComponentProps<"div"> & { variant?: "default" | "destructive" }>) { | 5 | +export function Alert( |
| 6 | + props: ParentProps<ComponentProps<"div"> & { variant?: "default" | "destructive" | "success" }>, | ||
| 7 | +) { | ||
| 6 | const [local, rest] = splitProps(props, ["class", "children", "variant"]); | 8 | const [local, rest] = splitProps(props, ["class", "children", "variant"]); |
| 7 | return ( | 9 | return ( |
| 8 | <div | 10 | <div |
| 9 | role="alert" | 11 | role="alert" |
| 10 | class={cn( | 12 | class={cn( |
| 11 | "relative w-full rounded-md border px-4 py-3 text-sm shadow-sm", | 13 | "relative w-full rounded-md border px-4 py-3 text-sm shadow-sm", |
| 12 | - local.variant === "destructive" | 14 | + local.variant === "destructive" && "border-destructive/30 bg-destructive/10 text-destructive", |
| 13 | - ? "border-destructive/30 bg-destructive/10 text-destructive" | 15 | + local.variant === "success" && "border-emerald-600/30 bg-emerald-600/10 text-emerald-800 dark:text-emerald-300", |
| 14 | - : "bg-background text-foreground", | 16 | + (!local.variant || local.variant === "default") && "bg-background text-foreground", |
| 15 | local.class, | 17 | local.class, |
| 16 | )} | 18 | )} |
| 17 | {...rest} | 19 | {...rest} |
src/components/ui/empty-state.tsxadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +import type { JSX } from "solid-js"; | ||
| 2 | +import { Show } from "solid-js"; | ||
| 3 | +import { cn } from "@/lib/cn"; | ||
| 4 | + | ||
| 5 | +/** Dashed empty panel with optional primary action. */ | ||
| 6 | +export function EmptyState(props: { | ||
| 7 | + title: string; | ||
| 8 | + description?: string; | ||
| 9 | + action?: JSX.Element; | ||
| 10 | + class?: string; | ||
| 11 | +}) { | ||
| 12 | + return ( | ||
| 13 | + <div | ||
| 14 | + class={cn( | ||
| 15 | + "flex min-h-[12rem] flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border/80 bg-muted/20 px-6 py-10 text-center", | ||
| 16 | + props.class, | ||
| 17 | + )} | ||
| 18 | + > | ||
| 19 | + <p class="text-sm font-medium text-foreground">{props.title}</p> | ||
| 20 | + <Show when={props.description}> | ||
| 21 | + <p class="max-w-sm text-sm leading-6 text-muted-foreground">{props.description}</p> | ||
| 22 | + </Show> | ||
| 23 | + <Show when={props.action}> | ||
| 24 | + <div class="pt-1">{props.action}</div> | ||
| 25 | + </Show> | ||
| 26 | + </div> | ||
| 27 | + ); | ||
| 28 | +} | ||
src/i18n/messages.tsmodified+9 -0
| @@ -77,6 +77,9 @@ export type MessageKey = | |||
| 77 | | "common.searchPlaceholder" | 77 | | "common.searchPlaceholder" |
| 78 | | "common.all" | 78 | | "common.all" |
| 79 | | "common.saveAttendance" | 79 | | "common.saveAttendance" |
| 80 | + | "common.created" | ||
| 81 | + | "common.deleted" | ||
| 82 | + | "common.saved" | ||
| 80 | | "theme.light" | 83 | | "theme.light" |
| 81 | | "theme.dark" | 84 | | "theme.dark" |
| 82 | | "theme.toggle" | 85 | | "theme.toggle" |
| @@ -618,6 +621,9 @@ const en: Dict = { | |||
| 618 | "common.searchPlaceholder": "Search…", | 621 | "common.searchPlaceholder": "Search…", |
| 619 | "common.all": "All", | 622 | "common.all": "All", |
| 620 | "common.saveAttendance": "Save my attendance", | 623 | "common.saveAttendance": "Save my attendance", |
| 624 | + "common.created": "Created.", | ||
| 625 | + "common.deleted": "Deleted.", | ||
| 626 | + "common.saved": "Saved.", | ||
| 621 | "theme.light": "Light", | 627 | "theme.light": "Light", |
| 622 | "theme.dark": "Dark", | 628 | "theme.dark": "Dark", |
| 623 | "theme.toggle": "Toggle theme", | 629 | "theme.toggle": "Toggle theme", |
| @@ -1171,6 +1177,9 @@ const tr: Dict = { | |||
| 1171 | "common.searchPlaceholder": "Ara…", | 1177 | "common.searchPlaceholder": "Ara…", |
| 1172 | "common.all": "Tümü", | 1178 | "common.all": "Tümü", |
| 1173 | "common.saveAttendance": "Yoklamamı kaydet", | 1179 | "common.saveAttendance": "Yoklamamı kaydet", |
| 1180 | + "common.created": "Oluşturuldu.", | ||
| 1181 | + "common.deleted": "Silindi.", | ||
| 1182 | + "common.saved": "Kaydedildi.", | ||
| 1174 | "theme.light": "Açık", | 1183 | "theme.light": "Açık", |
| 1175 | "theme.dark": "Koyu", | 1184 | "theme.dark": "Koyu", |
| 1176 | "theme.toggle": "Tema", | 1185 | "theme.toggle": "Tema", |
src/lib/flash.tsadded+13 -0
| @@ -0,0 +1,13 @@ | |||
| 1 | +import { createEffect, createSignal, onCleanup, type Accessor, type Setter } from "solid-js"; | ||
| 2 | + | ||
| 3 | +/** Short-lived success banner; auto-clears after `ms` (default 3s). */ | ||
| 4 | +export function createFlash(ms = 3000): [Accessor<string>, Setter<string>] { | ||
| 5 | + const [message, setMessage] = createSignal(""); | ||
| 6 | + createEffect(() => { | ||
| 7 | + const text = message(); | ||
| 8 | + if (!text) return; | ||
| 9 | + const id = window.setTimeout(() => setMessage(""), ms); | ||
| 10 | + onCleanup(() => window.clearTimeout(id)); | ||
| 11 | + }); | ||
| 12 | + return [message, setMessage]; | ||
| 13 | +} | ||
src/pages/courses-page.tsxmodified+24 -2
| @@ -12,7 +12,8 @@ import { RouteGuard } from "@/components/layout/route-guard"; | |||
| 12 | import { PageHeader } from "@/components/layout/page-header"; | 12 | import { PageHeader } from "@/components/layout/page-header"; |
| 13 | import { Badge } from "@/components/ui/badge"; | 13 | import { Badge } from "@/components/ui/badge"; |
| 14 | import { Button } from "@/components/ui/button"; | 14 | import { Button } from "@/components/ui/button"; |
| 15 | -import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; | 15 | +import { DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; |
| 16 | +import { EmptyState } from "@/components/ui/empty-state"; | ||
| 16 | import { DataToolbar } from "@/components/ui/data-toolbar"; | 17 | import { DataToolbar } from "@/components/ui/data-toolbar"; |
| 17 | import { IconEye, IconPlus } from "@/components/ui/icons"; | 18 | import { IconEye, IconPlus } from "@/components/ui/icons"; |
| 18 | import { Input } from "@/components/ui/input"; | 19 | import { Input } from "@/components/ui/input"; |
| @@ -23,6 +24,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@ | |||
| 23 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 24 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 24 | import { Textarea } from "@/components/ui/textarea"; | 25 | import { Textarea } from "@/components/ui/textarea"; |
| 25 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 26 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 27 | +import { createFlash } from "@/lib/flash"; | ||
| 26 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; | 28 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; |
| 27 | import { useAuth } from "@/stores/auth-context"; | 29 | import { useAuth } from "@/stores/auth-context"; |
| 28 | import { useT } from "@/stores/preferences-context"; | 30 | import { useT } from "@/stores/preferences-context"; |
| @@ -49,6 +51,7 @@ function CoursesContent() { | |||
| 49 | const [kind, setKind] = createSignal<CourseKind>("course"); | 51 | const [kind, setKind] = createSignal<CourseKind>("course"); |
| 50 | const [termId, setTermId] = createSignal(""); | 52 | const [termId, setTermId] = createSignal(""); |
| 51 | const [error, setError] = createSignal(""); | 53 | const [error, setError] = createSignal(""); |
| 54 | + const [flash, setFlash] = createFlash(); | ||
| 52 | const [pending, setPending] = createSignal(false); | 55 | const [pending, setPending] = createSignal(false); |
| 53 | const [query, setQuery] = createSignal(""); | 56 | const [query, setQuery] = createSignal(""); |
| 54 | const [termFilter, setTermFilter] = createSignal("all"); | 57 | const [termFilter, setTermFilter] = createSignal("all"); |
| @@ -128,6 +131,7 @@ function CoursesContent() { | |||
| 128 | setTermId(""); | 131 | setTermId(""); |
| 129 | setShowForm(false); | 132 | setShowForm(false); |
| 130 | await refetch(); | 133 | await refetch(); |
| 134 | + setFlash(t("common.created")); | ||
| 131 | } catch (err) { | 135 | } catch (err) { |
| 132 | setError(formatApiError(err)); | 136 | setError(formatApiError(err)); |
| 133 | } finally { | 137 | } finally { |
| @@ -221,11 +225,29 @@ function CoursesContent() { | |||
| 221 | } | 225 | } |
| 222 | /> | 226 | /> |
| 223 | 227 | ||
| 228 | + <Show when={flash()}> | ||
| 229 | + <Alert variant="success">{flash()}</Alert> | ||
| 230 | + </Show> | ||
| 224 | <Suspense fallback={<DataTableSkeleton columns={5} rows={8} />}> | 231 | <Suspense fallback={<DataTableSkeleton columns={5} rows={8} />}> |
| 225 | <Show when={list.error}> | 232 | <Show when={list.error}> |
| 226 | <Alert variant="destructive">{formatApiError(list.error)}</Alert> | 233 | <Alert variant="destructive">{formatApiError(list.error)}</Alert> |
| 227 | </Show> | 234 | </Show> |
| 228 | - <Show when={pageItems().length > 0} fallback={<DataTableEmpty>{t("courses.empty")}</DataTableEmpty>}> | 235 | + <Show |
| 236 | + when={pageItems().length > 0} | ||
| 237 | + fallback={ | ||
| 238 | + <EmptyState | ||
| 239 | + title={t("courses.empty")} | ||
| 240 | + action={ | ||
| 241 | + canCreate() ? ( | ||
| 242 | + <Button type="button" size="sm" class="rounded-lg" onClick={() => setShowForm(true)}> | ||
| 243 | + <IconPlus class="h-4 w-4" /> | ||
| 244 | + {t("courses.create")} | ||
| 245 | + </Button> | ||
| 246 | + ) : undefined | ||
| 247 | + } | ||
| 248 | + /> | ||
| 249 | + } | ||
| 250 | + > | ||
| 229 | <div class="space-y-4"> | 251 | <div class="space-y-4"> |
| 230 | <div class="flex flex-wrap items-center justify-between gap-3"> | 252 | <div class="flex flex-wrap items-center justify-between gap-3"> |
| 231 | <div> | 253 | <div> |
src/pages/events-page.tsxmodified+18 -3
| @@ -10,11 +10,13 @@ import { EventForm } from "@/components/events/event-form"; | |||
| 10 | import { RouteGuard } from "@/components/layout/route-guard"; | 10 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 11 | import { PageHeader } from "@/components/layout/page-header"; | 11 | import { PageHeader } from "@/components/layout/page-header"; |
| 12 | import { DataToolbar } from "@/components/ui/data-toolbar"; | 12 | import { DataToolbar } from "@/components/ui/data-toolbar"; |
| 13 | +import { EmptyState } from "@/components/ui/empty-state"; | ||
| 13 | import { IconPlus } from "@/components/ui/icons"; | 14 | import { IconPlus } from "@/components/ui/icons"; |
| 14 | import { PageSpinner } from "@/components/ui/page-spinner"; | 15 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 15 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 16 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 16 | import { Select } from "@/components/ui/select"; | 17 | import { Select } from "@/components/ui/select"; |
| 17 | import { SidePanel } from "@/components/ui/side-panel"; | 18 | import { SidePanel } from "@/components/ui/side-panel"; |
| 19 | +import { createFlash } from "@/lib/flash"; | ||
| 18 | import { formatDateTime } from "@/lib/format"; | 20 | import { formatDateTime } from "@/lib/format"; |
| 19 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; | 21 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; |
| 20 | import { hasMinRole } from "@/lib/roles"; | 22 | import { hasMinRole } from "@/lib/roles"; |
| @@ -36,6 +38,7 @@ function EventsContent() { | |||
| 36 | const { locale } = usePreferences(); | 38 | const { locale } = usePreferences(); |
| 37 | const t = useT(); | 39 | const t = useT(); |
| 38 | const [error, setError] = createSignal(""); | 40 | const [error, setError] = createSignal(""); |
| 41 | + const [flash, setFlash] = createFlash(); | ||
| 39 | const [showForm, setShowForm] = createSignal(false); | 42 | const [showForm, setShowForm] = createSignal(false); |
| 40 | const [query, setQuery] = createSignal(""); | 43 | const [query, setQuery] = createSignal(""); |
| 41 | const [timeFilter, setTimeFilter] = createSignal("all"); | 44 | const [timeFilter, setTimeFilter] = createSignal("all"); |
| @@ -120,6 +123,7 @@ function EventsContent() { | |||
| 120 | await postEvent(body); | 123 | await postEvent(body); |
| 121 | setShowForm(false); | 124 | setShowForm(false); |
| 122 | await refetch(); | 125 | await refetch(); |
| 126 | + setFlash(t("common.created")); | ||
| 123 | } catch (err) { | 127 | } catch (err) { |
| 124 | setError(formatApiError(err)); | 128 | setError(formatApiError(err)); |
| 125 | throw err; | 129 | throw err; |
| @@ -128,6 +132,9 @@ function EventsContent() { | |||
| 128 | /> | 132 | /> |
| 129 | </SidePanel> | 133 | </SidePanel> |
| 130 | 134 | ||
| 135 | + <Show when={flash()}> | ||
| 136 | + <Alert variant="success">{flash()}</Alert> | ||
| 137 | + </Show> | ||
| 131 | {error() && <p class="text-sm text-destructive">{error()}</p>} | 138 | {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 132 | 139 | ||
| 133 | <section class="data-shell space-y-4 p-4"> | 140 | <section class="data-shell space-y-4 p-4"> |
| @@ -163,9 +170,17 @@ function EventsContent() { | |||
| 163 | <Show | 170 | <Show |
| 164 | when={pageItems().length > 0} | 171 | when={pageItems().length > 0} |
| 165 | fallback={ | 172 | fallback={ |
| 166 | - <div class="rounded-sm border border-dashed border-border bg-muted/20 px-6 py-16 text-center text-sm text-muted-foreground"> | 173 | + <EmptyState |
| 167 | - {t("events.empty")} | 174 | + title={t("events.empty")} |
| 168 | - </div> | 175 | + action={ |
| 176 | + canCreate() ? ( | ||
| 177 | + <Button type="button" size="sm" class="rounded-lg" onClick={() => setShowForm(true)}> | ||
| 178 | + <IconPlus class="h-4 w-4" /> | ||
| 179 | + {t("events.create")} | ||
| 180 | + </Button> | ||
| 181 | + ) : undefined | ||
| 182 | + } | ||
| 183 | + /> | ||
| 169 | } | 184 | } |
| 170 | > | 185 | > |
| 171 | <div class="space-y-4"> | 186 | <div class="space-y-4"> |
src/pages/exams-page.tsxmodified+25 -2
| @@ -13,7 +13,8 @@ import { PageHeader } from "@/components/layout/page-header"; | |||
| 13 | import { Alert } from "@/components/ui/alert"; | 13 | import { Alert } from "@/components/ui/alert"; |
| 14 | import { Badge } from "@/components/ui/badge"; | 14 | import { Badge } from "@/components/ui/badge"; |
| 15 | import { Button } from "@/components/ui/button"; | 15 | import { Button } from "@/components/ui/button"; |
| 16 | -import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; | 16 | +import { DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; |
| 17 | +import { EmptyState } from "@/components/ui/empty-state"; | ||
| 17 | import { DataToolbar } from "@/components/ui/data-toolbar"; | 18 | import { DataToolbar } from "@/components/ui/data-toolbar"; |
| 18 | import { IconEdit, IconEye, IconPlus } from "@/components/ui/icons"; | 19 | import { IconEdit, IconEye, IconPlus } from "@/components/ui/icons"; |
| 19 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 20 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| @@ -23,6 +24,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@ | |||
| 23 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 24 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 24 | import { createNow } from "@/lib/create-now"; | 25 | import { createNow } from "@/lib/create-now"; |
| 25 | import { examKindLabel } from "@/lib/exam-labels"; | 26 | import { examKindLabel } from "@/lib/exam-labels"; |
| 27 | +import { createFlash } from "@/lib/flash"; | ||
| 26 | import { formatDateTime } from "@/lib/format"; | 28 | import { formatDateTime } from "@/lib/format"; |
| 27 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; | 29 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; |
| 28 | import { hasMinRole } from "@/lib/roles"; | 30 | import { hasMinRole } from "@/lib/roles"; |
| @@ -56,6 +58,7 @@ function ExamsContent() { | |||
| 56 | const [selectedCourseId, setSelectedCourseId] = createSignal(""); | 58 | const [selectedCourseId, setSelectedCourseId] = createSignal(""); |
| 57 | const [editingExam, setEditingExam] = createSignal<Exam | null>(null); | 59 | const [editingExam, setEditingExam] = createSignal<Exam | null>(null); |
| 58 | const [page, setPage] = createSignal(0); | 60 | const [page, setPage] = createSignal(0); |
| 61 | + const [flash, setFlash] = createFlash(); | ||
| 59 | 62 | ||
| 60 | const [courses] = createResource( | 63 | const [courses] = createResource( |
| 61 | () => (auth.user()?.role && auth.user()?.role !== "student" ? true : null), | 64 | () => (auth.user()?.role && auth.user()?.role !== "student" ? true : null), |
| @@ -160,6 +163,7 @@ function ExamsContent() { | |||
| 160 | }); | 163 | }); |
| 161 | setCreateOpen(false); | 164 | setCreateOpen(false); |
| 162 | await refetchExams(); | 165 | await refetchExams(); |
| 166 | + setFlash(t("common.created")); | ||
| 163 | }; | 167 | }; |
| 164 | 168 | ||
| 165 | const updateExam = async (values: ExamFormValues) => { | 169 | const updateExam = async (values: ExamFormValues) => { |
| @@ -168,6 +172,7 @@ function ExamsContent() { | |||
| 168 | await patchExamById(exam.id, values); | 172 | await patchExamById(exam.id, values); |
| 169 | setEditingExam(null); | 173 | setEditingExam(null); |
| 170 | await refetchExams(); | 174 | await refetchExams(); |
| 175 | + setFlash(t("common.saved")); | ||
| 171 | }; | 176 | }; |
| 172 | 177 | ||
| 173 | return ( | 178 | return ( |
| @@ -238,11 +243,29 @@ function ExamsContent() { | |||
| 238 | } | 243 | } |
| 239 | /> | 244 | /> |
| 240 | 245 | ||
| 246 | + <Show when={flash()}> | ||
| 247 | + <Alert variant="success">{flash()}</Alert> | ||
| 248 | + </Show> | ||
| 241 | <Suspense fallback={<DataTableSkeleton columns={6} rows={8} />}> | 249 | <Suspense fallback={<DataTableSkeleton columns={6} rows={8} />}> |
| 242 | <Show when={list.error}> | 250 | <Show when={list.error}> |
| 243 | <Alert variant="destructive">{formatApiError(list.error)}</Alert> | 251 | <Alert variant="destructive">{formatApiError(list.error)}</Alert> |
| 244 | </Show> | 252 | </Show> |
| 245 | - <Show when={pageItems().length > 0} fallback={<DataTableEmpty>{t("exams.empty")}</DataTableEmpty>}> | 253 | + <Show |
| 254 | + when={pageItems().length > 0} | ||
| 255 | + fallback={ | ||
| 256 | + <EmptyState | ||
| 257 | + title={t("exams.empty")} | ||
| 258 | + action={ | ||
| 259 | + canCreate() ? ( | ||
| 260 | + <Button type="button" size="sm" class="rounded-lg" onClick={() => setCreateOpen(true)}> | ||
| 261 | + <IconPlus class="h-4 w-4" /> | ||
| 262 | + {t("exams.create")} | ||
| 263 | + </Button> | ||
| 264 | + ) : undefined | ||
| 265 | + } | ||
| 266 | + /> | ||
| 267 | + } | ||
| 268 | + > | ||
| 246 | <DataTableFrame> | 269 | <DataTableFrame> |
| 247 | <Table class="data-table table-fixed min-w-[64rem]"> | 270 | <Table class="data-table table-fixed min-w-[64rem]"> |
| 248 | <colgroup> | 271 | <colgroup> |
src/pages/notes-page.tsxmodified+22 -5
| @@ -15,6 +15,7 @@ import { IconPlus } from "@/components/ui/icons"; | |||
| 15 | import { PageSpinner } from "@/components/ui/page-spinner"; | 15 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 16 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 16 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 17 | import { SidePanel } from "@/components/ui/side-panel"; | 17 | import { SidePanel } from "@/components/ui/side-panel"; |
| 18 | +import { createFlash } from "@/lib/flash"; | ||
| 18 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; | 19 | import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; |
| 19 | import { useT } from "@/stores/preferences-context"; | 20 | import { useT } from "@/stores/preferences-context"; |
| 20 | 21 | ||
| @@ -31,6 +32,7 @@ export default function NotesPage() { | |||
| 31 | function NotesContent() { | 32 | function NotesContent() { |
| 32 | const t = useT(); | 33 | const t = useT(); |
| 33 | const [error, setError] = createSignal(""); | 34 | const [error, setError] = createSignal(""); |
| 35 | + const [flash, setFlash] = createFlash(); | ||
| 34 | const [createOpen, setCreateOpen] = createSignal(false); | 36 | const [createOpen, setCreateOpen] = createSignal(false); |
| 35 | const [page, setPage] = createSignal(0); | 37 | const [page, setPage] = createSignal(0); |
| 36 | 38 | ||
| @@ -50,11 +52,12 @@ function NotesContent() { | |||
| 50 | const totalPages = createMemo(() => pagesOf(total(), NOTE_PAGE_SIZE)); | 52 | const totalPages = createMemo(() => pagesOf(total(), NOTE_PAGE_SIZE)); |
| 51 | const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); | 53 | const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); |
| 52 | 54 | ||
| 53 | - const wrap = async (fn: () => Promise<void>) => { | 55 | + const wrap = async (fn: () => Promise<void>, okMessage: string) => { |
| 54 | setError(""); | 56 | setError(""); |
| 55 | try { | 57 | try { |
| 56 | await fn(); | 58 | await fn(); |
| 57 | await refetch(); | 59 | await refetch(); |
| 60 | + setFlash(okMessage); | ||
| 58 | } catch (err) { | 61 | } catch (err) { |
| 59 | setError(formatApiError(err)); | 62 | setError(formatApiError(err)); |
| 60 | } | 63 | } |
| @@ -101,13 +104,20 @@ function NotesContent() { | |||
| 101 | } | 104 | } |
| 102 | await refetch(); | 105 | await refetch(); |
| 103 | setCreateOpen(false); | 106 | setCreateOpen(false); |
| 104 | - if (failedUploads > 0) setError(t("notes.fileUploadPartial", { count: failedUploads })); | 107 | + if (failedUploads > 0) { |
| 108 | + setError(t("notes.fileUploadPartial", { count: failedUploads })); | ||
| 109 | + return; | ||
| 110 | + } | ||
| 111 | + setFlash(t("common.created")); | ||
| 105 | }} | 112 | }} |
| 106 | /> | 113 | /> |
| 107 | </SidePanel> | 114 | </SidePanel> |
| 108 | 115 | ||
| 109 | <div class="space-y-5"> | 116 | <div class="space-y-5"> |
| 110 | <section class="min-w-0 space-y-4"> | 117 | <section class="min-w-0 space-y-4"> |
| 118 | + <Show when={flash()}> | ||
| 119 | + <Alert variant="success">{flash()}</Alert> | ||
| 120 | + </Show> | ||
| 111 | {error() && <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>} | 121 | {error() && <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>} |
| 112 | <Suspense fallback={<PageSpinner />}> | 122 | <Suspense fallback={<PageSpinner />}> |
| 113 | <Show when={list.error}> | 123 | <Show when={list.error}> |
| @@ -116,16 +126,23 @@ function NotesContent() { | |||
| 116 | <Show when={list()}> | 126 | <Show when={list()}> |
| 117 | <NoteList | 127 | <NoteList |
| 118 | notes={pageItems()} | 128 | notes={pageItems()} |
| 119 | - emptyLabel={t("notes.empty")} | 129 | + emptyTitle={t("dashboard.emptyNotesTitle")} |
| 130 | + emptyDescription={t("notes.empty")} | ||
| 131 | + emptyAction={ | ||
| 132 | + <Button type="button" size="sm" class="rounded-lg" onClick={() => setCreateOpen(true)}> | ||
| 133 | + <IconPlus class="h-4 w-4" /> | ||
| 134 | + {t("notes.new")} | ||
| 135 | + </Button> | ||
| 136 | + } | ||
| 120 | onUpdate={(id, values) => | 137 | onUpdate={(id, values) => |
| 121 | wrap(async () => { | 138 | wrap(async () => { |
| 122 | await patchNoteById(id, values); | 139 | await patchNoteById(id, values); |
| 123 | - }) | 140 | + }, t("common.saved")) |
| 124 | } | 141 | } |
| 125 | onDelete={(id) => | 142 | onDelete={(id) => |
| 126 | wrap(async () => { | 143 | wrap(async () => { |
| 127 | await deleteNoteById(id); | 144 | await deleteNoteById(id); |
| 128 | - }) | 145 | + }, t("common.deleted")) |
| 129 | } | 146 | } |
| 130 | /> | 147 | /> |
| 131 | <Show when={total() > NOTE_PAGE_SIZE}> | 148 | <Show when={total() > NOTE_PAGE_SIZE}> |