🪪 show available student and parent record details
Browse files at this commit50dd157cbe7fdcc0f18059a12c898d3738461f36Parent: 8eccb7a- fix
- 🪪 show available student and parent record details
7 changed files +144 -41
- src/components/ui/detail-field.tsx +2 -2
- src/components/users/student-info-panel.test.tsx +94 -0
- src/components/users/student-info-panel.tsx +44 -35
- src/i18n/locales/en.ts +1 -1
- src/i18n/locales/tr.ts +1 -1
- src/pages/profile-page.tsx +1 -1
- src/pages/students-roster-page.tsx +1 -1
src/components/ui/detail-field.tsxmodified+2 -2
| @@ -1,10 +1,10 @@ | |||
| 1 | import { cn } from "@/lib/cn"; | 1 | import { cn } from "@/lib/cn"; |
| 2 | 2 | ||
| 3 | -export function DetailField(props: { label: string; value: string; mono?: boolean }) { | 3 | +export function DetailField(props: { label: string; value: string; mono?: boolean; wrap?: boolean }) { |
| 4 | return ( | 4 | return ( |
| 5 | <div class="min-w-0 space-y-1"> | 5 | <div class="min-w-0 space-y-1"> |
| 6 | <p class="text-xs font-medium text-muted-foreground">{props.label}</p> | 6 | <p class="text-xs font-medium text-muted-foreground">{props.label}</p> |
| 7 | - <p class={cn("truncate text-sm font-medium", props.mono && "mono font-normal")}>{props.value}</p> | 7 | + <p class={cn(props.wrap ? "whitespace-pre-wrap break-words" : "truncate", "text-sm font-medium", props.mono && "mono font-normal")}>{props.value}</p> |
| 8 | </div> | 8 | </div> |
| 9 | ); | 9 | ); |
| 10 | } | 10 | } |
src/components/users/student-info-panel.test.tsxadded+94 -0
| @@ -0,0 +1,94 @@ | |||
| 1 | +import { render, screen } from "@solidjs/testing-library"; | ||
| 2 | +import type { User } from "@/api/client"; | ||
| 3 | +import { StudentInfoPanel } from "@/components/users/student-info-panel"; | ||
| 4 | +import { PreferencesProvider } from "@/stores/preferences-context"; | ||
| 5 | + | ||
| 6 | +let currentUser: User; | ||
| 7 | +const getMyStudents = vi.fn(); | ||
| 8 | +const getUserById = vi.fn(); | ||
| 9 | + | ||
| 10 | +vi.mock("@/stores/auth-context", () => ({ | ||
| 11 | + useAuth: () => ({ user: () => currentUser }), | ||
| 12 | +})); | ||
| 13 | +vi.mock("@/api/parents", () => ({ getMyStudents: (...args: unknown[]) => getMyStudents(...args) })); | ||
| 14 | +vi.mock("@/api/users", () => ({ | ||
| 15 | + getUserById: (...args: unknown[]) => getUserById(...args), | ||
| 16 | + getUserSearch: vi.fn(), | ||
| 17 | +})); | ||
| 18 | +vi.mock("@/components/ui/side-panel", () => ({ | ||
| 19 | + SidePanel: (props: { children: unknown }) => <div>{props.children as never}</div>, | ||
| 20 | +})); | ||
| 21 | + | ||
| 22 | +const student: User = { | ||
| 23 | + id: "student-1", | ||
| 24 | + username: "ada", | ||
| 25 | + role: "student", | ||
| 26 | + name: "Ada", | ||
| 27 | + surname: "Yılmaz", | ||
| 28 | + display_name: "Ada Yılmaz", | ||
| 29 | + email: "ada@example.com", | ||
| 30 | + phone: "+90 555 123 45 67", | ||
| 31 | + birth_date: "2013-01-02", | ||
| 32 | + gender: "female", | ||
| 33 | + address: "Çamlık Mahallesi, İzmir", | ||
| 34 | + emergency_contact_name: "Ayşe Yılmaz", | ||
| 35 | + emergency_contact_phone: "+90 555 222 33 44", | ||
| 36 | + bio: "Satranç kulübü", | ||
| 37 | + student_number: "1234", | ||
| 38 | + theme: null, | ||
| 39 | + language: null, | ||
| 40 | + palette_color: null, | ||
| 41 | +}; | ||
| 42 | + | ||
| 43 | +function renderPanel(source: "self" | "parent") { | ||
| 44 | + return render(() => ( | ||
| 45 | + <PreferencesProvider> | ||
| 46 | + <StudentInfoPanel | ||
| 47 | + open | ||
| 48 | + onOpenChange={() => {}} | ||
| 49 | + source={source} | ||
| 50 | + student={{ id: student.id, username: student.username, displayName: student.display_name }} | ||
| 51 | + /> | ||
| 52 | + </PreferencesProvider> | ||
| 53 | + )); | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +afterEach(() => { | ||
| 57 | + getMyStudents.mockReset(); | ||
| 58 | + getUserById.mockReset(); | ||
| 59 | +}); | ||
| 60 | + | ||
| 61 | +describe("StudentInfoPanel record details", () => { | ||
| 62 | + it("shows the complete available student record, including dates and gender", async () => { | ||
| 63 | + currentUser = student; | ||
| 64 | + renderPanel("self"); | ||
| 65 | + | ||
| 66 | + expect(await screen.findByText("Çamlık Mahallesi, İzmir")).toBeTruthy(); | ||
| 67 | + for (const value of ["Ada", "Yılmaz", "January 2, 2013", "Female", "ada@example.com", "Ayşe Yılmaz", "1234"]) { | ||
| 68 | + expect(screen.getByText(value)).toBeTruthy(); | ||
| 69 | + } | ||
| 70 | + expect(getUserById).not.toHaveBeenCalled(); | ||
| 71 | + }); | ||
| 72 | + | ||
| 73 | + it("shows the linked parent's own record without inventing private student details", async () => { | ||
| 74 | + currentUser = { | ||
| 75 | + ...student, | ||
| 76 | + id: "parent-1", | ||
| 77 | + username: "ayse", | ||
| 78 | + role: "parent", | ||
| 79 | + name: "Ayşe", | ||
| 80 | + surname: "Yılmaz", | ||
| 81 | + birth_date: "1985-05-06", | ||
| 82 | + address: "Veli adresi", | ||
| 83 | + student_number: null, | ||
| 84 | + }; | ||
| 85 | + getMyStudents.mockResolvedValue({ items: [{ id: student.id, username: student.username, student_number: "1234" }] }); | ||
| 86 | + renderPanel("parent"); | ||
| 87 | + | ||
| 88 | + expect(await screen.findByText("Veli adresi")).toBeTruthy(); | ||
| 89 | + expect(screen.getByText("1234")).toBeTruthy(); | ||
| 90 | + expect(screen.getByText("May 6, 1985")).toBeTruthy(); | ||
| 91 | + expect(screen.queryByText("January 2, 2013")).toBeNull(); | ||
| 92 | + expect(getUserById).not.toHaveBeenCalled(); | ||
| 93 | + }); | ||
| 94 | +}); | ||
src/components/users/student-info-panel.tsxmodified+44 -35
| @@ -8,6 +8,7 @@ import { EmptyInline } from "@/components/ui/empty-inline"; | |||
| 8 | import { ErrorAlert } from "@/components/ui/error-alert"; | 8 | import { ErrorAlert } from "@/components/ui/error-alert"; |
| 9 | import { PageSpinner } from "@/components/ui/page-spinner"; | 9 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 10 | import { SidePanel } from "@/components/ui/side-panel"; | 10 | import { SidePanel } from "@/components/ui/side-panel"; |
| 11 | +import { genderLabel } from "@/lib/gender"; | ||
| 11 | import type { StudentInfoSource } from "@/lib/student-info-access"; | 12 | import type { StudentInfoSource } from "@/lib/student-info-access"; |
| 12 | import { useAuth } from "@/stores/auth-context"; | 13 | import { useAuth } from "@/stores/auth-context"; |
| 13 | import { usePreferences, useT } from "@/stores/preferences-context"; | 14 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| @@ -17,7 +18,7 @@ type Section = { title: string; hint?: string; fields: Field[] }; | |||
| 17 | 18 | ||
| 18 | /** What each source can actually read; fields no endpoint fills stay out. */ | 19 | /** What each source can actually read; fields no endpoint fills stay out. */ |
| 19 | type Loaded = { | 20 | type Loaded = { |
| 20 | - student: Partial<Pick<User, "name" | "surname" | "email" | "phone" | "birth_date" | "student_number">> | null; | 21 | + student: Partial<User> | null; |
| 21 | guardian: User | null; | 22 | guardian: User | null; |
| 22 | }; | 23 | }; |
| 23 | 24 | ||
| @@ -25,17 +26,15 @@ const forbidden = (err: unknown) => err instanceof ApiError && err.status === 40 | |||
| 25 | 26 | ||
| 26 | /** | 27 | /** |
| 27 | * Record details about a student — and, for a linked parent, about the parent — | 28 | * Record details about a student — and, for a linked parent, about the parent — |
| 28 | - * that the public profile never carries (legal name, student number, contact, | 29 | + * that the public profile never carries. Each viewer only reads what the backend |
| 29 | - * birth date). Each viewer only reads what the backend already grants them; see | 30 | + * already grants them; see |
| 30 | * `studentInfoSource`. | 31 | * `studentInfoSource`. |
| 31 | */ | 32 | */ |
| 32 | export function StudentInfoPanel(props: { | 33 | export function StudentInfoPanel(props: { |
| 33 | open: boolean; | 34 | open: boolean; |
| 34 | onOpenChange: (open: boolean) => void; | 35 | onOpenChange: (open: boolean) => void; |
| 35 | source: StudentInfoSource; | 36 | source: StudentInfoSource; |
| 36 | - /** `name` is what the profile heading already shows; a legal name equal to | 37 | + student: { id: string; username: string; displayName?: string | null }; |
| 37 | - * it is not repeated here. */ | ||
| 38 | - student: { id: string; username: string; name: string }; | ||
| 39 | }) { | 38 | }) { |
| 40 | const t = useT(); | 39 | const t = useT(); |
| 41 | const prefs = usePreferences(); | 40 | const prefs = usePreferences(); |
| @@ -70,7 +69,7 @@ export function StudentInfoPanel(props: { | |||
| 70 | case "parent": { | 69 | case "parent": { |
| 71 | let ref: PersonRef | undefined; | 70 | let ref: PersonRef | undefined; |
| 72 | try { | 71 | try { |
| 73 | - ref = (await getMyStudents({ limit: 100 })).items.find((p) => p.id === props.student.id); | 72 | + ref = (await getMyStudents()).items.find((p) => p.id === props.student.id); |
| 74 | } catch (err) { | 73 | } catch (err) { |
| 75 | if (!forbidden(err)) throw err; | 74 | if (!forbidden(err)) throw err; |
| 76 | } | 75 | } |
| @@ -80,9 +79,6 @@ export function StudentInfoPanel(props: { | |||
| 80 | }, | 79 | }, |
| 81 | ); | 80 | ); |
| 82 | 81 | ||
| 83 | - const fullName = (u: { name?: string | null; surname?: string | null } | null) => | ||
| 84 | - [u?.name, u?.surname].map((s) => s?.trim()).filter(Boolean).join(" "); | ||
| 85 | - | ||
| 86 | // birth_date is a calendar date ("1990-01-02"); read it as local midnight so | 82 | // birth_date is a calendar date ("1990-01-02"); read it as local midnight so |
| 87 | // no time zone shifts it a day. | 83 | // no time zone shifts it a day. |
| 88 | const birthDate = (raw: string) => { | 84 | const birthDate = (raw: string) => { |
| @@ -93,35 +89,48 @@ export function StudentInfoPanel(props: { | |||
| 93 | ); | 89 | ); |
| 94 | }; | 90 | }; |
| 95 | 91 | ||
| 96 | - const present = (fields: { label: string; value: string | null | undefined }[]): Field[] => | 92 | + const field = (label: string, value: string | null | undefined): Field => ({ |
| 97 | - fields | 93 | + label, |
| 98 | - .map((f) => ({ label: f.label, value: f.value?.trim() ?? "" })) | 94 | + value: value?.trim() || "—", |
| 99 | - .filter((f) => f.value !== ""); | 95 | + }); |
| 96 | + | ||
| 97 | + const personalFields = (u: Partial<User>): Field[] => [ | ||
| 98 | + field(t("admin.username"), u.username), | ||
| 99 | + field(t("profile.name"), u.name), | ||
| 100 | + field(t("profile.surname"), u.surname), | ||
| 101 | + field(t("profile.displayName"), u.display_name), | ||
| 102 | + field(t("profile.birthDate"), u.birth_date ? birthDate(u.birth_date) : null), | ||
| 103 | + field(t("profile.gender"), genderLabel(u.gender ?? null, t)), | ||
| 104 | + field(t("profile.email"), u.email), | ||
| 105 | + field(t("profile.phone"), u.phone), | ||
| 106 | + field(t("profile.address"), u.address), | ||
| 107 | + field(t("profile.emergencyContactName"), u.emergency_contact_name), | ||
| 108 | + field(t("profile.emergencyContactPhone"), u.emergency_contact_phone), | ||
| 109 | + field(t("profile.bio"), u.bio), | ||
| 110 | + ]; | ||
| 100 | 111 | ||
| 101 | const sections = (d: Loaded): Section[] => { | 112 | const sections = (d: Loaded): Section[] => { |
| 102 | const out: Section[] = []; | 113 | const out: Section[] = []; |
| 103 | const s = d.student; | 114 | const s = d.student; |
| 104 | - if (s) { | 115 | + if (s) out.push({ |
| 105 | - const fields = present([ | 116 | + title: t("profile.studentInfoStudent"), |
| 106 | - { label: t("profile.fullName"), value: fullName(s) === props.student.name ? null : fullName(s) }, | 117 | + fields: props.source === "self" || props.source === "admin" |
| 107 | - { label: t("roster.studentNumber"), value: s.student_number }, | 118 | + ? [ |
| 108 | - { label: t("profile.birthDate"), value: s.birth_date ? birthDate(s.birth_date) : null }, | 119 | + ...personalFields(s), |
| 109 | - { label: t("profile.email"), value: s.email }, | 120 | + field(t("roster.studentNumber"), s.student_number), |
| 110 | - { label: t("profile.phone"), value: s.phone }, | 121 | + ] |
| 111 | - ]); | 122 | + : [ |
| 112 | - if (fields.length) out.push({ title: t("profile.studentInfoStudent"), fields }); | 123 | + field(t("profile.displayName"), props.student.displayName), |
| 113 | - } | 124 | + field(t("admin.username"), props.student.username), |
| 125 | + field(t("roster.studentNumber"), s.student_number), | ||
| 126 | + ], | ||
| 127 | + }); | ||
| 114 | const g = d.guardian; | 128 | const g = d.guardian; |
| 115 | - if (g) { | 129 | + if (g) out.push({ |
| 116 | - const fields = present([ | 130 | + title: t("profile.studentInfoGuardian"), |
| 117 | - { label: t("profile.fullName"), value: fullName(g) || g.display_name }, | 131 | + hint: t("profile.studentInfoGuardianHint"), |
| 118 | - { label: t("profile.email"), value: g.email }, | 132 | + fields: personalFields(g), |
| 119 | - { label: t("profile.phone"), value: g.phone }, | 133 | + }); |
| 120 | - ]); | ||
| 121 | - if (fields.length) { | ||
| 122 | - out.push({ title: t("profile.studentInfoGuardian"), hint: t("profile.studentInfoGuardianHint"), fields }); | ||
| 123 | - } | ||
| 124 | - } | ||
| 125 | return out; | 134 | return out; |
| 126 | }; | 135 | }; |
| 127 | 136 | ||
| @@ -160,7 +169,7 @@ export function StudentInfoPanel(props: { | |||
| 160 | </div> | 169 | </div> |
| 161 | <div class="grid gap-4 rounded-lg border p-4 sm:grid-cols-2"> | 170 | <div class="grid gap-4 rounded-lg border p-4 sm:grid-cols-2"> |
| 162 | <For each={section.fields}> | 171 | <For each={section.fields}> |
| 163 | - {(f) => <DetailField label={f.label} value={f.value} />} | 172 | + {(f) => <DetailField label={f.label} value={f.value} wrap />} |
| 164 | </For> | 173 | </For> |
| 165 | </div> | 174 | </div> |
| 166 | </section> | 175 | </section> |
src/i18n/locales/en.tsmodified+1 -1
| @@ -1955,7 +1955,7 @@ export const en: Dict = { | |||
| 1955 | "profile.birthDate": "Birth date", | 1955 | "profile.birthDate": "Birth date", |
| 1956 | "profile.fullName": "Full name", | 1956 | "profile.fullName": "Full name", |
| 1957 | "profile.studentInfo": "Student info", | 1957 | "profile.studentInfo": "Student info", |
| 1958 | - "profile.studentInfoHint": "Record details the profile does not show.", | 1958 | + "profile.studentInfoHint": "Student and parent record details available to you.", |
| 1959 | "profile.studentInfoStudent": "Student", | 1959 | "profile.studentInfoStudent": "Student", |
| 1960 | "profile.studentInfoGuardian": "Parent", | 1960 | "profile.studentInfoGuardian": "Parent", |
| 1961 | "profile.studentInfoGuardianHint": "Your details as the school has them.", | 1961 | "profile.studentInfoGuardianHint": "Your details as the school has them.", |
src/i18n/locales/tr.tsmodified+1 -1
| @@ -1951,7 +1951,7 @@ export const tr: Dict = { | |||
| 1951 | "profile.birthDate": "Doğum tarihi", | 1951 | "profile.birthDate": "Doğum tarihi", |
| 1952 | "profile.fullName": "Ad soyad", | 1952 | "profile.fullName": "Ad soyad", |
| 1953 | "profile.studentInfo": "Öğrenci bilgileri", | 1953 | "profile.studentInfo": "Öğrenci bilgileri", |
| 1954 | - "profile.studentInfoHint": "Profilde yer almayan kayıt bilgileri.", | 1954 | + "profile.studentInfoHint": "Erişebildiğiniz öğrenci ve veli kayıt bilgileri.", |
| 1955 | "profile.studentInfoStudent": "Öğrenci", | 1955 | "profile.studentInfoStudent": "Öğrenci", |
| 1956 | "profile.studentInfoGuardian": "Veli", | 1956 | "profile.studentInfoGuardian": "Veli", |
| 1957 | "profile.studentInfoGuardianHint": "Okulun kayıtlarındaki sizin bilgileriniz.", | 1957 | "profile.studentInfoGuardianHint": "Okulun kayıtlarındaki sizin bilgileriniz.", |
src/pages/profile-page.tsxmodified+1 -1
| @@ -260,7 +260,7 @@ function ProfileContent() { | |||
| 260 | open={infoOpen()} | 260 | open={infoOpen()} |
| 261 | onOpenChange={setInfoOpen} | 261 | onOpenChange={setInfoOpen} |
| 262 | source={source()} | 262 | source={source()} |
| 263 | - student={{ id: p().id, username: p().username, name: name(p()) }} | 263 | + student={{ id: p().id, username: p().username, displayName: p().display_name }} |
| 264 | /> | 264 | /> |
| 265 | )} | 265 | )} |
| 266 | </Show> | 266 | </Show> |
src/pages/students-roster-page.tsxmodified+1 -1
| @@ -188,7 +188,7 @@ function StudentsRosterContent() { | |||
| 188 | open | 188 | open |
| 189 | onOpenChange={(open) => { if (!open) setInfoTarget(null); }} | 189 | onOpenChange={(open) => { if (!open) setInfoTarget(null); }} |
| 190 | source={source()} | 190 | source={source()} |
| 191 | - student={{ id: person.id, username: person.username, name: person.display_name || person.username }} | 191 | + student={{ id: person.id, username: person.username, displayName: person.display_name }} |
| 192 | /> | 192 | /> |
| 193 | )} | 193 | )} |
| 194 | </Show> | 194 | </Show> |