@@ -128,9 +141,10 @@ function PhotoAvatar({ studentId, photoPath, canEdit }: { studentId: string; pho
);
}
-// ── Profile (all single-value student fields) ────────────────────────────────
+// ── Profile ──────────────────────────────────────────────────────────────────
function ProfileTab({ studentId, canEdit }: { studentId: string; canEdit: boolean }) {
const qc = useQueryClient();
+ const [editing, setEditing] = useState(false);
const { data: s } = useQuery({
queryKey: ["student", studentId],
queryFn: async () => (await supabase.from("students").select("*").eq("id", studentId).single()).data,
@@ -151,7 +165,6 @@ function ProfileTab({ studentId, canEdit }: { studentId: string; canEdit: boolea
const keys = [
"first_name", "last_name", "dob", "gender", "grade_level", "preferred_start_date", "class_id",
"allergies", "chronic_conditions", "primary_physician", "physician_phone",
- "home_ed_eval_due", "previous_schools", "special_needs", "portfolio_keeper", "disciplinary_history", "custody_agreement",
"dismissal_other", "backup_transport_plan", "interests", "other_info", "agreement_signed_by", "agreement_signed_date", "notes",
];
const payload: Record
= { dismissal_methods: dismissal, photo_release: !!c.photo_release };
@@ -161,16 +174,57 @@ function ProfileTab({ studentId, canEdit }: { studentId: string; canEdit: boolea
const { error } = await supabase.from("students").update(payload as never).eq("id", studentId);
if (error) throw error;
},
- onSuccess: () => { toast.success("Profile saved"); qc.invalidateQueries({ queryKey: ["student", studentId] }); setForm(null); },
+ onSuccess: () => { toast.success("Profile saved"); qc.invalidateQueries({ queryKey: ["student", studentId] }); setForm(null); setEditing(false); },
onError: (e: Error) => toast.error(e.message),
});
if (!c) return
;
const val = (k: string) => (c[k] as string) ?? "";
- const T = (k: string, label: string, className = "") => upd(k, e.target.value)} />;
- const D = (k: string, label: string) => upd(k, e.target.value)} />;
- const A = (k: string, label: string, rows = 2) => ;
+ const className = (classes ?? []).find((cl) => cl.id === c.class_id)?.name ?? null;
+ // ── View mode ──
+ if (!editing) {
+ return (
+
+
+
+
+
+
+ {dismissal.includes("other") && }
+
+
+
+
+
+ );
+ }
+
+ // ── Edit mode ──
+ const T = (k: string, label: string) => upd(k, e.target.value)} />;
+ const D = (k: string, label: string) => upd(k, e.target.value)} />;
+ const A = (k: string, label: string, rows = 2) => ;
return (
@@ -179,7 +233,7 @@ function ProfileTab({ studentId, canEdit }: { studentId: string; canEdit: boolea
{T("last_name", "Last name")}
{D("dob", "Date of birth")}
-
-
{A("allergies", "Allergies (blank if none)")}
{A("chronic_conditions", "Chronic conditions (blank if none)")}
{T("primary_physician", "Primary physician")}{T("physician_phone", "Physician phone")}
-
{DISMISSAL_OPTIONS.map((o) => (
))}
{dismissal.includes("other") && T("dismissal_other", "Other (describe)")}
{A("backup_transport_plan", "Backup transportation plan")}
-
{A("interests", "Interests / hobbies / activities")}
{A("other_info", "Anything else we should know")}
- upd("photo_release", v)} />
+ upd("photo_release", v)} />
{A("notes", "Internal notes (staff only)")}
-
{T("agreement_signed_by", "Signed by")}{D("agreement_signed_date", "Date")}
-
- {canEdit && }
+
+
+
+
);
}
-// ── Family & pickup (guardians, emergency contacts, authorized pickups) ───────
+// ── Family & pickup ──────────────────────────────────────────────────────────
type GuardianRow = { id: string; is_primary: boolean; full_name: string; relationship: string | null; phone: string | null; address: string | null; city: string | null; state: string | null; zip: string | null; email: string | null; employer: string | null };
function FamilyTab({ studentId, canEdit }: { studentId: string; canEdit: boolean }) {
const qc = useQueryClient();
+ const [editing, setEditing] = useState(false);
const { data: guardians } = useQuery({
queryKey: ["guardians", studentId],
queryFn: async () => (await supabase.from("student_guardians").select("*").eq("student_id", studentId).order("is_primary", { ascending: false })).data ?? [],
});
-
const addGuardian = useMutation({
mutationFn: async (isPrimary: boolean) => {
const { error } = await supabase.from("student_guardians").insert({ student_id: studentId, is_primary: isPrimary, full_name: "New guardian" });
@@ -250,30 +302,26 @@ function FamilyTab({ studentId, canEdit }: { studentId: string; canEdit: boolean
return (
);
}
-function GuardianCard({ g, studentId, canEdit }: { g: GuardianRow; studentId: string; canEdit: boolean }) {
+function GuardianCard({ g, studentId, editing }: { g: GuardianRow; studentId: string; editing: boolean }) {
const qc = useQueryClient();
const [row, setRow] = useState