diff --git a/apps/web/app/t/[tenantSlug]/(workspace)/lessons/[lessonId]/edit/tenant-lesson-edit-page.tsx b/apps/web/app/t/[tenantSlug]/(workspace)/lessons/[lessonId]/edit/tenant-lesson-edit-page.tsx index fe288d9..0017ddc 100644 --- a/apps/web/app/t/[tenantSlug]/(workspace)/lessons/[lessonId]/edit/tenant-lesson-edit-page.tsx +++ b/apps/web/app/t/[tenantSlug]/(workspace)/lessons/[lessonId]/edit/tenant-lesson-edit-page.tsx @@ -3,11 +3,20 @@ import type { components } from "@studiqo/api-client/generated"; import { zodResolver } from "@/lib/zod-resolver"; import { isStudiqoApiError } from "@studiqo/api-client/errors"; -import Link from "next/link"; import { useParams, useRouter } from "next/navigation"; import { useEffect, useState } from "react"; -import { useForm } from "react-hook-form"; +import { Controller, useForm } from "react-hook-form"; +import { Alert, AlertDescription } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; import { useLessonDetailQuery, useUpdateLessonMutation } from "@/lib/api/lessons-query"; import { useOrganizationMembersQuery } from "@/lib/api/organization-members-query"; import { useSubjectsListQuery } from "@/lib/api/subjects-query"; @@ -25,6 +34,13 @@ import { type UpdateLessonForm, } from "@/lib/validation/lesson-forms"; +import { + LessonField, + LessonFormCard, + LessonFormPage, + LessonTextarea, +} from "../../_components/lesson-form"; + type Lesson = components["schemas"]["Lesson"]; type UpdateLessonBody = components["schemas"]["UpdateLessonRequest"]; @@ -107,75 +123,81 @@ export function TenantLessonEditPage() { }, [lesson, form]); const base = `/t/${tenantSlug}/lessons`; + const detailUrl = `${base}/${lessonId}`; if (!canManage) { return ( -
-

Edit lesson

-

- Only organization admins can edit lessons. -

-

- Back to lesson -

-
+ + + + Only organization admins can edit lessons. + + + ); } if (orgsLoading || !organizationId) { return ( -
-

- ← Lesson -

-

Loading…

-
+ +

Loading…

+
); } if (lessonQ.isLoading) { return ( -
-

- ← Lesson -

-

Loading lesson…

-
+ +

Loading lesson…

+
); } if (lessonQ.error || !lesson) { return ( -
-

- ← Lessons -

-

- {lessonQ.error instanceof Error - ? lessonQ.error.message - : "Could not load lesson"} -

-
+ + + + {lessonQ.error instanceof Error + ? lessonQ.error.message + : "Could not load lesson"} + + + ); } if (lesson.status !== "scheduled") { return ( -
-

- ← Lesson -

-

Edit lesson

-

- Only scheduled lessons can be edited. This lesson is{" "} - {lesson.status}. -

-
+ + + + Only scheduled lessons can be edited. This lesson is{" "} + {lesson.status}. + + + ); } const editingLesson = lesson; const tutors = membersQ.data?.filter((m) => m.role === "tutor") ?? []; + const referenceError = subjectsQ.error ?? membersQ.error ?? null; + const loadingRefs = subjectsQ.isLoading || membersQ.isLoading; async function onSubmit(values: UpdateLessonForm) { setFormError(null); @@ -193,99 +215,156 @@ export function TenantLessonEditPage() { } } - const loadingRefs = subjectsQ.isLoading || membersQ.isLoading; + if (referenceError) { + return ( + + + + {referenceError instanceof Error + ? referenceError.message + : "Could not load lesson references"} + + + + ); + } return ( -
-

- ← Lesson -

-

Edit lesson

+ + {loadingRefs ? ( +

Loading references…

+ ) : null} - {loadingRefs ?

Loading…

: null} - -
- + + + ( + + )} + /> + - + + ( + + )} + /> + - + + + - + + + -