forked from Tadrisino/MathApp_frontend
Remove every guest remnant: profile badge, register flow, delete-by-word
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,7 +34,7 @@ export function App() {
|
||||
/** پروفایل و پایهها را میگیرد و تصمیم میگیرد کاربر کجا برود. */
|
||||
const enter = useCallback(async () => {
|
||||
const [profile, grades] = await Promise.all([api.profile.get(), api.grades()]);
|
||||
await trackReferral(profile);
|
||||
await trackReferral();
|
||||
if (profile.name && profile.gradeId) setFlow({ kind: 'main', profile, grades });
|
||||
else setFlow({ kind: 'setup', profile, grades });
|
||||
}, []);
|
||||
@@ -124,7 +124,6 @@ export function App() {
|
||||
grades={flow.grades}
|
||||
payment={launchPayment}
|
||||
onSignedOut={() => setFlow({ kind: 'login' })}
|
||||
onRegistered={trackReferral}
|
||||
/>
|
||||
)}
|
||||
</motion.div>
|
||||
@@ -135,13 +134,10 @@ export function App() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* اگر کاربر با لینکِ دعوت آمده بود و حالا با شماره وارد شده، معرفی را ثبت کن.
|
||||
* مهمان را سرور نمیپذیرد، پس کد تا ثبتِ شماره نگه داشته میشود.
|
||||
*/
|
||||
async function trackReferral(profile: UserProfile) {
|
||||
/** اگر کاربر با لینکِ دعوت آمده بود و حالا وارد شده، معرفی را ثبت کن. */
|
||||
async function trackReferral() {
|
||||
const code = store.get(KEYS.referralCode);
|
||||
if (!code || profile.isGuest) return;
|
||||
if (!code) return;
|
||||
try {
|
||||
await api.affiliate.track(code);
|
||||
store.remove(KEYS.referralCode);
|
||||
|
||||
@@ -7,10 +7,8 @@ import { NavigatorProvider, useNav } from '@/nav/Navigator';
|
||||
import { isTab, type Route } from '@/nav/routes';
|
||||
import { BottomNav } from '@/components/BottomNav';
|
||||
import { Sheet } from '@/components/Sheet';
|
||||
import { useToast } from '@/components/Toast';
|
||||
import { LoadingState, PrimaryButton } from '@/components/ui';
|
||||
import { HomeScreen } from '@/screens/HomeScreen';
|
||||
import { LoginScreen } from '@/screens/LoginScreen';
|
||||
import type { PaymentReturn } from './launchParams';
|
||||
|
||||
/**
|
||||
@@ -54,23 +52,22 @@ interface Props {
|
||||
grades: Grade[];
|
||||
payment: PaymentReturn | null;
|
||||
onSignedOut: () => void;
|
||||
onRegistered: (profile: UserProfile) => Promise<void>;
|
||||
}
|
||||
|
||||
/** اپِ اصلی بعد از ورود: تبها، صفحهها و دادهی مشترک. */
|
||||
export function MainApp({ profile, grades, payment, onSignedOut, onRegistered }: Props) {
|
||||
export function MainApp({ profile, grades, payment, onSignedOut }: Props) {
|
||||
useEffect(preloadScreens, []);
|
||||
return (
|
||||
<AppDataProvider initialProfile={profile} grades={grades}>
|
||||
<NavigatorProvider initial={{ name: payment ? 'subscription' : 'home' }}>
|
||||
<Screens onSignedOut={onSignedOut} onRegistered={onRegistered} />
|
||||
<Screens onSignedOut={onSignedOut} />
|
||||
{payment && <PaymentResult payment={payment} />}
|
||||
</NavigatorProvider>
|
||||
</AppDataProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function Screens({ onSignedOut, onRegistered }: Pick<Props, 'onSignedOut' | 'onRegistered'>) {
|
||||
function Screens({ onSignedOut }: Pick<Props, 'onSignedOut'>) {
|
||||
const nav = useNav();
|
||||
const { route } = nav;
|
||||
const showNav = isTab(route.name) && nav.tab === route.name;
|
||||
@@ -88,7 +85,7 @@ function Screens({ onSignedOut, onRegistered }: Pick<Props, 'onSignedOut' | 'onR
|
||||
transition={{ duration: 0.18 }}
|
||||
>
|
||||
<Suspense fallback={<LoadingState />}>
|
||||
<RouteView route={route} onSignedOut={onSignedOut} onRegistered={onRegistered} />
|
||||
<RouteView route={route} onSignedOut={onSignedOut} />
|
||||
</Suspense>
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
@@ -98,7 +95,7 @@ function Screens({ onSignedOut, onRegistered }: Pick<Props, 'onSignedOut' | 'onR
|
||||
);
|
||||
}
|
||||
|
||||
function RouteView({ route, onSignedOut, onRegistered }: { route: Route } & Pick<Props, 'onSignedOut' | 'onRegistered'>) {
|
||||
function RouteView({ route, onSignedOut }: { route: Route } & Pick<Props, 'onSignedOut'>) {
|
||||
switch (route.name) {
|
||||
case 'home': return <HomeScreen />;
|
||||
case 'map': return <MapScreen />;
|
||||
@@ -116,34 +113,9 @@ function RouteView({ route, onSignedOut, onRegistered }: { route: Route } & Pick
|
||||
case 'report': return <ReportScreen />;
|
||||
case 'invoices': return <InvoicesScreen />;
|
||||
case 'invite': return <InviteScreen />;
|
||||
case 'register': return <RegisterView onRegistered={onRegistered} />;
|
||||
}
|
||||
}
|
||||
|
||||
/** مهمانی که شماره ثبت میکند؛ همان کاربر میماند و فقط پروفایل تازه میشود. */
|
||||
function RegisterView({ onRegistered }: Pick<Props, 'onRegistered'>) {
|
||||
const nav = useNav();
|
||||
const { setProfile } = useAppData();
|
||||
const toast = useToast();
|
||||
return (
|
||||
<LoginScreen
|
||||
upgrade
|
||||
onCancel={nav.back}
|
||||
onDone={async () => {
|
||||
try {
|
||||
const profile = await api.profile.get();
|
||||
setProfile(profile);
|
||||
await onRegistered(profile);
|
||||
} catch {
|
||||
/* ورود انجام شده؛ پروفایل با بازگشت به اپ تازه میشود */
|
||||
}
|
||||
toast('شمارهت ثبت شد! پیشرفتت امنه.', 'success');
|
||||
nav.back();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* نتیجهی برگشت از درگاه. فقط پاسخِ سرور تعیین میکند پرداخت موفق بوده یا نه؛ `status` در آدرس را هر
|
||||
* لینکِ ساختگی میتواند «paid» بگذارد.
|
||||
|
||||
Reference in New Issue
Block a user