give parents their own way in instead of the student setup form
A parent account has no grade, so the app sent the demo mother to the "which grade are you in?" form and she never reached the parents screen. Now an account with a name, no grade and a parent-side family link opens straight on the parents screen (with a logout button, since it has no tab bar), and the setup form offers "I'm a parent, not a student" for new ones. The header's back button only shows when there is somewhere to go back to. Found on the live site with the demo accounts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { BookOpen, Flame, Link2, Star, Trophy, UserPlus } from 'lucide-react';
|
||||
import { BookOpen, Flame, Link2, LogOut, Star, Trophy, UserPlus } from 'lucide-react';
|
||||
import { useNav } from '@/nav/Navigator';
|
||||
import { api, ApiError, type FamilyLink, type FamilyWeeklyReport } from '@/api';
|
||||
import { useAsync } from '@/lib/useAsync';
|
||||
import { useToast } from '@/components/Toast';
|
||||
@@ -12,7 +13,8 @@ import { digitsOnly, formatJalaliDate, toFa } from '@/lib/format';
|
||||
* (با همان شماره وارد شده) کد را اینجا وارد میکند. بعد از اتصال، والد
|
||||
* گزارشِ هفتگی را میبیند.
|
||||
*/
|
||||
export function FamilyScreen() {
|
||||
export function FamilyScreen({ onSignedOut }: { onSignedOut: () => void }) {
|
||||
const nav = useNav();
|
||||
// GET /family/link نمیگوید کاربر در این اتصال والد است یا فرزند؛ گزارشِ
|
||||
// هفتگی فقط برای والد جواب میدهد و برای فرزند ۴۰۴ است، پس نقش از همان درمیآید.
|
||||
const state = useAsync(async () => {
|
||||
@@ -46,6 +48,16 @@ export function FamilyScreen() {
|
||||
{!data?.role && <AcceptInvite onDone={state.reload} />}
|
||||
</>
|
||||
)}
|
||||
{/* والد بدونِ پایه نوارِ پایین را ندارد؛ خروج باید همینجا باشد. */}
|
||||
{!nav.canGoBack && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void api.auth.logout().catch(() => {}).finally(onSignedOut)}
|
||||
className="flex items-center justify-center gap-2 py-3 text-sm font-bold text-red-500"
|
||||
>
|
||||
<LogOut size={16} /> خروج از حساب
|
||||
</button>
|
||||
)}
|
||||
</ScreenBody>
|
||||
</Screen>
|
||||
);
|
||||
|
||||
@@ -12,10 +12,13 @@ export function SetupScreen({
|
||||
profile,
|
||||
grades,
|
||||
onDone,
|
||||
onParent,
|
||||
}: {
|
||||
profile: UserProfile;
|
||||
grades: Grade[];
|
||||
onDone: (profile: UserProfile) => void;
|
||||
/** «من والدم»: بدونِ پایه، مستقیم به بخشِ والدین. */
|
||||
onParent: (profile: UserProfile) => void;
|
||||
}) {
|
||||
const [name, setName] = useState(profile.name);
|
||||
const [age, setAge] = useState<number | null>(ageFromBirthYear(profile.birthYear));
|
||||
@@ -46,6 +49,20 @@ export function SetupScreen({
|
||||
}
|
||||
}
|
||||
|
||||
async function submitAsParent() {
|
||||
setTouched(true);
|
||||
if (!name.trim() || saving) return;
|
||||
setSaving(true);
|
||||
setError('');
|
||||
try {
|
||||
onParent(await api.profile.update({ name: name.trim() }));
|
||||
} catch (err) {
|
||||
setError(friendlyError(err, 'ذخیره نشد، دوباره امتحان کن'));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col bg-page">
|
||||
<header className="relative overflow-hidden rounded-b-[32px] bg-coral px-5 pb-7 pt-safe text-white">
|
||||
@@ -122,6 +139,9 @@ export function SetupScreen({
|
||||
<PrimaryButton onClick={() => void submit()} loading={saving} className="mt-auto">
|
||||
شروعِ یادگیری <ChevronLeft size={19} strokeWidth={3} />
|
||||
</PrimaryButton>
|
||||
<button type="button" onClick={() => void submitAsParent()} disabled={saving} className="-mt-2 py-2 text-sm font-bold text-muted disabled:opacity-40">
|
||||
دانشآموز نیستم؛ والدم
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user