forge
Explore
Log in

Don't you dare go Hollow

✨ empty-state CTAs and save flash banners

Browse files at this commit

f1d34524f55ae2241aade905eadb3bf40a7d5ba5Burak BoduroğluParent: d6c0195
  • feat
    • ✨ empty-state CTAs and save flash banners
Show full message
feat: ✨ empty-state CTAs and save flash banners
- EmptyState component with optional primary action
- notes/courses/exams/events empty lists show create CTA when allowed
- createFlash helper + Alert success variant for short confirmations
- i18n: common.created/deleted/saved (en/tr)
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";
22 import type { Note } from "@/api/types";
33 import { NoteCard } from "@/components/notes/note-card";
44 import { NoteReaderPanel } from "@/components/notes/note-reader-panel";
5+import { EmptyState } from "@/components/ui/empty-state";
56
67 export function NoteList(props: {
78 notes: Note[];
8- emptyLabel?: string;
9+ emptyTitle: string;
10+ emptyDescription?: string;
11+ emptyAction?: JSX.Element;
912 onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>;
1013 onDelete: (id: string) => Promise<void>;
1114 }) {
@@ -16,9 +19,11 @@ export function NoteList(props: {
1619 <Show
1720 when={props.notes.length > 0}
1821 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">
20- {props.emptyLabel ?? ""}
21- </div>
22+ <EmptyState
23+ title={props.emptyTitle}
24+ description={props.emptyDescription}
25+ action={props.emptyAction}
26+ />
2227 }
2328 >
2429 <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";
22 import { splitProps } from "solid-js";
33 import { cn } from "@/lib/cn";
44
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+) {
68 const [local, rest] = splitProps(props, ["class", "children", "variant"]);
79 return (
810 <div
911 role="alert"
1012 class={cn(
1113 "relative w-full rounded-md border px-4 py-3 text-sm shadow-sm",
12- local.variant === "destructive"
13- ? "border-destructive/30 bg-destructive/10 text-destructive"
14- : "bg-background text-foreground",
14+ local.variant === "destructive" && "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",
16+ (!local.variant || local.variant === "default") && "bg-background text-foreground",
1517 local.class,
1618 )}
1719 {...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 =
7777 | "common.searchPlaceholder"
7878 | "common.all"
7979 | "common.saveAttendance"
80+ | "common.created"
81+ | "common.deleted"
82+ | "common.saved"
8083 | "theme.light"
8184 | "theme.dark"
8285 | "theme.toggle"
@@ -618,6 +621,9 @@ const en: Dict = {
618621 "common.searchPlaceholder": "Search…",
619622 "common.all": "All",
620623 "common.saveAttendance": "Save my attendance",
624+ "common.created": "Created.",
625+ "common.deleted": "Deleted.",
626+ "common.saved": "Saved.",
621627 "theme.light": "Light",
622628 "theme.dark": "Dark",
623629 "theme.toggle": "Toggle theme",
@@ -1171,6 +1177,9 @@ const tr: Dict = {
11711177 "common.searchPlaceholder": "Ara…",
11721178 "common.all": "Tümü",
11731179 "common.saveAttendance": "Yoklamamı kaydet",
1180+ "common.created": "Oluşturuldu.",
1181+ "common.deleted": "Silindi.",
1182+ "common.saved": "Kaydedildi.",
11741183 "theme.light": "Açık",
11751184 "theme.dark": "Koyu",
11761185 "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";
1212 import { PageHeader } from "@/components/layout/page-header";
1313 import { Badge } from "@/components/ui/badge";
1414 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";
1617 import { DataToolbar } from "@/components/ui/data-toolbar";
1718 import { IconEye, IconPlus } from "@/components/ui/icons";
1819 import { Input } from "@/components/ui/input";
@@ -23,6 +24,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@
2324 import { TableRowActions } from "@/components/ui/table-row-actions";
2425 import { Textarea } from "@/components/ui/textarea";
2526 import { PaginationControls } from "@/components/ui/pagination-controls";
27+import { createFlash } from "@/lib/flash";
2628 import { loadListPage, totalPages as pagesOf } from "@/lib/list-page";
2729 import { useAuth } from "@/stores/auth-context";
2830 import { useT } from "@/stores/preferences-context";
@@ -49,6 +51,7 @@ function CoursesContent() {
4951 const [kind, setKind] = createSignal<CourseKind>("course");
5052 const [termId, setTermId] = createSignal("");
5153 const [error, setError] = createSignal("");
54+ const [flash, setFlash] = createFlash();
5255 const [pending, setPending] = createSignal(false);
5356 const [query, setQuery] = createSignal("");
5457 const [termFilter, setTermFilter] = createSignal("all");
@@ -128,6 +131,7 @@ function CoursesContent() {
128131 setTermId("");
129132 setShowForm(false);
130133 await refetch();
134+ setFlash(t("common.created"));
131135 } catch (err) {
132136 setError(formatApiError(err));
133137 } finally {
@@ -221,11 +225,29 @@ function CoursesContent() {
221225 }
222226 />
223227
228+ <Show when={flash()}>
229+ <Alert variant="success">{flash()}</Alert>
230+ </Show>
224231 <Suspense fallback={<DataTableSkeleton columns={5} rows={8} />}>
225232 <Show when={list.error}>
226233 <Alert variant="destructive">{formatApiError(list.error)}</Alert>
227234 </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+ >
229251 <div class="space-y-4">
230252 <div class="flex flex-wrap items-center justify-between gap-3">
231253 <div>
src/pages/events-page.tsxmodified+18 -3
@@ -10,11 +10,13 @@ import { EventForm } from "@/components/events/event-form";
1010 import { RouteGuard } from "@/components/layout/route-guard";
1111 import { PageHeader } from "@/components/layout/page-header";
1212 import { DataToolbar } from "@/components/ui/data-toolbar";
13+import { EmptyState } from "@/components/ui/empty-state";
1314 import { IconPlus } from "@/components/ui/icons";
1415 import { PageSpinner } from "@/components/ui/page-spinner";
1516 import { PaginationControls } from "@/components/ui/pagination-controls";
1617 import { Select } from "@/components/ui/select";
1718 import { SidePanel } from "@/components/ui/side-panel";
19+import { createFlash } from "@/lib/flash";
1820 import { formatDateTime } from "@/lib/format";
1921 import { loadListPage, totalPages as pagesOf } from "@/lib/list-page";
2022 import { hasMinRole } from "@/lib/roles";
@@ -36,6 +38,7 @@ function EventsContent() {
3638 const { locale } = usePreferences();
3739 const t = useT();
3840 const [error, setError] = createSignal("");
41+ const [flash, setFlash] = createFlash();
3942 const [showForm, setShowForm] = createSignal(false);
4043 const [query, setQuery] = createSignal("");
4144 const [timeFilter, setTimeFilter] = createSignal("all");
@@ -120,6 +123,7 @@ function EventsContent() {
120123 await postEvent(body);
121124 setShowForm(false);
122125 await refetch();
126+ setFlash(t("common.created"));
123127 } catch (err) {
124128 setError(formatApiError(err));
125129 throw err;
@@ -128,6 +132,9 @@ function EventsContent() {
128132 />
129133 </SidePanel>
130134
135+ <Show when={flash()}>
136+ <Alert variant="success">{flash()}</Alert>
137+ </Show>
131138 {error() && <p class="text-sm text-destructive">{error()}</p>}
132139
133140 <section class="data-shell space-y-4 p-4">
@@ -163,9 +170,17 @@ function EventsContent() {
163170 <Show
164171 when={pageItems().length > 0}
165172 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">
167- {t("events.empty")}
168- </div>
173+ <EmptyState
174+ title={t("events.empty")}
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+ />
169184 }
170185 >
171186 <div class="space-y-4">
src/pages/exams-page.tsxmodified+25 -2
@@ -13,7 +13,8 @@ import { PageHeader } from "@/components/layout/page-header";
1313 import { Alert } from "@/components/ui/alert";
1414 import { Badge } from "@/components/ui/badge";
1515 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";
1718 import { DataToolbar } from "@/components/ui/data-toolbar";
1819 import { IconEdit, IconEye, IconPlus } from "@/components/ui/icons";
1920 import { PaginationControls } from "@/components/ui/pagination-controls";
@@ -23,6 +24,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@
2324 import { TableRowActions } from "@/components/ui/table-row-actions";
2425 import { createNow } from "@/lib/create-now";
2526 import { examKindLabel } from "@/lib/exam-labels";
27+import { createFlash } from "@/lib/flash";
2628 import { formatDateTime } from "@/lib/format";
2729 import { loadListPage, totalPages as pagesOf } from "@/lib/list-page";
2830 import { hasMinRole } from "@/lib/roles";
@@ -56,6 +58,7 @@ function ExamsContent() {
5658 const [selectedCourseId, setSelectedCourseId] = createSignal("");
5759 const [editingExam, setEditingExam] = createSignal<Exam | null>(null);
5860 const [page, setPage] = createSignal(0);
61+ const [flash, setFlash] = createFlash();
5962
6063 const [courses] = createResource(
6164 () => (auth.user()?.role && auth.user()?.role !== "student" ? true : null),
@@ -160,6 +163,7 @@ function ExamsContent() {
160163 });
161164 setCreateOpen(false);
162165 await refetchExams();
166+ setFlash(t("common.created"));
163167 };
164168
165169 const updateExam = async (values: ExamFormValues) => {
@@ -168,6 +172,7 @@ function ExamsContent() {
168172 await patchExamById(exam.id, values);
169173 setEditingExam(null);
170174 await refetchExams();
175+ setFlash(t("common.saved"));
171176 };
172177
173178 return (
@@ -238,11 +243,29 @@ function ExamsContent() {
238243 }
239244 />
240245
246+ <Show when={flash()}>
247+ <Alert variant="success">{flash()}</Alert>
248+ </Show>
241249 <Suspense fallback={<DataTableSkeleton columns={6} rows={8} />}>
242250 <Show when={list.error}>
243251 <Alert variant="destructive">{formatApiError(list.error)}</Alert>
244252 </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+ >
246269 <DataTableFrame>
247270 <Table class="data-table table-fixed min-w-[64rem]">
248271 <colgroup>
src/pages/notes-page.tsxmodified+22 -5
@@ -15,6 +15,7 @@ import { IconPlus } from "@/components/ui/icons";
1515 import { PageSpinner } from "@/components/ui/page-spinner";
1616 import { PaginationControls } from "@/components/ui/pagination-controls";
1717 import { SidePanel } from "@/components/ui/side-panel";
18+import { createFlash } from "@/lib/flash";
1819 import { loadListPage, totalPages as pagesOf } from "@/lib/list-page";
1920 import { useT } from "@/stores/preferences-context";
2021
@@ -31,6 +32,7 @@ export default function NotesPage() {
3132 function NotesContent() {
3233 const t = useT();
3334 const [error, setError] = createSignal("");
35+ const [flash, setFlash] = createFlash();
3436 const [createOpen, setCreateOpen] = createSignal(false);
3537 const [page, setPage] = createSignal(0);
3638
@@ -50,11 +52,12 @@ function NotesContent() {
5052 const totalPages = createMemo(() => pagesOf(total(), NOTE_PAGE_SIZE));
5153 const safePage = createMemo(() => Math.min(page(), totalPages() - 1));
5254
53- const wrap = async (fn: () => Promise<void>) => {
55+ const wrap = async (fn: () => Promise<void>, okMessage: string) => {
5456 setError("");
5557 try {
5658 await fn();
5759 await refetch();
60+ setFlash(okMessage);
5861 } catch (err) {
5962 setError(formatApiError(err));
6063 }
@@ -101,13 +104,20 @@ function NotesContent() {
101104 }
102105 await refetch();
103106 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"));
105112 }}
106113 />
107114 </SidePanel>
108115
109116 <div class="space-y-5">
110117 <section class="min-w-0 space-y-4">
118+ <Show when={flash()}>
119+ <Alert variant="success">{flash()}</Alert>
120+ </Show>
111121 {error() && <p class="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">{error()}</p>}
112122 <Suspense fallback={<PageSpinner />}>
113123 <Show when={list.error}>
@@ -116,16 +126,23 @@ function NotesContent() {
116126 <Show when={list()}>
117127 <NoteList
118128 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+ }
120137 onUpdate={(id, values) =>
121138 wrap(async () => {
122139 await patchNoteById(id, values);
123- })
140+ }, t("common.saved"))
124141 }
125142 onDelete={(id) =>
126143 wrap(async () => {
127144 await deleteNoteById(id);
128- })
145+ }, t("common.deleted"))
129146 }
130147 />
131148 <Show when={total() > NOTE_PAGE_SIZE}>