forge
Explore
Log in

Don't you dare go Hollow

🛟 the unsaved-input guard covers every form panel

Browse files at this commit

b507ba2a89bc29ad7e3ffeeca5d0e9c360fcc701Burak BoduroğluParent: 1747ea7
  • feat
    • 🛟 the unsaved-input guard covers every form panel
Show full message
feat: 🛟 the unsaved-input guard covers every form panel
- guardUnsaved on 37 create/edit side panels: users, schools, blueprints,
  subjects, notes, homework and grading, sessions, academic years, terms,
  appointments, bank questions, classes, courses, events, exam edit and
  grading, meals, payments, profiles, staff work, whiteboards
- left off: single-person pickers (little to lose), the multi-step exam
  create panels past their first step, and read-only panels
src/components/builder/create-school-panel.tsxmodified+1 -1
@@ -68,7 +68,7 @@ export function CreateSchoolPanel(props: { open: boolean; onOpenChange: (open: b
6868 };
6969
7070 return (
71- <SidePanel
71+ <SidePanel guardUnsaved
7272 size="wide"
7373 open={props.open}
7474 onOpenChange={(open) => {
src/components/builder/school-admin-access-panel.tsxmodified+1 -1
@@ -56,7 +56,7 @@ export function SchoolAdminAccessPanel(props: {
5656 };
5757
5858 return (
59- <SidePanel
59+ <SidePanel guardUnsaved
6060 open={props.mode != null}
6161 onOpenChange={(open) => {
6262 if (!open) {
src/components/classes/blueprint-panel.tsxmodified+1 -1
@@ -101,7 +101,7 @@ export function BlueprintPanel(props: {
101101 };
102102
103103 return (
104- <SidePanel
104+ <SidePanel guardUnsaved
105105 open={props.open}
106106 onOpenChange={props.onOpenChange}
107107 title={editing() ? t("classBlueprints.edit") : t("classBlueprints.new")}
src/components/courses/course-notes-panel.tsxmodified+1 -1
@@ -67,7 +67,7 @@ export function CourseNotesPanel(props: {
6767 </Show>
6868
6969 <Show when={props.canManage}>
70- <SidePanel open={props.createOpen} onOpenChange={props.onCreateOpenChange} title={t("courseNotes.new")}>
70+ <SidePanel guardUnsaved open={props.createOpen} onOpenChange={props.onCreateOpenChange} title={t("courseNotes.new")}>
7171 <NoteForm
7272 enableFiles
7373 submitLabel={t("common.create")}
src/components/courses/course-subjects-panel.tsxmodified+1 -1
@@ -112,7 +112,7 @@ export function CourseSubjectsPanel(props: { courseId: string; canManage: boolea
112112 <Show when={flash()}>
113113 <Alert variant="success">{flash()}</Alert>
114114 </Show>
115- <SidePanel open={props.createOpen} onOpenChange={setPanelOpen} title={editing() ? t("subjects.edit") : t("subjects.add")} description={t("subjects.help")}>
115+ <SidePanel guardUnsaved open={props.createOpen} onOpenChange={setPanelOpen} title={editing() ? t("subjects.edit") : t("subjects.add")} description={t("subjects.help")}>
116116 <form class="space-y-3" onSubmit={(event) => void save(event)}>
117117 <div class="space-y-1.5">
118118 <Label for="subject-name">{t("subjects.name")}</Label>
src/components/homework/course-homework-panel.tsxmodified+1 -1
@@ -217,7 +217,7 @@ export function CourseHomeworkPanel(props: {
217217 </Show>
218218 </Suspense>
219219
220- <SidePanel open={props.createOpen} onOpenChange={setPanelOpen} title={editing() ? t("homework.edit") : t("homework.add")} description={t("homework.help")}>
220+ <SidePanel guardUnsaved open={props.createOpen} onOpenChange={setPanelOpen} title={editing() ? t("homework.edit") : t("homework.add")} description={t("homework.help")}>
221221 <form class="space-y-4" onSubmit={(event) => void save(event)}>
222222 <Show when={error()}>
223223 <Alert variant="destructive">{error()}</Alert>
src/components/homework/homework-submissions-panel.tsxmodified+1 -1
@@ -155,7 +155,7 @@ export function HomeworkSubmissionsPanel(props: { homeworkId: string; instanceId
155155 <Show when={submissions.error}><Alert variant="destructive">{formatApiError(submissions.error, locale())}</Alert></Show>
156156 <DataTable columns={columns()} data={submissions()?.items ?? []} filterColumn="user" enablePagination pageSize={10} empty={t("common.noResults")} />
157157 </Suspense>
158- <SidePanel open={gradeTarget() != null} onOpenChange={(open) => !open && closeGrade()} title={t("homework.grade")} description={gradeTarget() ? studentLabel(gradeTarget()!.user) : ""}>
158+ <SidePanel guardUnsaved open={gradeTarget() != null} onOpenChange={(open) => !open && closeGrade()} title={t("homework.grade")} description={gradeTarget() ? studentLabel(gradeTarget()!.user) : ""}>
159159 <form class="space-y-4" onSubmit={(event) => void saveGrade(event)}>
160160 <Show when={error()}><Alert variant="destructive">{error()}</Alert></Show>
161161 <div class="space-y-1.5">
src/components/notes/note-card.tsxmodified+1 -1
@@ -75,7 +75,7 @@ export function NoteCard(props: {
7575 {error() && <p class="mt-2 text-sm text-destructive-text">{error()}</p>}
7676 </article>
7777
78- <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={props.note.title}>
78+ <SidePanel guardUnsaved open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={props.note.title}>
7979 <NoteForm
8080 initial={props.note}
8181 submitLabel={t("common.update")}
src/components/sessions/course-sessions-panel.tsxmodified+1 -1
@@ -265,7 +265,7 @@ export function CourseSessionsPanel(props: {
265265 />
266266 </Suspense>
267267
268- <SidePanel
268+ <SidePanel guardUnsaved
269269 open={panelOpen()}
270270 onOpenChange={(open) => {
271271 if (!open) {
src/components/users/create-user-panel.tsxmodified+1 -1
@@ -74,7 +74,7 @@ export function CreateUserPanel(props: {
7474 };
7575
7676 return (
77- <SidePanel
77+ <SidePanel guardUnsaved
7878 open={props.open}
7979 onOpenChange={(open) => { if (!open) close(); }}
8080 title={t("admin.createUser")}
src/pages/academic-years-page.tsxmodified+2 -2
@@ -255,7 +255,7 @@ function AcademicYearsContent() {
255255 </Suspense>
256256 </section>
257257
258- <SidePanel
258+ <SidePanel guardUnsaved
259259 open={panelOpen()}
260260 onOpenChange={(open) => {
261261 setPanelOpen(open);
@@ -347,7 +347,7 @@ function AcademicYearsContent() {
347347 </form>
348348 </SidePanel>
349349
350- <SidePanel
350+ <SidePanel guardUnsaved
351351 open={rolloverTarget() !== null}
352352 onOpenChange={(open) => !open && setRolloverTarget(null)}
353353 title={t("academicYears.rollover")}
src/pages/admin-user-detail-page.tsxmodified+1 -1
@@ -133,7 +133,7 @@ function AdminUserDetailContent() {
133133 </div>
134134 </section>
135135
136- <SidePanel
136+ <SidePanel guardUnsaved
137137 open={editing()}
138138 onOpenChange={setEditing}
139139 title={t("profile.edit")}
src/pages/appointments-page.tsxmodified+3 -3
@@ -369,7 +369,7 @@ function AppointmentsContent() {
369369
370370 return (
371371 <div class="space-y-5">
372- <SidePanel open={showPublish()} onOpenChange={setShowPublish} title={t("appointments.publish")} description={t("appointments.publishSubtitle")}>
372+ <SidePanel guardUnsaved open={showPublish()} onOpenChange={setShowPublish} title={t("appointments.publish")} description={t("appointments.publishSubtitle")}>
373373 <PublishSlotsForm
374374 onCancel={() => setShowPublish(false)}
375375 onSubmit={async (values) => {
@@ -387,7 +387,7 @@ function AppointmentsContent() {
387387 />
388388 </SidePanel>
389389
390- <SidePanel open={bookSlot() != null} onOpenChange={(o) => !o && setBookSlot(null)} title={t("appointments.book")} description={t("appointments.bookSubtitle")}>
390+ <SidePanel guardUnsaved open={bookSlot() != null} onOpenChange={(o) => !o && setBookSlot(null)} title={t("appointments.book")} description={t("appointments.bookSubtitle")}>
391391 <Show when={bookSlot()}>
392392 {(slot) => (
393393 <BookAppointmentForm
@@ -411,7 +411,7 @@ function AppointmentsContent() {
411411 </Show>
412412 </SidePanel>
413413
414- <SidePanel open={reschedAppt() != null} onOpenChange={(o) => !o && setReschedAppt(null)} title={t("appointments.reschedule")} description={t("appointments.rescheduleSubtitle")}>
414+ <SidePanel guardUnsaved open={reschedAppt() != null} onOpenChange={(o) => !o && setReschedAppt(null)} title={t("appointments.reschedule")} description={t("appointments.rescheduleSubtitle")}>
415415 <Show when={reschedAppt()}>
416416 {(appt) => (
417417 <RescheduleForm
src/pages/bank-question-detail-page.tsxmodified+1 -1
@@ -196,7 +196,7 @@ function BankQuestionDetailContent() {
196196 </Show>
197197 </section>
198198
199- <SidePanel open={editing()} onOpenChange={setEditing} title={t("bank.edit")} description={current().text} size="wide">
199+ <SidePanel guardUnsaved open={editing()} onOpenChange={setEditing} title={t("bank.edit")} description={current().text} size="wide">
200200 <BankQuestionForm
201201 initial={current()}
202202 courses={manageableCourses()}
src/pages/builder-school-detail-page.tsxmodified+1 -1
@@ -188,7 +188,7 @@ function BuilderSchoolDetailContent() {
188188 </Show>
189189 </Suspense>
190190
191- <SidePanel open={editOpen()} onOpenChange={setEditOpen} title={t("builder.editSchool")} description={t("builder.editSchoolHint")}>
191+ <SidePanel guardUnsaved open={editOpen()} onOpenChange={setEditOpen} title={t("builder.editSchool")} description={t("builder.editSchoolHint")}>
192192 <form class="space-y-4" onSubmit={saveEdit}>
193193 <Show when={editError()}>
194194 <Alert variant="destructive">{editError()}</Alert>
src/pages/class-detail-page.tsxmodified+2 -2
@@ -312,7 +312,7 @@ function ClassDetailContent() {
312312 </Tabs>
313313
314314 {/* Edit class */}
315- <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().name}>
315+ <SidePanel guardUnsaved open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().name}>
316316 <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void wrap(async () => { await patchClassById(id(), { name: name().trim(), grade: grade().trim() || null, year: yearId() || null, teacher_id: teacherId() || null }); setEditing(false); await refresh(refetchClass); }, "common.saved"); }}>
317317 <div class="space-y-3">
318318 <div class="space-y-1.5"><Label for="edit-class-name">{t("classGroups.className")}</Label><Input id="edit-class-name" maxlength={limits.latest?.course.max_class_name_len} value={name()} onInput={(e) => setName(e.currentTarget.value)} /></div>
@@ -333,7 +333,7 @@ function ClassDetailContent() {
333333 </SidePanel>
334334
335335 {/* Attach course */}
336- <SidePanel open={showAttachCourse()} onOpenChange={setShowAttachCourse} title={t("classGroups.attachCourse")} description={t("classGroups.attachCourseHelp")}>
336+ <SidePanel guardUnsaved open={showAttachCourse()} onOpenChange={setShowAttachCourse} title={t("classGroups.attachCourse")} description={t("classGroups.attachCourseHelp")}>
337337 <form class="space-y-3" onSubmit={(e) => { e.preventDefault(); const cid = attachCourseId(); if (!cid) return; void wrap(async () => { await postClassInstance(id(), { course_id: cid }); setAttachCourseId(""); setShowAttachCourse(false); await refresh(refetchCourses); }, "common.saved"); }}>
338338 <div class="space-y-1.5">
339339 <Label for="class-attach-course">{t("classGroups.selectCourse")}</Label>
src/pages/course-detail-page.tsxmodified+1 -1
@@ -355,7 +355,7 @@ function CourseDetailContent() {
355355 }}
356356 />
357357
358- <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().title}>
358+ <SidePanel guardUnsaved open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={c().title}>
359359 <form
360360 class="space-y-4"
361361 onSubmit={(e) => {
src/pages/courses-page.tsxmodified+1 -1
@@ -114,7 +114,7 @@ function CoursesContent() {
114114
115115 return (
116116 <div class="space-y-6">
117- <SidePanel open={canCreate() && showForm()} onOpenChange={setShowForm} title={t("common.createItem", { item: kindInSentence() })} description={t("courses.subtitle", { item: kindLabel() })}>
117+ <SidePanel guardUnsaved open={canCreate() && showForm()} onOpenChange={setShowForm} title={t("common.createItem", { item: kindInSentence() })} description={t("courses.subtitle", { item: kindLabel() })}>
118118 <form class="space-y-4" onSubmit={createCourse}>
119119 <Show when={limits.error}><ErrorAlert message={formatApiError(limits.error)} onRetry={() => void refetchLimits()} /></Show>
120120 <div class="flex items-center justify-between rounded-xl border border-border-line bg-surface-tint px-3 py-2 text-xs text-text-subtle">
src/pages/event-detail-page.tsxmodified+1 -1
@@ -217,7 +217,7 @@ function EventDetailContent() {
217217 }}
218218 />
219219
220- <SidePanel
220+ <SidePanel guardUnsaved
221221 open={editing()}
222222 onOpenChange={setEditing}
223223 title={t("common.edit")}
src/pages/events-page.tsxmodified+1 -1
@@ -160,7 +160,7 @@ function EventsContent() {
160160
161161 return (
162162 <div class="space-y-6">
163- <SidePanel open={canCreate() && showForm()} onOpenChange={setShowForm} title={t("events.create")} description={t("events.subtitle")}>
163+ <SidePanel guardUnsaved open={canCreate() && showForm()} onOpenChange={setShowForm} title={t("events.create")} description={t("events.subtitle")}>
164164 <EventForm
165165 submitLabel={t("common.create")}
166166 onCancel={() => setShowForm(false)}
src/pages/exam-detail-page.tsxmodified+2 -2
@@ -606,7 +606,7 @@ function ExamDetailContent() {
606606 }}
607607 />
608608
609- <SidePanel
609+ <SidePanel guardUnsaved
610610 open={editing()}
611611 onOpenChange={setEditing}
612612 title={t("common.edit")}
@@ -742,7 +742,7 @@ function ExamDetailContent() {
742742 </TabsContent>
743743 </Tabs>
744744
745- <SidePanel
745+ <SidePanel guardUnsaved
746746 open={gradeOpen()}
747747 onOpenChange={setGradeOpen}
748748 title={t("exams.gradeStudent")}
src/pages/homework-page.tsxmodified+1 -1
@@ -210,7 +210,7 @@ function HomeworkContent() {
210210
211211 return (
212212 <div class="space-y-6">
213- <SidePanel open={createOpen()} onOpenChange={(open) => { setCreateOpen(open); if (!open) resetForm(); }} title={t("homework.add")} description={t("homework.help")}>
213+ <SidePanel guardUnsaved open={createOpen()} onOpenChange={(open) => { setCreateOpen(open); if (!open) resetForm(); }} title={t("homework.add")} description={t("homework.help")}>
214214 <form class="space-y-4" onSubmit={(event) => void save(event)}>
215215 <Show when={error()}>
216216 <Alert variant="destructive">{error()}</Alert>
src/pages/meal-detail-page.tsxmodified+2 -2
@@ -285,10 +285,10 @@ function MealDetailContent() {
285285 <ConfirmDialog open={deleteMenuOpen()} onOpenChange={setDeleteMenuOpen} title={t("meals.deleteMenu")} variant="destructive" summary={`${current().date} · ${current().slot}`} onConfirm={() => run(async () => { await deleteMealMenuById(id()); void navigate({ to: "/meals" }); }, t("common.deleted"))} />
286286 <ConfirmDialog open={deleteDish() !== null} onOpenChange={(open) => !open && setDeleteDish(null)} title={t("meals.deleteDish")} variant="destructive" summary={deleteDish()?.name ?? ""} onConfirm={() => run(async () => { if (!deleteDish()) return; await deleteMealDishById(deleteDish()!.id); setDeleteDish(null); await refetchMenu(); }, t("common.deleted"))} />
287287
288- <SidePanel open={showMenuEdit()} onOpenChange={setShowMenuEdit} title={t("meals.editMenu")} description={`${current().date} · ${current().slot}`}>
288+ <SidePanel guardUnsaved open={showMenuEdit()} onOpenChange={setShowMenuEdit} title={t("meals.editMenu")} description={`${current().date} · ${current().slot}`}>
289289 <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void run(async () => { await patchMealMenuById(id(), { capacity: capacity() ? Number(capacity()) : null }); setShowMenuEdit(false); await refetchMenu(); }); }}><div class="space-y-1.5"><Label for="menu-capacity">{t("meals.capacity")}</Label><Input id="menu-capacity" type="number" min={0} max={limits()?.meal.max_menu_capacity} value={capacity()} onInput={(e) => setCapacity(e.currentTarget.value)} /></div><Button type="submit" disabled={pending()}>{t("common.save")}</Button></form>
290290 </SidePanel>
291- <SidePanel open={showDishForm()} onOpenChange={setShowDishForm} title={editingDish() ? t("meals.editDish") : t("meals.addDish")} description={`${current().date} · ${current().slot}`}>
291+ <SidePanel guardUnsaved open={showDishForm()} onOpenChange={setShowDishForm} title={editingDish() ? t("meals.editDish") : t("meals.addDish")} description={`${current().date} · ${current().slot}`}>
292292 <form class="space-y-4" onSubmit={(e) => { e.preventDefault(); void run(async () => { const body = { name: dishName().trim(), description: dishDescription().trim() || null, price_minor: Math.round(Number(dishPrice()) * 100), tags: dishTags() }; if (editingDish()) await patchMealDishById(editingDish()!.id, body); else await postMealDish(id(), body); setShowDishForm(false); await refetchMenu(); }); }}>
293293 <div class="space-y-1.5"><Label for="dish-name">{t("meals.dishName")}</Label><Input id="dish-name" required maxlength={limits()?.meal.max_dish_name_len} value={dishName()} onInput={(e) => setDishName(e.currentTarget.value)} /></div>
294294 <div class="space-y-1.5"><Label for="dish-description">{t("form.description")}</Label><Textarea id="dish-description" maxlength={limits()?.meal.max_dish_description_len} value={dishDescription()} onInput={(e) => setDishDescription(e.currentTarget.value)} /></div>
src/pages/payments-page.tsxmodified+3 -3
@@ -850,7 +850,7 @@ function PaymentsContent() {
850850 </SidePanel>
851851
852852 {/* ---------------- Collect payment panel ---------------- */}
853- <SidePanel
853+ <SidePanel guardUnsaved
854854 open={collectEntry() != null}
855855 onOpenChange={(open) => { if (!open) setCollectEntry(null); }}
856856 title={t("payments.collectFrom")}
@@ -889,7 +889,7 @@ function PaymentsContent() {
889889 </SidePanel>
890890
891891 {/* ---------------- Correction panel (refund / reverse) ---------------- */}
892- <SidePanel
892+ <SidePanel guardUnsaved
893893 open={lineAction() != null}
894894 onOpenChange={(open) => { if (!open) setLineAction(null); }}
895895 title={lineAction()?.kind === "refund" ? t("payments.recordRefund") : t("payments.reverse")}
@@ -917,7 +917,7 @@ function PaymentsContent() {
917917 </SidePanel>
918918
919919 {/* ---------------- Plan create / edit ---------------- */}
920- <SidePanel open={panelOpen()} onOpenChange={(open) => { setPanelOpen(open); if (!open) resetPlanForm(); }} title={editing() ? t("payments.editPlan") : t("payments.createPlan")} description={t("payments.subtitle")}>
920+ <SidePanel guardUnsaved open={panelOpen()} onOpenChange={(open) => { setPanelOpen(open); if (!open) resetPlanForm(); }} title={editing() ? t("payments.editPlan") : t("payments.createPlan")} description={t("payments.subtitle")}>
921921 <form class="space-y-4" onSubmit={savePlan}>
922922 <Show when={error()}>
923923 <Alert variant="destructive">{error()}</Alert>
src/pages/profile-page.tsxmodified+1 -1
@@ -220,7 +220,7 @@ function ProfileContent() {
220220 courseTotal={p().stats.courses}
221221 />
222222
223- <SidePanel open={editing()} onOpenChange={setEditing} title={t("profile.edit")}>
223+ <SidePanel guardUnsaved open={editing()} onOpenChange={setEditing} title={t("profile.edit")}>
224224 <Show when={auth.user()}>
225225 {(u) => (
226226 <ProfileForm
src/pages/question-bank-page.tsxmodified+1 -1
@@ -283,7 +283,7 @@ function QuestionBankContent() {
283283 </TabsContent>
284284 </Tabs>
285285
286- <SidePanel
286+ <SidePanel guardUnsaved
287287 open={createOpen() || editing() != null}
288288 onOpenChange={(open) => {
289289 if (!open) {
src/pages/staff-work-page.tsxmodified+1 -1
@@ -356,7 +356,7 @@ function StaffWorkContent() {
356356 </Show>
357357 </SidePanel>
358358
359- <SidePanel
359+ <SidePanel guardUnsaved
360360 open={editTarget() != null}
361361 onOpenChange={(open) => {
362362 if (!open) {
src/pages/terms-page.tsxmodified+1 -1
@@ -251,7 +251,7 @@ function TermsContent() {
251251 </Suspense>
252252 </section>
253253
254- <SidePanel
254+ <SidePanel guardUnsaved
255255 open={panelOpen()}
256256 onOpenChange={(open) => {
257257 setPanelOpen(open);
src/pages/whiteboards-page.tsxmodified+1 -1
@@ -254,7 +254,7 @@ function CreateBoardPanel(props: {
254254 };
255255
256256 return (
257- <SidePanel open={props.open} onOpenChange={props.onOpenChange} title={t("whiteboard.create")}>
257+ <SidePanel guardUnsaved open={props.open} onOpenChange={props.onOpenChange} title={t("whiteboard.create")}>
258258 <div class="space-y-4">
259259 <Show when={error()}>
260260 <ErrorAlert message={error()} />