feat(market): complete entering and onboarding
Login, registration steps 1–4 and step 5 now follow the design (S6, R2-Register, R2-CompleteProfile). - Login: hourly code limit and blocks open the code step with their wait; wrong-code message no longer replaced while retyping; suspended screen on its own route with the admin's reason; «log in to subscribe» variant. - Registration: focus on the first card or empty upload box; typed number kept; «تمدید زمان» renews the token; live username check with ✓; leave prompt for in-app links; creator ID accepts PDF and maps server field errors. - Step 5: square photo crop, stricter link rules, done screen on its own route; the session's `needsProfile` keeps unfinished creators out of publishing and pricing (OnboardingGuard) and sends them back to step 5 at login. - Every auth and onboarding route has its own loading skeleton matching its frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ed6ddc05b1
commit
cb0891c77c
|
|
@ -0,0 +1,13 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Login, the number, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -3,8 +3,8 @@ import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
|||
import { LoginStep } from '@lumina/market/app/screens/(auth)/auth/login/organisms/login-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AuthTemplate } from '../../../templates/auth-template';
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return { title: i18n.t('auth:login.meta-title'), robots: { index: false } };
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** The suspended screen, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<SkeletonPreset preset="state" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { LoginSuspendedStep } from '@lumina/market/app/screens/(auth)/auth/login/suspended/organisms/login-suspended-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('auth:suspended.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* After a valid code for a suspended account (S6 3.1): the 560 card with the support button
|
||||
* inside it. The frame renders on the server; the screen only in the browser (0013).
|
||||
*/
|
||||
export default function LoginSuspendedPage() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset preset="state" label={i18n.t('auth:loading')} />
|
||||
}
|
||||
>
|
||||
<LoginSuspendedStep
|
||||
size="md"
|
||||
supportPlacement="popover"
|
||||
layout="desktop"
|
||||
/>
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Login, the code, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 1, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
delayed
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -3,8 +3,8 @@ import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
|||
import { RegisterTypeStep } from '@lumina/market/app/screens/(auth)/auth/register/organisms/register-type-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AuthTemplate } from '../../../templates/auth-template';
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 4, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={3}
|
||||
delayed
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 2, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
delayed
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 3, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
delayed
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../i18n';
|
||||
import { AuthTemplate } from '../templates/auth-template';
|
||||
|
||||
/** Login and registration, before their frame arrives: the header, the card and a form step's shape. */
|
||||
export default function AuthLoading() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// Locked until a creator finishes registration step 5 (0016); the guard renders the page as is.
|
||||
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// Locked until a creator finishes registration step 5 (0016); the guard renders the page as is.
|
||||
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../i18n';
|
||||
import { AuthTemplate } from '../templates/auth-template';
|
||||
|
||||
/** Registration's last steps, before their frame arrives: the header, the card and a form step's shape. */
|
||||
export default function OnboardingLoading() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import { CreatorProfileStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/organisms/creator-profile-step';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 5 for a creator, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate framed={false}>
|
||||
<CreatorProfileStepSkeleton
|
||||
layout="desktop"
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -6,8 +6,8 @@ import {
|
|||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AuthTemplate } from '../../../templates/auth-template';
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { CreatorProfileDoneStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/done/organisms/creator-profile-done-step';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** The creator's end of registration, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<CreatorProfileDoneStepSkeleton label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import {
|
||||
CreatorProfileDoneStep,
|
||||
CreatorProfileDoneStepSkeleton,
|
||||
} from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/done/organisms/creator-profile-done-step';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('auth:register.profile.done.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The end of registration for a creator (R2-CompleteProfile 3.3), in the 560 card. The frame renders on the server; the step only in the browser, for the signed-in creator,
|
||||
* behind the same-size skeleton.
|
||||
*/
|
||||
export default function CreatorProfileDonePage() {
|
||||
const skeleton = (
|
||||
<CreatorProfileDoneStepSkeleton label={i18n.t('auth:loading')} />
|
||||
);
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<AuthGuard role="creator" fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<CreatorProfileDoneStep size="md" supportPlacement="popover" />
|
||||
</Suspense>
|
||||
</AuthGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { InvestorProfileStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AuthTemplate } from '../../../templates/auth-template';
|
||||
|
||||
/** Registration step 5 for an investor, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<InvestorProfileStepSkeleton label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { InvestorProfileStep } from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
|
||||
import {
|
||||
InvestorProfileStep,
|
||||
InvestorProfileStepSkeleton,
|
||||
} from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
|
@ -23,11 +25,7 @@ export default function InvestorProfilePage() {
|
|||
<AuthGuard
|
||||
role="investor"
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
<InvestorProfileStepSkeleton label={i18n.t('auth:loading')} />
|
||||
}
|
||||
>
|
||||
<InvestorProfileStep size="md" supportPlacement="popover" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Login, the number, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@ import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
|||
import { LoginStep } from '@lumina/market/app/screens/(auth)/auth/login/organisms/login-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AuthTopBar } from '../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../templates/auth-template';
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return { title: i18n.t('auth:login.meta-title'), robots: { index: false } };
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** The suspended screen, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<SkeletonPreset preset="state" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { LoginSuspendedStep } from '@lumina/market/app/screens/(auth)/auth/login/suspended/organisms/login-suspended-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('auth:suspended.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* After a valid code for a suspended account (S6 1.11, 2.1): the brand header with support and
|
||||
* no way back into login. The frame renders on the server; the screen only in the browser (0013).
|
||||
*/
|
||||
export default function LoginSuspendedPage() {
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset preset="state" label={i18n.t('auth:loading')} />
|
||||
}
|
||||
>
|
||||
<LoginSuspendedStep
|
||||
size="lg"
|
||||
supportPlacement="bottom"
|
||||
layout="mobile"
|
||||
/>
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Login, the code, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar title={i18n.t('auth:login.header')} back={ROUTES.login} />
|
||||
}
|
||||
>
|
||||
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { ROUTES, withReturnPath } from '@lumina/market/app/navigation';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import { LoginVerifyStep } from '@lumina/market/app/screens/(auth)/auth/login/verify/organisms/login-verify-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
|
|
@ -15,24 +15,12 @@ export function generateMetadata(): Metadata {
|
|||
};
|
||||
}
|
||||
|
||||
type LoginVerifyPageProps = {
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
||||
};
|
||||
|
||||
/** Login, the code. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default async function LoginVerifyPage({
|
||||
searchParams,
|
||||
}: LoginVerifyPageProps) {
|
||||
const { redirect } = await searchParams;
|
||||
const backHref = withReturnPath(
|
||||
ROUTES.login,
|
||||
typeof redirect === 'string' ? redirect : null,
|
||||
);
|
||||
|
||||
export default function LoginVerifyPage() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar title={i18n.t('auth:login.header')} backHref={backHref} />
|
||||
<AuthTopBar title={i18n.t('auth:login.header')} back={ROUTES.login} />
|
||||
}
|
||||
>
|
||||
<GuestGuard
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 1, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
delayed
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -3,9 +3,9 @@ import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
|||
import { RegisterTypeStep } from '@lumina/market/app/screens/(auth)/auth/register/organisms/register-type-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AuthTopBar } from '../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../templates/auth-template';
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 4, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
|
||||
>
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={3}
|
||||
delayed
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 2, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar
|
||||
title={i18n.t('auth:register.header')}
|
||||
back={ROUTES.register.type}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
delayed
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { ROUTES, withReturnPath } from '@lumina/market/app/navigation';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import { RegisterPhoneStep } from '@lumina/market/app/screens/(auth)/auth/register/phone/organisms/register-phone-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
|
|
@ -15,26 +15,14 @@ export function generateMetadata(): Metadata {
|
|||
};
|
||||
}
|
||||
|
||||
type RegisterPhonePageProps = {
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
||||
};
|
||||
|
||||
/** Registration step 2, the number. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default async function RegisterPhonePage({
|
||||
searchParams,
|
||||
}: RegisterPhonePageProps) {
|
||||
const { redirect } = await searchParams;
|
||||
const backHref = withReturnPath(
|
||||
ROUTES.register.type,
|
||||
typeof redirect === 'string' ? redirect : null,
|
||||
);
|
||||
|
||||
export default function RegisterPhonePage() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar
|
||||
title={i18n.t('auth:register.header')}
|
||||
backHref={backHref}
|
||||
back={ROUTES.register.type}
|
||||
/>
|
||||
}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 3, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar
|
||||
title={i18n.t('auth:register.header')}
|
||||
back={ROUTES.register.phone}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
delayed
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { ROUTES, withReturnPath } from '@lumina/market/app/navigation';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import { RegisterVerifyStep } from '@lumina/market/app/screens/(auth)/auth/register/verify/organisms/register-verify-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
|
|
@ -15,26 +15,14 @@ export function generateMetadata(): Metadata {
|
|||
};
|
||||
}
|
||||
|
||||
type RegisterVerifyPageProps = {
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
||||
};
|
||||
|
||||
/** Registration step 3, the code. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default async function RegisterVerifyPage({
|
||||
searchParams,
|
||||
}: RegisterVerifyPageProps) {
|
||||
const { redirect } = await searchParams;
|
||||
const backHref = withReturnPath(
|
||||
ROUTES.register.phone,
|
||||
typeof redirect === 'string' ? redirect : null,
|
||||
);
|
||||
|
||||
export default function RegisterVerifyPage() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar
|
||||
title={i18n.t('auth:register.header')}
|
||||
backHref={backHref}
|
||||
back={ROUTES.register.phone}
|
||||
/>
|
||||
}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../i18n';
|
||||
import { AuthTopBar } from '../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../templates/auth-template';
|
||||
|
||||
/** Login and registration, before their frame arrives: the top bar and a form step's shape. */
|
||||
export default function AuthLoading() {
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// Locked until a creator finishes registration step 5 (0016); the guard renders the page as is.
|
||||
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// Locked until a creator finishes registration step 5 (0016); the guard renders the page as is.
|
||||
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../i18n';
|
||||
import { AuthTopBar } from '../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../templates/auth-template';
|
||||
|
||||
/** Registration's last steps, before their frame arrives: the top bar and a form step's shape. */
|
||||
export default function OnboardingLoading() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
|
||||
>
|
||||
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import { CreatorProfileStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/organisms/creator-profile-step';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** Registration step 5 for a creator, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
|
||||
>
|
||||
<CreatorProfileStepSkeleton
|
||||
layout="mobile"
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -6,9 +6,9 @@ import {
|
|||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AuthTopBar } from '../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../templates/auth-template';
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { CreatorProfileDoneStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/done/organisms/creator-profile-done-step';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
/** The creator's end of registration, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<CreatorProfileDoneStepSkeleton label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import {
|
||||
CreatorProfileDoneStep,
|
||||
CreatorProfileDoneStepSkeleton,
|
||||
} from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/done/organisms/creator-profile-done-step';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../../templates/auth-template';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('auth:register.profile.done.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The end of registration for a creator (R2-CompleteProfile 1.8): the brand header, as
|
||||
* registration is over. The frame renders on the server; the step only in the browser, for the signed-in creator,
|
||||
* behind the same-size skeleton.
|
||||
*/
|
||||
export default function CreatorProfileDonePage() {
|
||||
const skeleton = (
|
||||
<CreatorProfileDoneStepSkeleton label={i18n.t('auth:loading')} />
|
||||
);
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<AuthGuard role="creator" fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<CreatorProfileDoneStep size="lg" supportPlacement="bottom" />
|
||||
</Suspense>
|
||||
</AuthGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import { InvestorProfileStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AuthTopBar } from '../../../organisms/auth-top-bar';
|
||||
import { AuthTemplate } from '../../../templates/auth-template';
|
||||
|
||||
/** Registration step 5 for an investor, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
|
||||
>
|
||||
<InvestorProfileStepSkeleton label={i18n.t('auth:loading')} />
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { InvestorProfileStep } from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
|
||||
import {
|
||||
InvestorProfileStep,
|
||||
InvestorProfileStepSkeleton,
|
||||
} from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
|
@ -26,11 +28,7 @@ export default function InvestorProfilePage() {
|
|||
<AuthGuard
|
||||
role="investor"
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
<InvestorProfileStepSkeleton label={i18n.t('auth:loading')} />
|
||||
}
|
||||
>
|
||||
<InvestorProfileStep size="lg" supportPlacement="bottom" />
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
|
|
@ -6,6 +5,7 @@ import { SupportEntry } from '@lumina/market/app/screens/organisms/support-entry
|
|||
import NextLink from 'next/link';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import { BackButton } from './components/BackButton';
|
||||
import type { AuthTopBarProps } from './types';
|
||||
|
||||
/**
|
||||
|
|
@ -13,7 +13,7 @@ import type { AuthTopBarProps } from './types';
|
|||
* support on a pushed step; only the name on a step with no way back (registration step 4).
|
||||
* Back keeps what was typed: the number lives in the flow store.
|
||||
*/
|
||||
export function AuthTopBar({ title, backHref }: AuthTopBarProps) {
|
||||
export function AuthTopBar({ title, back }: AuthTopBarProps) {
|
||||
return (
|
||||
<FlexBox
|
||||
tag="header"
|
||||
|
|
@ -21,19 +21,12 @@ export function AuthTopBar({ title, backHref }: AuthTopBarProps) {
|
|||
gap="gap-1"
|
||||
className="sticky top-0 z-sticky min-h-14 border-b border-border-subtle bg-surface px-2"
|
||||
>
|
||||
{backHref && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="chevron-right"
|
||||
label={i18n.t('auth:header.back')}
|
||||
href={backHref}
|
||||
/>
|
||||
)}
|
||||
{back && <BackButton step={back} label={i18n.t('auth:header.back')} />}
|
||||
{title ? (
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="heading-sm"
|
||||
className={backHref ? 'flex-1' : 'flex-1 px-2'}
|
||||
className={back ? 'flex-1' : 'flex-1 px-2'}
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { withReturnPath } from '@lumina/market/app/navigation';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import type { BackButtonProps } from '../types';
|
||||
|
||||
/**
|
||||
* Back to the previous step, keeping `?redirect=` from the address bar, so a page and its loading
|
||||
* frame lead to the same place and the person still returns to the page that asked for login.
|
||||
*/
|
||||
export function BackButton({ step, label }: BackButtonProps) {
|
||||
const redirect = useSearchParams().get('redirect');
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="chevron-right"
|
||||
label={label}
|
||||
href={withReturnPath(step, redirect)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
export type AuthTopBarProps = {
|
||||
/** A pushed step's name, such as «ورود». Without it the bar shows the brand. */
|
||||
title?: string;
|
||||
/** The previous step, behind the back button. */
|
||||
backHref?: string;
|
||||
/** The previous step's path, behind the back button; `?redirect=` is kept from the address. */
|
||||
back?: string;
|
||||
};
|
||||
|
||||
export type BackButtonProps = {
|
||||
step: string;
|
||||
label: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,18 +3,20 @@
|
|||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { useViewerStatus } from '../../../stores/auth';
|
||||
import { safeReturnPath } from '../../navigation';
|
||||
import { useNeedsProfile, useViewerStatus } from '../../../stores/auth';
|
||||
import { ROUTES, safeReturnPath, withReturnPath } from '../../navigation';
|
||||
import type { GuestGuardProps } from './types';
|
||||
|
||||
/**
|
||||
* Wraps login and registration, which render only in the browser. A visitor who arrives signed in
|
||||
* goes on to `?redirect=` (a path on this site only) or home; a guest sees the page. The skeleton
|
||||
* goes on to `?redirect=` (a path on this site only) or home, or to registration step 5 when they
|
||||
* are a creator who has not finished it; a guest sees the page. The skeleton
|
||||
* covers the moment before the viewer is known. A guest who signs in on the page keeps it: the
|
||||
* page shows its progress and sends them on itself.
|
||||
*/
|
||||
export function GuestGuard({ fallback, children }: GuestGuardProps) {
|
||||
const status = useViewerStatus();
|
||||
const needsProfile = useNeedsProfile();
|
||||
const router = useRouter();
|
||||
const [wasGuest, setWasGuest] = useState(false);
|
||||
// Remembered during render, so the render that turns member already knows.
|
||||
|
|
@ -25,8 +27,12 @@ export function GuestGuard({ fallback, children }: GuestGuardProps) {
|
|||
const redirect = new URLSearchParams(window.location.search).get(
|
||||
'redirect',
|
||||
);
|
||||
router.replace(safeReturnPath(redirect));
|
||||
}, [status, wasGuest, router]);
|
||||
router.replace(
|
||||
needsProfile
|
||||
? withReturnPath(ROUTES.onboarding.creatorProfile, redirect)
|
||||
: safeReturnPath(redirect),
|
||||
);
|
||||
}, [status, needsProfile, wasGuest, router]);
|
||||
|
||||
const showsPage = status === 'guest' || (status === 'member' && wasGuest);
|
||||
return showsPage ? children : fallback;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useNeedsProfile, useViewerStatus } from '../../../stores/auth';
|
||||
import { ROUTES, withReturnPath } from '../../navigation';
|
||||
import type { OnboardingGuardProps } from './types';
|
||||
|
||||
/**
|
||||
* Keeps a creator who has not finished registration step 5 away from what stays locked until
|
||||
* then: publishing and prices (R2-CompleteProfile 4.2). It changes nothing in the render, so the
|
||||
* server HTML stays the same for every visitor; once the browser knows the viewer, such a creator
|
||||
* goes to step 5, which returns here when done. The layouts of those routes render it
|
||||
* (`compose`, `dashboard/pricing`); everything else, such as the terms, stays open.
|
||||
*/
|
||||
export function OnboardingGuard({ children }: OnboardingGuardProps) {
|
||||
const status = useViewerStatus();
|
||||
const needsProfile = useNeedsProfile();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (status !== 'member' || !needsProfile) return;
|
||||
const { pathname, search } = window.location;
|
||||
router.replace(
|
||||
withReturnPath(ROUTES.onboarding.creatorProfile, `${pathname}${search}`),
|
||||
);
|
||||
}, [status, needsProfile, router]);
|
||||
|
||||
return children;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { OnboardingGuard } from './OnboardingGuard';
|
||||
export type { OnboardingGuardProps } from './types';
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
export type OnboardingGuardProps = { children: ReactNode };
|
||||
|
|
@ -1,2 +1,5 @@
|
|||
/** The public channel URL prefix; next.config rewrites `/@username` onto `channels/[username]`. */
|
||||
export const CHANNEL_PREFIX = '/@';
|
||||
|
||||
/** Login's query parameter naming the channel a guest wants to subscribe to. */
|
||||
export const SUBSCRIBE_PARAM = 'subscribe';
|
||||
|
|
|
|||
|
|
@ -1,23 +1,44 @@
|
|||
import { useSearchParams } from 'next/navigation';
|
||||
import { useMemo } from 'react';
|
||||
import * as v from 'valibot';
|
||||
|
||||
import type { SignedInViewer } from '../../../features/auth';
|
||||
import { usernameSchema } from '../../../shared/validations';
|
||||
import { SUBSCRIBE_PARAM } from '../constants';
|
||||
import { ROUTES, withReturnPath } from '../navigation';
|
||||
import { safeReturnPath } from '../return-path';
|
||||
import type { AuthRoutes } from '../types';
|
||||
|
||||
/**
|
||||
* The channel named by `?subscribe=`, as the API stores it, only when the person returns to that
|
||||
* same channel (`?redirect=`): the notice says where they go back to, so any other pair, or a
|
||||
* name that is no username, shows the plain login.
|
||||
*/
|
||||
function toSubscribeUsername(
|
||||
subscribe: string | null,
|
||||
redirect: string | null,
|
||||
): string | null {
|
||||
const parsed = v.safeParse(usernameSchema, subscribe ?? '');
|
||||
return parsed.success && redirect === ROUTES.channel(parsed.output)
|
||||
? parsed.output
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Every login and registration step's path, each keeping `?redirect=`, and where a person lands
|
||||
* once signed in. Browser only: the auth pages render their steps in the browser.
|
||||
*/
|
||||
export function useAuthRoutes(): AuthRoutes {
|
||||
const redirect = useSearchParams().get('redirect');
|
||||
const params = useSearchParams();
|
||||
const redirect = params.get('redirect');
|
||||
const subscribe = params.get(SUBSCRIBE_PARAM);
|
||||
|
||||
return useMemo(() => {
|
||||
const step = (path: string) => withReturnPath(path, redirect);
|
||||
return {
|
||||
login: step(ROUTES.login),
|
||||
loginVerify: step(ROUTES.loginVerify),
|
||||
loginSuspended: ROUTES.loginSuspended,
|
||||
register: {
|
||||
type: step(ROUTES.register.type),
|
||||
phone: step(ROUTES.register.phone),
|
||||
|
|
@ -27,12 +48,14 @@ export function useAuthRoutes(): AuthRoutes {
|
|||
profile: {
|
||||
investor: step(ROUTES.onboarding.investorProfile),
|
||||
creator: step(ROUTES.onboarding.creatorProfile),
|
||||
creatorDone: step(ROUTES.onboarding.creatorProfileDone),
|
||||
},
|
||||
landing: ({ role, username, needsProfile }: SignedInViewer) => {
|
||||
if (needsProfile) return step(ROUTES.onboarding.creatorProfile);
|
||||
if (redirect) return safeReturnPath(redirect);
|
||||
return role === 'creator' ? ROUTES.channel(username) : ROUTES.home;
|
||||
},
|
||||
subscribeTo: toSubscribeUsername(subscribe, redirect),
|
||||
};
|
||||
}, [redirect]);
|
||||
}, [redirect, subscribe]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
export { CHANNEL_PREFIX } from './constants';
|
||||
export { useAuthRoutes } from './hooks/use-auth-routes';
|
||||
export { loginRoute, ROUTES, withReturnPath } from './navigation';
|
||||
export {
|
||||
loginRoute,
|
||||
ROUTES,
|
||||
subscribeLoginRoute,
|
||||
withReturnPath,
|
||||
} from './navigation';
|
||||
export { safeReturnPath } from './return-path';
|
||||
export type { AuthRoutes } from './types';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { CHANNEL_PREFIX } from './constants';
|
||||
import { CHANNEL_PREFIX, SUBSCRIBE_PARAM } from './constants';
|
||||
|
||||
const channel = (username: string) =>
|
||||
`${CHANNEL_PREFIX}${encodeURIComponent(username)}`;
|
||||
|
|
@ -8,6 +8,8 @@ export const ROUTES = {
|
|||
home: '/',
|
||||
login: '/auth/login',
|
||||
loginVerify: '/auth/login/verify',
|
||||
/** After a valid code for a suspended account: no session, only support. */
|
||||
loginSuspended: '/auth/login/suspended',
|
||||
register: {
|
||||
type: '/auth/register',
|
||||
phone: '/auth/register/phone',
|
||||
|
|
@ -32,8 +34,9 @@ export const ROUTES = {
|
|||
sheba: '/dashboard/finance/sheba',
|
||||
},
|
||||
onboarding: {
|
||||
creatorIdentity: '/onboarding/creator-identity',
|
||||
creatorProfile: '/onboarding/creator-profile',
|
||||
/** The end of registration for a creator: what happens next. */
|
||||
creatorProfileDone: '/onboarding/creator-profile/done',
|
||||
investorProfile: '/onboarding/investor-profile',
|
||||
},
|
||||
terms: '/terms/subscription',
|
||||
|
|
@ -44,6 +47,15 @@ export function loginRoute(returnTo?: string): string {
|
|||
return withReturnPath(ROUTES.login, returnTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Login for a guest who tapped «اشتراک» on a channel: the login page says why, and the person
|
||||
* comes back to the channel (S6 Login · to-subscribe). The channel page's «اشتراک» links here;
|
||||
* until that page is built (the channel epic), nothing does.
|
||||
*/
|
||||
export function subscribeLoginRoute(username: string): string {
|
||||
return `${loginRoute(channel(username))}&${SUBSCRIBE_PARAM}=${encodeURIComponent(username)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* An auth step's path that keeps `?redirect=`, so every step of login and registration returns
|
||||
* to the page that asked for it.
|
||||
|
|
|
|||
|
|
@ -4,13 +4,16 @@ import type { SignedInViewer } from '../../features/auth';
|
|||
export type AuthRoutes = {
|
||||
login: string;
|
||||
loginVerify: string;
|
||||
loginSuspended: string;
|
||||
register: {
|
||||
type: string;
|
||||
phone: string;
|
||||
verify: string;
|
||||
details: string;
|
||||
};
|
||||
/** Registration step 5, per account type. */
|
||||
profile: { investor: string; creator: string };
|
||||
/** Registration step 5, per account type, and the creator's end of registration. */
|
||||
profile: { investor: string; creator: string; creatorDone: string };
|
||||
landing: (viewer: SignedInViewer) => string;
|
||||
/** The channel's username when a guest came to log in from «اشتراک», else `null`. */
|
||||
subscribeTo: string | null;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ import type { LoginStepProps } from './types';
|
|||
|
||||
/**
|
||||
* Login step 1: the mobile number and «دریافت کد» right under it, the way to registration, and
|
||||
* support. A number with no account gets the way to register with it under the field.
|
||||
* support. A number with no account gets the way to register with it under the field. A guest
|
||||
* who came from «اشتراک» reads why, and which channel they return to (S6 Login · to-subscribe).
|
||||
*/
|
||||
export function LoginStep({ size, supportPlacement }: LoginStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
|
|
@ -28,26 +29,31 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
|
|||
submit,
|
||||
isSubmitting,
|
||||
formError,
|
||||
clearError,
|
||||
isUnknownPhone,
|
||||
registerHref,
|
||||
carryPhone,
|
||||
subscribe,
|
||||
} = useLoginPage({
|
||||
codeHref: routes.loginVerify,
|
||||
registerHref: routes.register.type,
|
||||
subscribeTo: routes.subscribeTo,
|
||||
});
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
{/* The toast carries the details; the banner says what to do (S6 1.5). */}
|
||||
{formError && (
|
||||
<Banner tone="danger" title={t('phone.send-failed-banner')}>
|
||||
{formError}
|
||||
</Banner>
|
||||
<Banner tone="danger">{t('phone.send-failed-banner')}</Banner>
|
||||
)}
|
||||
<FlexBox direction="flex-col" className="gap-1.5">
|
||||
<Typography tag="h1" variant="heading-md">
|
||||
{t('login.title')}
|
||||
{subscribe ? t('login.subscribe.title') : t('login.title')}
|
||||
</Typography>
|
||||
<Typography color="secondary">
|
||||
{subscribe
|
||||
? t('login.subscribe.return', { name: subscribe.channelName })
|
||||
: t('login.description')}
|
||||
</Typography>
|
||||
<Typography color="secondary">{t('login.description')}</Typography>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
tag="form"
|
||||
|
|
@ -66,6 +72,10 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
|
|||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
onChange={(event) => {
|
||||
field.onChange(event);
|
||||
clearError();
|
||||
}}
|
||||
type="tel"
|
||||
dir="ltr"
|
||||
inputMode="numeric"
|
||||
|
|
@ -78,12 +88,7 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
|
|||
)}
|
||||
/>
|
||||
{isUnknownPhone && (
|
||||
<Link
|
||||
href={registerHref}
|
||||
onClick={carryPhone}
|
||||
icon="arrow-left"
|
||||
standalone
|
||||
>
|
||||
<Link href={registerHref} icon="arrow-left" standalone>
|
||||
{t('login.register-with-phone')}
|
||||
</Link>
|
||||
)}
|
||||
|
|
@ -97,6 +102,11 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
|
|||
>
|
||||
{t('login.submit')}
|
||||
</Button>
|
||||
{subscribe && (
|
||||
<Banner tone="info" icon="lock">
|
||||
{t('login.subscribe.notice')}
|
||||
</Banner>
|
||||
)}
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
|
|
@ -106,9 +116,7 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
|
|||
<Typography tag="span" variant="body-sm" color="secondary">
|
||||
{t('login.no-account')}
|
||||
</Typography>
|
||||
<Link href={registerHref} onClick={carryPhone}>
|
||||
{t('login.register')}
|
||||
</Link>
|
||||
<Link href={registerHref}>{t('login.register')}</Link>
|
||||
</FlexBox>
|
||||
<FlexBox justifyContent="justify-center" className="mt-auto">
|
||||
<SupportEntry trigger="link" placement={supportPlacement} />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { StateArt } from '@lumina/island/atoms/state-art';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useLoginSuspendedPage } from '../../../../../../../../features/auth';
|
||||
import { useAuthRoutes } from '../../../../../../../navigation';
|
||||
import { SupportEntry } from '../../../../../../organisms/support-entry';
|
||||
import type { LoginSuspendedStepProps } from './types';
|
||||
|
||||
/**
|
||||
* A valid code for a suspended account (S6 1.11, 2.1, 3.1): no session, nothing else reachable,
|
||||
* one way out to support. Amber, because a suspension is a state, not an error. The admin's reason
|
||||
* shows when there is one. Focus starts on the heading, as the page replaces the code step.
|
||||
*/
|
||||
export function LoginSuspendedStep({
|
||||
size,
|
||||
supportPlacement,
|
||||
layout,
|
||||
}: LoginSuspendedStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const routes = useAuthRoutes();
|
||||
const { suspension } = useLoginSuspendedPage({ loginHref: routes.login });
|
||||
const headingRef = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
useEffect(() => headingRef.current?.focus(), [suspension]);
|
||||
|
||||
if (!suspension) {
|
||||
// The page's own skeleton, while a reload goes back to login.
|
||||
return <SkeletonPreset preset="state" label={t('loading')} />;
|
||||
}
|
||||
return (
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
alignItems="items-center"
|
||||
gap="gap-4"
|
||||
className={
|
||||
layout === 'mobile' ? 'flex-1 pt-6 text-center' : 'pt-6 text-center'
|
||||
}
|
||||
>
|
||||
<StateArt icon="ban" tone="warning" />
|
||||
<FlexBox direction="flex-col" alignItems="items-center" gap="gap-2">
|
||||
<Typography
|
||||
ref={headingRef}
|
||||
tabIndex={-1}
|
||||
tag="h1"
|
||||
variant="heading-md"
|
||||
className="outline-none"
|
||||
>
|
||||
{t('suspended.title')}
|
||||
</Typography>
|
||||
<Typography color="secondary">
|
||||
{suspension.reason
|
||||
? t('suspended.reason', { reason: suspension.reason })
|
||||
: t('suspended.description')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
className={layout === 'mobile' ? 'mt-auto w-full' : 'mt-2 w-full'}
|
||||
>
|
||||
<SupportEntry
|
||||
trigger="button"
|
||||
placement={supportPlacement}
|
||||
size={size}
|
||||
/>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { LoginSuspendedStep } from './LoginSuspendedStep';
|
||||
export type { LoginSuspendedStepProps } from './types';
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import type { SupportEntryProps } from '../../../../../../organisms/support-entry';
|
||||
|
||||
export type LoginSuspendedStepProps = {
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
/** Mobile pins «تماس با پشتیبانی» to the bottom; desktop keeps it in the card. */
|
||||
layout: 'mobile' | 'desktop';
|
||||
};
|
||||
|
|
@ -6,13 +6,12 @@ import { useTranslation } from 'react-i18next';
|
|||
import { useLoginVerifyPage } from '../../../../../../../../features/auth';
|
||||
import { useAuthRoutes } from '../../../../../../../navigation';
|
||||
import { CodeStep } from '../../../../organisms/code-step';
|
||||
import { SuspendedNotice } from './components/SuspendedNotice';
|
||||
import type { LoginVerifyStepProps } from './types';
|
||||
|
||||
/**
|
||||
* Login step 2: the code, then the person lands where they were going. A suspended account sees
|
||||
* the suspended screen here instead. Without a number (after a reload) it waits in its skeleton
|
||||
* while the model sends the person back to the number step.
|
||||
* Login step 2: the code, then the person lands where they were going, or on the suspended
|
||||
* screen. Without a number (after a reload) it waits in its skeleton while the model sends the
|
||||
* person back to the number step.
|
||||
*/
|
||||
export function LoginVerifyStep({
|
||||
size,
|
||||
|
|
@ -22,12 +21,10 @@ export function LoginVerifyStep({
|
|||
const routes = useAuthRoutes();
|
||||
const model = useLoginVerifyPage({
|
||||
phoneHref: routes.login,
|
||||
suspendedHref: routes.loginSuspended,
|
||||
landing: routes.landing,
|
||||
});
|
||||
|
||||
if (model.view === 'suspended') {
|
||||
return <SuspendedNotice size={size} supportPlacement={supportPlacement} />;
|
||||
}
|
||||
if (!model.phone) {
|
||||
return <SkeletonPreset preset="form" label={t('loading')} />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { StateArt } from '@lumina/island/atoms/state-art';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SupportEntry } from '../../../../../../../organisms/support-entry';
|
||||
import type { SuspendedNoticeProps } from '../types';
|
||||
|
||||
/**
|
||||
* A valid code for a suspended account: no session, nothing else reachable, one way out to
|
||||
* support. Amber, because a suspension is a state, not an error. It replaces the code step, so
|
||||
* focus moves to its heading. The API gives no reason yet.
|
||||
*/
|
||||
export function SuspendedNotice({
|
||||
size,
|
||||
supportPlacement,
|
||||
}: SuspendedNoticeProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const headingRef = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
useEffect(() => headingRef.current?.focus(), []);
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
alignItems="items-center"
|
||||
gap="gap-4"
|
||||
className="pt-6 text-center"
|
||||
>
|
||||
<StateArt icon="ban" tone="warning" />
|
||||
<FlexBox direction="flex-col" alignItems="items-center" gap="gap-2">
|
||||
<Typography
|
||||
ref={headingRef}
|
||||
tabIndex={-1}
|
||||
tag="h1"
|
||||
variant="heading-md"
|
||||
className="outline-none"
|
||||
>
|
||||
{t('suspended.title')}
|
||||
</Typography>
|
||||
<Typography color="secondary">{t('suspended.description')}</Typography>
|
||||
</FlexBox>
|
||||
<FlexBox direction="flex-col" className="mt-2 w-full">
|
||||
<SupportEntry
|
||||
trigger="button"
|
||||
placement={supportPlacement}
|
||||
size={size}
|
||||
/>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -5,5 +5,3 @@ export type LoginVerifyStepProps = {
|
|||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
};
|
||||
|
||||
export type SuspendedNoticeProps = LoginVerifyStepProps;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ import type { CodeStepProps } from './types';
|
|||
/**
|
||||
* The 6-digit code step of login and registration: the number it went to, the cells, the resend
|
||||
* wait and the submit button under them. Blocked, the cells and the button rest and the wait
|
||||
* counts to the moment a new code may be asked for; «ویرایش شماره» stays live.
|
||||
* counts to the moment a new code may be asked for; «ویرایش شماره» stays live. Limited (too many
|
||||
* codes in an hour), only the wait is amber: the last code can still be typed.
|
||||
*/
|
||||
export function CodeStep({
|
||||
model,
|
||||
|
|
@ -29,7 +30,7 @@ export function CodeStep({
|
|||
progress,
|
||||
}: CodeStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const { form, status, attempt, submit, complete, resend } = model;
|
||||
const { form, status, attempt, submit, clearError, complete, resend } = model;
|
||||
const isBlocked = status === 'blocked';
|
||||
const formError = form.formState.errors.root?.server?.message;
|
||||
|
||||
|
|
@ -79,7 +80,10 @@ export function CodeStep({
|
|||
key={attempt}
|
||||
name={field.name}
|
||||
value={field.value}
|
||||
onChange={field.onChange}
|
||||
onChange={(value: string) => {
|
||||
field.onChange(value);
|
||||
clearError();
|
||||
}}
|
||||
onComplete={complete}
|
||||
label={t('code.label')}
|
||||
error={translateMessage(t, fieldState.error?.message)}
|
||||
|
|
@ -96,9 +100,10 @@ export function CodeStep({
|
|||
// A new code (or block) starts a new wait, and its announcement plays again.
|
||||
key={resend.endsAt}
|
||||
endsAt={resend.endsAt}
|
||||
limitTotal={resend.limitTotal}
|
||||
status={
|
||||
resend.phase === 'auto'
|
||||
? isBlocked
|
||||
? resend.isLimited
|
||||
? 'limited'
|
||||
: 'auto'
|
||||
: resend.phase
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ export function CreatorIdentityForm(props: DetailsFormProps) {
|
|||
submit,
|
||||
isSubmitting,
|
||||
formError,
|
||||
username,
|
||||
pickImage,
|
||||
progress,
|
||||
cancelUpload,
|
||||
|
|
@ -129,8 +130,9 @@ export function CreatorIdentityForm(props: DetailsFormProps) {
|
|||
<UsernameField
|
||||
control={form.control}
|
||||
name="username"
|
||||
placeholder="ali_trader"
|
||||
hint={t('register.identity.username-note')}
|
||||
placeholder={t('register.identity.username-placeholder')}
|
||||
note={t('register.identity.username-note')}
|
||||
availability={username}
|
||||
/>
|
||||
</Group>
|
||||
<Group
|
||||
|
|
@ -162,13 +164,15 @@ export function CreatorIdentityForm(props: DetailsFormProps) {
|
|||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<FileField
|
||||
// An empty required box takes focus on submit.
|
||||
ref={field.ref}
|
||||
name={field.name}
|
||||
file={field.value}
|
||||
onChange={(file) => pickImage(side, file)}
|
||||
onBlur={field.onBlur}
|
||||
accept={ID_CARD_IMAGE.types.join(',')}
|
||||
label={t(`register.fields.${label}`)}
|
||||
hint={t('register.fields.id-card-hint')}
|
||||
hint={t(`register.fields.${label}-hint`)}
|
||||
size={
|
||||
field.value &&
|
||||
t('register.fields.file-size', {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,11 @@ export function DetailsFrame({
|
|||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
{page.phase === 'warning' && page.expiresAt !== null && (
|
||||
<ExpiryWarning expiresAt={page.expiresAt} />
|
||||
<ExpiryWarning
|
||||
expiresAt={page.expiresAt}
|
||||
isRenewing={page.isRenewing}
|
||||
onRenew={page.canRenew ? page.renew : undefined}
|
||||
/>
|
||||
)}
|
||||
{formError && (
|
||||
<Banner tone="danger" title={t('register.details.network-title')}>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { Countdown } from '@lumina/island/atoms/countdown';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
|
@ -7,10 +8,15 @@ import { useTranslation } from 'react-i18next';
|
|||
import type { ExpiryWarningProps } from '../types';
|
||||
|
||||
/**
|
||||
* Two minutes before the registration token runs out. Announced once (the banner's status
|
||||
* role), never every second: the clock inside is not a live region.
|
||||
* Two minutes before the registration token runs out, with «تمدید زمان» for another 15 minutes
|
||||
* without leaving the page (WCAG 2.2.1). Announced once (the banner's status role), never every
|
||||
* second: the clock inside is not a live region.
|
||||
*/
|
||||
export function ExpiryWarning({ expiresAt }: ExpiryWarningProps) {
|
||||
export function ExpiryWarning({
|
||||
expiresAt,
|
||||
isRenewing,
|
||||
onRenew,
|
||||
}: ExpiryWarningProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
|
||||
return (
|
||||
|
|
@ -18,6 +24,19 @@ export function ExpiryWarning({ expiresAt }: ExpiryWarningProps) {
|
|||
tone="warning"
|
||||
icon="clock"
|
||||
title={t('register.expiry.warning-title')}
|
||||
action={
|
||||
onRenew && (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
icon="refresh"
|
||||
isLoading={isRenewing}
|
||||
onClick={onRenew}
|
||||
>
|
||||
{t('register.expiry.renew')}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('register.expiry.warning-before')}{' '}
|
||||
<Countdown kind="otp" endsAt={expiresAt} />{' '}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import { UsernameField } from './UsernameField';
|
|||
/** Step 4 for an investor: name, last name and username, then «ساخت حساب». */
|
||||
export function InvestorDetailsForm(props: DetailsFormProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const { form, submit, isSubmitting, formError, draft } =
|
||||
const { form, submit, isSubmitting, formError, username, draft } =
|
||||
useInvestorDetailsPart(props.partOptions);
|
||||
|
||||
return (
|
||||
|
|
@ -45,6 +45,7 @@ export function InvestorDetailsForm(props: DetailsFormProps) {
|
|||
name="username"
|
||||
placeholder={t('register.fields.username-placeholder')}
|
||||
hint={t('register.fields.username-hint')}
|
||||
availability={username}
|
||||
/>
|
||||
</DetailsFrame>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Icon } from '@lumina/island/atoms/icon';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { TextInput } from '@lumina/island/molecules/text-input';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import type { FieldValues } from 'react-hook-form';
|
||||
|
|
@ -9,35 +12,63 @@ import { translateMessage } from '../../../../../../../../../shared/utils';
|
|||
import { USERNAME_LENGTH } from '../../../../../../../../../shared/validations';
|
||||
import type { UsernameFieldProps } from '../types';
|
||||
|
||||
/** The public username: left to right after a fixed «@», lower-case, 3 to 30 characters. */
|
||||
/**
|
||||
* The public username: left to right after a fixed «@», lower-case, 3 to 30 characters. A wrong
|
||||
* character or a taken name shows as it is typed, and a free one gets the ✓ line in place of the
|
||||
* hint; the other rules wait for blur.
|
||||
*/
|
||||
export function UsernameField<T extends FieldValues>({
|
||||
control,
|
||||
name,
|
||||
placeholder,
|
||||
hint,
|
||||
note,
|
||||
availability,
|
||||
}: UsernameFieldProps<T>) {
|
||||
const { t } = useTranslation('auth');
|
||||
|
||||
return (
|
||||
<Controller
|
||||
name={name}
|
||||
control={control}
|
||||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
value={field.value as string}
|
||||
dir="ltr"
|
||||
prefix="@"
|
||||
autoComplete="username"
|
||||
autoCapitalize="none"
|
||||
spellCheck={false}
|
||||
maxLength={USERNAME_LENGTH.max}
|
||||
label={t('register.fields.username')}
|
||||
placeholder={placeholder}
|
||||
hint={hint}
|
||||
error={translateMessage(t, fieldState.error?.message)}
|
||||
/>
|
||||
<FlexBox direction="flex-col" gap="gap-2">
|
||||
<Controller
|
||||
name={name}
|
||||
control={control}
|
||||
render={({ field, fieldState }) => {
|
||||
const error = fieldState.error?.message ?? availability.error;
|
||||
return (
|
||||
<TextInput
|
||||
{...field}
|
||||
value={field.value as string}
|
||||
dir="ltr"
|
||||
prefix="@"
|
||||
autoComplete="username"
|
||||
autoCapitalize="none"
|
||||
spellCheck={false}
|
||||
maxLength={USERNAME_LENGTH.max}
|
||||
label={t('register.fields.username')}
|
||||
placeholder={placeholder}
|
||||
hint={hint}
|
||||
error={translateMessage(t, error)}
|
||||
success={
|
||||
!error && availability.status === 'available'
|
||||
? t('register.fields.username-available')
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{note && (
|
||||
<FlexBox alignItems="items-start" gap="gap-1">
|
||||
<Icon
|
||||
name="lock"
|
||||
size={16}
|
||||
className="mt-0.5 flex-none text-text-secondary"
|
||||
/>
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
{note}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
)}
|
||||
/>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import type { Control, FieldValues, Path } from 'react-hook-form';
|
|||
import type {
|
||||
RegisterDetailsPageModel,
|
||||
UseDetailsPartOptions,
|
||||
UsernameAvailability,
|
||||
} from '../../../../../../../../features/auth';
|
||||
import type { SupportEntryProps } from '../../../../../../organisms/support-entry';
|
||||
|
||||
|
|
@ -36,6 +37,9 @@ export type DetailsFrameProps = DetailsFormProps & {
|
|||
|
||||
export type ExpiryWarningProps = {
|
||||
expiresAt: number;
|
||||
isRenewing: boolean;
|
||||
/** Without it, the warning offers no renewal (the server allows no more). */
|
||||
onRenew?: () => void;
|
||||
};
|
||||
|
||||
export type ExpiryHaltProps = {
|
||||
|
|
@ -53,8 +57,12 @@ export type UsernameFieldProps<T extends FieldValues> = {
|
|||
control: Control<T>;
|
||||
name: Path<T>;
|
||||
placeholder: string;
|
||||
/** A rule shown before typing, replaced by an error. */
|
||||
/** A rule shown before typing, replaced by an error or the free ✓. */
|
||||
hint?: string;
|
||||
/** A note that stays under the field whatever it shows, with a lock: the name can't change later. */
|
||||
note?: string;
|
||||
/** The live character and availability checks. */
|
||||
availability: UsernameAvailability;
|
||||
};
|
||||
|
||||
export type NameFieldsProps<T extends FieldValues> = {
|
||||
|
|
|
|||
|
|
@ -77,9 +77,11 @@ export function RegisterTypeStep({
|
|||
<Typography tag="legend" className="sr-only">
|
||||
{t('register.type.label')}
|
||||
</Typography>
|
||||
{ACCOUNT_TYPES.map(({ value, icon }) => (
|
||||
{ACCOUNT_TYPES.map(({ value, icon }, index) => (
|
||||
<ChoiceCard
|
||||
key={value}
|
||||
// Nothing chosen on «ادامه»: focus goes to the first card (R2 1.3).
|
||||
ref={index === 0 ? field.ref : undefined}
|
||||
name={field.name}
|
||||
value={value}
|
||||
icon={icon}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ export function RegisterPhoneStep({
|
|||
submit,
|
||||
isSubmitting,
|
||||
formError,
|
||||
clearError,
|
||||
isTakenPhone,
|
||||
loginWithPhone,
|
||||
isLoggingIn,
|
||||
carryPhone,
|
||||
} = useRegisterPhonePage({
|
||||
typeHref: routes.register.type,
|
||||
codeHref: routes.register.verify,
|
||||
|
|
@ -49,10 +49,9 @@ export function RegisterPhoneStep({
|
|||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
{/* The toast carries the details; the banner says what to do (S6 1.5). */}
|
||||
{formError && (
|
||||
<Banner tone="danger" title={t('phone.send-failed-banner')}>
|
||||
{formError}
|
||||
</Banner>
|
||||
<Banner tone="danger">{t('phone.send-failed-banner')}</Banner>
|
||||
)}
|
||||
<RegisterProgress current={1} role={role} />
|
||||
<FlexBox direction="flex-col" className="gap-1.5">
|
||||
|
|
@ -98,6 +97,10 @@ export function RegisterPhoneStep({
|
|||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
onChange={(event) => {
|
||||
field.onChange(event);
|
||||
clearError();
|
||||
}}
|
||||
type="tel"
|
||||
dir="ltr"
|
||||
inputMode="numeric"
|
||||
|
|
@ -140,9 +143,7 @@ export function RegisterPhoneStep({
|
|||
<Typography tag="span" variant="body-sm" color="secondary">
|
||||
{t('register.has-account')}
|
||||
</Typography>
|
||||
<Link href={routes.login} onClick={carryPhone}>
|
||||
{t('register.login')}
|
||||
</Link>
|
||||
<Link href={routes.login}>{t('register.login')}</Link>
|
||||
</FlexBox>
|
||||
<FlexBox justifyContent="justify-center" className="mt-auto">
|
||||
<SupportEntry trigger="link" placement={supportPlacement} />
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ import { Card } from '@lumina/island/molecules/card';
|
|||
import { useEffect, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { ROUTES } from '../../../../../../../navigation';
|
||||
import { useCreatorProfileDonePage } from '../../../../../../../../features/profile';
|
||||
import { ROUTES, useAuthRoutes } from '../../../../../../../navigation';
|
||||
import { SupportEntry } from '../../../../../../organisms/support-entry';
|
||||
import type { CompletedViewProps } from '../types';
|
||||
import { CreatorProfileDoneStepSkeleton } from './CreatorProfileDoneStepSkeleton';
|
||||
import type { CreatorProfileDoneStepProps } from './types';
|
||||
|
||||
const NEXT_STEPS = [
|
||||
{ icon: 'check-circle', text: 'account', tone: 'text-success-text' },
|
||||
|
|
@ -23,21 +25,28 @@ const NEXT_STEPS = [
|
|||
] as const satisfies readonly { icon: IconName; text: string; tone: string }[];
|
||||
|
||||
/**
|
||||
* The end of registration for a creator: identity under review (the dashboard's badge), news by
|
||||
* SMS and notification, prices can be set now, posting opens after approval. Focus moves to the
|
||||
* heading so screen readers hear it.
|
||||
* The end of registration for a creator (R2-CompleteProfile 1.8, 3.3): identity under review (the
|
||||
* dashboard's badge), news by SMS and notification, prices can be set now, posting opens after
|
||||
* approval. «رفتن به کانال» goes to the page that asked for login, else the channel. Focus moves
|
||||
* to the heading so screen readers hear it.
|
||||
*/
|
||||
export function CompletedView({
|
||||
username,
|
||||
export function CreatorProfileDoneStep({
|
||||
size,
|
||||
supportPlacement,
|
||||
}: CompletedViewProps) {
|
||||
}: CreatorProfileDoneStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const { t: tCommon } = useTranslation('common');
|
||||
const routes = useAuthRoutes();
|
||||
const { username, isLeaving } = useCreatorProfileDonePage({
|
||||
formHref: routes.profile.creator,
|
||||
});
|
||||
const headingRef = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
useEffect(() => headingRef.current?.focus(), []);
|
||||
useEffect(() => headingRef.current?.focus(), [isLeaving]);
|
||||
|
||||
if (isLeaving) {
|
||||
return <CreatorProfileDoneStepSkeleton label={t('loading')} />;
|
||||
}
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
<FlexBox
|
||||
|
|
@ -60,27 +69,34 @@ export function CompletedView({
|
|||
{tCommon('status.verification.pending')}
|
||||
</StatusBadge>
|
||||
</FlexBox>
|
||||
<Card
|
||||
tag="ul"
|
||||
aria-label={t('register.profile.done.steps-label')}
|
||||
className="flex flex-col gap-3"
|
||||
>
|
||||
{NEXT_STEPS.map(({ icon, text, tone }) => (
|
||||
<FlexBox key={text} tag="li" alignItems="items-start" gap="gap-3">
|
||||
<Icon
|
||||
name={icon}
|
||||
size={20}
|
||||
className={`mt-0.5 flex-none ${tone}`}
|
||||
/>
|
||||
<Typography tag="span" variant="body-sm">
|
||||
{t(`register.profile.done.${text}`)}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
))}
|
||||
<Card>
|
||||
<FlexBox
|
||||
tag="ul"
|
||||
aria-label={t('register.profile.done.steps-label')}
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
>
|
||||
{NEXT_STEPS.map(({ icon, text, tone }) => (
|
||||
<FlexBox key={text} tag="li" alignItems="items-start" gap="gap-3">
|
||||
<Icon
|
||||
name={icon}
|
||||
size={20}
|
||||
className={`mt-0.5 flex-none ${tone}`}
|
||||
/>
|
||||
<Typography tag="span" variant="body-sm">
|
||||
{t(`register.profile.done.${text}`)}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
))}
|
||||
</FlexBox>
|
||||
</Card>
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Button
|
||||
href={ROUTES.channel(username)}
|
||||
href={routes.landing({
|
||||
role: 'creator',
|
||||
username,
|
||||
needsProfile: false,
|
||||
})}
|
||||
variant="primary"
|
||||
size={size}
|
||||
block
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
|
||||
import type { CreatorProfileDoneStepSkeletonProps } from './types';
|
||||
|
||||
/**
|
||||
* The end of registration's shape before the viewer and the profile are known: the art, heading
|
||||
* and badge, the four next steps in their card, and the two buttons. Server-safe, for the page's
|
||||
* guard and Suspense.
|
||||
*/
|
||||
export function CreatorProfileDoneStepSkeleton({
|
||||
label,
|
||||
}: CreatorProfileDoneStepSkeletonProps) {
|
||||
return (
|
||||
<SkeletonRegion label={label}>
|
||||
<FlexBox direction="flex-col" gap="gap-6" aria-hidden>
|
||||
<FlexBox direction="flex-col" alignItems="items-center" gap="gap-3">
|
||||
<Skeleton shape="circle" className="size-19" />
|
||||
<Skeleton className="h-6 w-[55%]" />
|
||||
<Skeleton shape="pill" className="h-6 w-32" />
|
||||
</FlexBox>
|
||||
<Card>
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
{['account', 'review', 'pricing', 'posting'].map((line) => (
|
||||
<Skeleton key={line} className="h-5 w-[85%]" />
|
||||
))}
|
||||
</FlexBox>
|
||||
</Card>
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Skeleton shape="pill" className="h-control-lg w-full" />
|
||||
<Skeleton shape="pill" className="h-control-lg w-full" />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
</SkeletonRegion>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
export { CreatorProfileDoneStep } from './CreatorProfileDoneStep';
|
||||
export { CreatorProfileDoneStepSkeleton } from './CreatorProfileDoneStepSkeleton';
|
||||
export type {
|
||||
CreatorProfileDoneStepProps,
|
||||
CreatorProfileDoneStepSkeletonProps,
|
||||
} from './types';
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import type { SupportEntryProps } from '../../../../../../organisms/support-entry';
|
||||
|
||||
export type CreatorProfileDoneStepProps = {
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
};
|
||||
|
||||
export type CreatorProfileDoneStepSkeletonProps = {
|
||||
/** Hidden status text: «در حال بارگذاری…». */
|
||||
label: string;
|
||||
};
|
||||
|
|
@ -1,32 +1,37 @@
|
|||
'use client';
|
||||
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import {
|
||||
useCreatorPhotoPart,
|
||||
useCreatorProfilePage,
|
||||
} from '../../../../../../../features/profile';
|
||||
import { CompletedView } from './components/CompletedView';
|
||||
import { useAuthRoutes } from '../../../../../../navigation';
|
||||
import { CreatorProfileStepSkeleton } from './CreatorProfileStepSkeleton';
|
||||
import { ProfileForm } from './components/ProfileForm';
|
||||
import { StepLayout } from './components/StepLayout';
|
||||
import type { CreatorProfileStepProps } from './types';
|
||||
|
||||
/**
|
||||
* Registration step 5 for a creator, on the normal session: the public profile, required but
|
||||
* saved as it is typed, so it can be finished later. The page wraps it in Suspense while the
|
||||
* saved draft loads; then the form, and after «تکمیل ثبتنام» the end of registration.
|
||||
* saved draft loads; «تکمیل ثبتنام» opens the end of registration. A creator who already
|
||||
* finished goes on to their channel (or the page that asked) and sees the skeleton meanwhile.
|
||||
*/
|
||||
export function CreatorProfileStep(props: CreatorProfileStepProps) {
|
||||
const page = useCreatorProfilePage();
|
||||
const { t } = useTranslation('auth');
|
||||
const routes = useAuthRoutes();
|
||||
const page = useCreatorProfilePage({
|
||||
doneHref: routes.profile.creatorDone,
|
||||
finishedHref: (username) =>
|
||||
routes.landing({ role: 'creator', username, needsProfile: false }),
|
||||
});
|
||||
const photo = useCreatorPhotoPart(page.profile);
|
||||
|
||||
if (page.view === 'completed') {
|
||||
// Finished before this visit: the skeleton stays while the page moves on. Completed in this
|
||||
// visit, the form stays, its button busy, until the end of registration opens.
|
||||
if (page.isFinished) {
|
||||
return (
|
||||
<StepLayout layout={props.layout}>
|
||||
<CompletedView
|
||||
username={page.profile.username}
|
||||
size={props.size}
|
||||
supportPlacement={props.supportPlacement}
|
||||
/>
|
||||
</StepLayout>
|
||||
<CreatorProfileStepSkeleton layout={props.layout} label={t('loading')} />
|
||||
);
|
||||
}
|
||||
return <ProfileForm {...props} page={page} photo={photo} />;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@ export function LinksSection({ control, links, layout }: LinksSectionProps) {
|
|||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
onChange={(event) =>
|
||||
field.onChange(
|
||||
links.toTyped(row.platform, event.target.value),
|
||||
)
|
||||
}
|
||||
className="flex-1"
|
||||
dir="ltr"
|
||||
inputMode="url"
|
||||
|
|
|
|||
|
|
@ -62,10 +62,3 @@ export type ProfilePreviewProps = {
|
|||
export type SaveStatusProps = {
|
||||
status: AutosaveStatus;
|
||||
};
|
||||
|
||||
export type CompletedViewProps = Pick<
|
||||
CreatorProfileStepProps,
|
||||
'size' | 'supportPlacement'
|
||||
> & {
|
||||
username: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
||||
|
||||
import type { InvestorProfileStepSkeletonProps } from './types';
|
||||
|
||||
/** The eight markets' chips, as placeholders of their usual widths. */
|
||||
const CHIP_WIDTHS = [
|
||||
'w-16',
|
||||
'w-24',
|
||||
'w-14',
|
||||
'w-16',
|
||||
'w-28',
|
||||
'w-14',
|
||||
'w-14',
|
||||
'w-28',
|
||||
];
|
||||
|
||||
/**
|
||||
* The investor's step 5 before the viewer is known, at the step's size: the progress, heading,
|
||||
* the photo section with its 96px avatar, the market chips, and the two stacked buttons.
|
||||
* Server-safe, for the page's guard.
|
||||
*/
|
||||
export function InvestorProfileStepSkeleton({
|
||||
label,
|
||||
}: InvestorProfileStepSkeletonProps) {
|
||||
return (
|
||||
<SkeletonRegion label={label}>
|
||||
<FlexBox direction="flex-col" gap="gap-6" aria-hidden>
|
||||
<FlexBox direction="flex-col" gap="gap-2">
|
||||
<Skeleton className="h-1 w-full" />
|
||||
<Skeleton className="w-24" />
|
||||
</FlexBox>
|
||||
<FlexBox direction="flex-col" gap="gap-2">
|
||||
<Skeleton className="h-6 w-[55%]" />
|
||||
<Skeleton className="w-[75%]" />
|
||||
</FlexBox>
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Skeleton className="w-28" />
|
||||
<FlexBox alignItems="items-center" gap="gap-4">
|
||||
<Skeleton shape="circle" className="size-24" />
|
||||
<Skeleton shape="pill" className="h-control-sm w-28" />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Skeleton className="w-32" />
|
||||
<FlexBox wrap="flex-wrap" gap="gap-2">
|
||||
{CHIP_WIDTHS.map((width, chip) => (
|
||||
<Skeleton
|
||||
// Static placeholders that never reorder, so the index is a stable key.
|
||||
key={chip}
|
||||
shape="pill"
|
||||
className={`h-control-sm ${width}`}
|
||||
/>
|
||||
))}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Skeleton shape="pill" className="h-control-lg w-full" />
|
||||
<Skeleton shape="pill" className="h-control-lg w-full" />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
</SkeletonRegion>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,2 +1,6 @@
|
|||
export { InvestorProfileStep } from './InvestorProfileStep';
|
||||
export type { InvestorProfileStepProps } from './types';
|
||||
export { InvestorProfileStepSkeleton } from './InvestorProfileStepSkeleton';
|
||||
export type {
|
||||
InvestorProfileStepProps,
|
||||
InvestorProfileStepSkeletonProps,
|
||||
} from './types';
|
||||
|
|
|
|||
|
|
@ -5,3 +5,8 @@ export type InvestorProfileStepProps = {
|
|||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
};
|
||||
|
||||
export type InvestorProfileStepSkeletonProps = {
|
||||
/** Hidden status text: «در حال بارگذاری…». */
|
||||
label: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,38 +4,48 @@ import { eventEmitter } from '@lumina/libs/event-emitter';
|
|||
import { useAuthStore } from '../../../../stores/auth';
|
||||
import { useAuthFlowStore } from '../../../../stores/auth-flow';
|
||||
import { AUTH_EVENTS } from '../../constants';
|
||||
import { authRepository } from '../../repositories/auth';
|
||||
import type { VerifyOtpArgs } from '../../repositories/auth';
|
||||
import { authRepository, suspensionOf } from '../../repositories/auth';
|
||||
import type { SessionPayload, VerifyOtpArgs } from '../../repositories/auth';
|
||||
import type { LoginOutcome } from './types';
|
||||
|
||||
/**
|
||||
* Verifies the login code; the gateway sets the session cookies and the auth store learns the
|
||||
* account, so every auth-dependent part renders its member variant. A suspended account gets no
|
||||
* session: the gateway still opens one, so it is closed again at once. When that close fails the
|
||||
* person still sees the suspended screen, and the next `restoreSession` closes the session. Emits
|
||||
* `auth.login` when the person is signed in.
|
||||
* account, with whether a creator still has to finish registration step 5. A suspended account
|
||||
* gets no session: the gateway refuses it with the admin's reason, which the flow keeps for the
|
||||
* suspended screen. Should a gateway still sign a suspended account in, its session is closed at
|
||||
* once. Emits `auth.login` when the person is signed in.
|
||||
*/
|
||||
export async function login(
|
||||
args: VerifyOtpArgs,
|
||||
{ emit = true }: { emit?: boolean } = {},
|
||||
): Promise<LoginOutcome> {
|
||||
const { account } = await authRepository.verifyLoginOtp(args);
|
||||
if (account.status === 'suspended') {
|
||||
let session: SessionPayload;
|
||||
try {
|
||||
session = await authRepository.verifyLoginOtp(args);
|
||||
} catch (error) {
|
||||
const suspension = suspensionOf(error);
|
||||
if (!suspension) throw error;
|
||||
useAuthFlowStore.getState().reset();
|
||||
useAuthFlowStore.getState().markSuspended(suspension);
|
||||
return { status: 'suspended' };
|
||||
}
|
||||
if (session.account.status === 'suspended') {
|
||||
await authRepository
|
||||
.logout()
|
||||
.catch((error: unknown) =>
|
||||
handleError(error, { where: 'action', name: 'logout-suspended' }),
|
||||
);
|
||||
useAuthFlowStore.getState().reset();
|
||||
useAuthFlowStore.getState().markSuspended({ reason: null });
|
||||
return { status: 'suspended' };
|
||||
}
|
||||
useAuthFlowStore.getState().reset();
|
||||
useAuthStore.getState().setSession({ account });
|
||||
useAuthStore.getState().setSession(session);
|
||||
if (emit) {
|
||||
eventEmitter.emit(AUTH_EVENTS.login, {
|
||||
userId: account.id,
|
||||
role: account.role,
|
||||
userId: session.account.id,
|
||||
role: session.account.role,
|
||||
});
|
||||
}
|
||||
return { status: 'signed-in', account };
|
||||
return { status: 'signed-in', ...session };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { AccountPayload } from '../../repositories/account';
|
||||
|
||||
/** Signed in, or turned away because the account is suspended (no session). */
|
||||
/** Signed in (and whether step 5 is still to do), or turned away because the account is suspended (no session). */
|
||||
export type LoginOutcome =
|
||||
| { status: 'signed-in'; account: AccountPayload }
|
||||
| { status: 'signed-in'; account: AccountPayload; needsProfile: boolean }
|
||||
| { status: 'suspended' };
|
||||
|
|
|
|||
|
|
@ -33,7 +33,11 @@ export async function registerCreator(
|
|||
});
|
||||
useAuthFlowStore.getState().reset();
|
||||
useAuthFlowStore.getState().markRegistered(registration.account.role);
|
||||
useAuthStore.getState().setSession({ account: registration.account });
|
||||
// Step 5 comes next: the new creator has no public profile yet.
|
||||
useAuthStore.getState().setSession({
|
||||
account: registration.account,
|
||||
needsProfile: registration.profileSetupRequired,
|
||||
});
|
||||
if (emit) {
|
||||
eventEmitter.emit(AUTH_EVENTS.register, {
|
||||
userId: registration.account.id,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export async function registerInvestor(
|
|||
const session = await authRepository.registerInvestor(args);
|
||||
useAuthFlowStore.getState().reset();
|
||||
useAuthFlowStore.getState().markRegistered(session.account.role);
|
||||
useAuthStore.getState().setSession({ account: session.account });
|
||||
useAuthStore.getState().setSession(session);
|
||||
if (emit) {
|
||||
eventEmitter.emit(AUTH_EVENTS.register, {
|
||||
userId: session.account.id,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
import { eventEmitter } from '@lumina/libs/event-emitter';
|
||||
|
||||
import { useAuthFlowStore } from '../../../../stores/auth-flow';
|
||||
import type { RegistrationGrant } from '../../../../stores/auth-flow';
|
||||
import { AUTH_EVENTS } from '../../constants';
|
||||
import { authRepository } from '../../repositories/auth';
|
||||
|
||||
/**
|
||||
* Gives registration step 4 another 15 minutes (R2 4.1): the server swaps the token for a new
|
||||
* one, which replaces it in memory. Throws when the flow has no token. Emits
|
||||
* `auth.registration-renewed`.
|
||||
*/
|
||||
export async function renewRegistration({
|
||||
emit = true,
|
||||
}: { emit?: boolean } = {}): Promise<
|
||||
RegistrationGrant & { renewalsLeft: number }
|
||||
> {
|
||||
const { phone, registration } = useAuthFlowStore.getState();
|
||||
if (!phone || !registration) {
|
||||
throw new Error('renewRegistration needs a verified number');
|
||||
}
|
||||
const { registrationToken, expiresInSeconds, renewalsLeft } =
|
||||
await authRepository.renewRegistration({
|
||||
phone,
|
||||
registrationToken: registration.token,
|
||||
});
|
||||
const grant = {
|
||||
token: registrationToken,
|
||||
expiresAt: Date.now() + expiresInSeconds * 1000,
|
||||
};
|
||||
useAuthFlowStore.getState().phoneVerified(grant);
|
||||
if (emit) {
|
||||
eventEmitter.emit(AUTH_EVENTS.registrationRenewed, { renewalsLeft });
|
||||
}
|
||||
return { ...grant, renewalsLeft };
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { renewRegistration } from './actions';
|
||||
|
|
@ -15,7 +15,8 @@ function isTransient(error: unknown): boolean {
|
|||
/**
|
||||
* Learns who the viewer is, once per page load and again when the connection comes back (the
|
||||
* AppShell calls it). A guest is an empty session, not an error. An expired access cookie is
|
||||
* refreshed by the HTTP client on the way. A suspended account is no member: its session is closed
|
||||
* refreshed by the HTTP client on the way. The session also says whether a creator still has to
|
||||
* finish registration step 5. A suspended account is no member: its session is closed
|
||||
* and the viewer is a guest. When the read fails for a reason that may pass (offline, a timeout,
|
||||
* a 5xx), who the viewer is stays unknown, so a member is never sent to login; any other failure
|
||||
* makes the viewer a guest. Both rethrow for reporting. Emits `auth.restore`.
|
||||
|
|
@ -26,7 +27,7 @@ export async function restoreSession({
|
|||
const { setSession, clearSession } = useAuthStore.getState();
|
||||
let status: ViewerStatus;
|
||||
try {
|
||||
const { account } = await authRepository.getSession();
|
||||
const { account, needsProfile } = await authRepository.getSession();
|
||||
if (account?.status === 'suspended') {
|
||||
clearSession();
|
||||
void authRepository
|
||||
|
|
@ -36,7 +37,7 @@ export async function restoreSession({
|
|||
);
|
||||
status = 'guest';
|
||||
} else if (account) {
|
||||
setSession({ account });
|
||||
setSession({ account, needsProfile });
|
||||
status = 'member';
|
||||
} else {
|
||||
clearSession();
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ export async function saveInvestorProfile(
|
|||
{ avatar: photo },
|
||||
{ signal, onProgress },
|
||||
);
|
||||
useAuthStore.getState().setSession({ account: withPhoto });
|
||||
useAuthStore.getState().updateAccount(withPhoto);
|
||||
onPhotoSaved?.(withPhoto);
|
||||
}
|
||||
const account = await accountRepository.update({ interests });
|
||||
useAuthStore.getState().setSession({ account });
|
||||
useAuthStore.getState().updateAccount(account);
|
||||
if (emit) eventEmitter.emit(AUTH_EVENTS.profileSaved, { userId: account.id });
|
||||
return account;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,16 +6,20 @@ import {
|
|||
AUTH_ERROR_CODES,
|
||||
authErrorCode,
|
||||
authRepository,
|
||||
blockEndOf,
|
||||
limitEndOf,
|
||||
} from '../../repositories/auth';
|
||||
import type { SendCodeArgs, SendCodeOptions } from './types';
|
||||
|
||||
/**
|
||||
* Sends a sign-in or registration code to the number and starts the resend wait. Also the resend:
|
||||
* a new code replaces the previous one. Asked again for the same number inside the server's
|
||||
* cooldown, the code already sent still works while it is unused, so that counts as sent; a code
|
||||
* that already verified the number (registration) does not. The resend button passes
|
||||
* `acceptPending: false`, so the person learns no new code went out. Emits `auth.code-sent` when a
|
||||
* code is sent.
|
||||
* cooldown, the code already sent still works while it is unused, so that counts as sent, also
|
||||
* when this tab forgot it after a reload (its wait then starts now); a code that already verified
|
||||
* the number in this flow (registration) does not. The resend button passes
|
||||
* `acceptPending: false`, so the person learns no new code went out. A number that may not get a
|
||||
* code now (three wrong codes, or too many codes in an hour) is kept with its wait, so the code
|
||||
* step can show it, and the error is rethrown. Emits `auth.code-sent` when a code is sent.
|
||||
*/
|
||||
export async function sendCode(
|
||||
{ purpose, phone }: SendCodeArgs,
|
||||
|
|
@ -26,14 +30,29 @@ export async function sendCode(
|
|||
else await authRepository.sendRegistrationOtp({ phone });
|
||||
} catch (error) {
|
||||
const flow = useAuthFlowStore.getState();
|
||||
const blockEnd = blockEndOf(error);
|
||||
const limitEnd = limitEndOf(error);
|
||||
if (blockEnd !== null || limitEnd !== null) {
|
||||
// First, as a different number starts clean.
|
||||
flow.carryPhone(phone);
|
||||
if (blockEnd !== null) flow.block(blockEnd);
|
||||
if (limitEnd !== null) flow.limit(limitEnd);
|
||||
throw error;
|
||||
}
|
||||
const isSameFlow = flow.purpose === purpose && flow.phone === phone;
|
||||
// This tab knows the cooldown belongs to a code for the other flow (login vs registration),
|
||||
// which this flow's code step would reject.
|
||||
const isOtherFlowsCode =
|
||||
flow.phone === phone && flow.codeSentAt !== null && !isSameFlow;
|
||||
const isPendingCode =
|
||||
acceptPending &&
|
||||
authErrorCode(error) === AUTH_ERROR_CODES.cooldown &&
|
||||
flow.purpose === purpose &&
|
||||
flow.phone === phone &&
|
||||
flow.codeSentAt !== null &&
|
||||
flow.registration === null;
|
||||
!isOtherFlowsCode &&
|
||||
!(isSameFlow && flow.registration !== null);
|
||||
if (!isPendingCode) throw error;
|
||||
if (!isSameFlow || flow.codeSentAt === null) {
|
||||
flow.codeSent(purpose, phone, Date.now());
|
||||
}
|
||||
return 'ok';
|
||||
}
|
||||
useAuthFlowStore.getState().codeSent(purpose, phone, Date.now());
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ export const AUTH_EVENTS = {
|
|||
restore: 'auth.restore',
|
||||
codeSent: 'auth.code-sent',
|
||||
phoneVerified: 'auth.phone-verified',
|
||||
registrationRenewed: 'auth.registration-renewed',
|
||||
login: 'auth.login',
|
||||
register: 'auth.register',
|
||||
profileSaved: 'auth.profile-saved',
|
||||
|
|
@ -14,15 +15,20 @@ export const AUTH_PURPOSES = ['login', 'register'] as const;
|
|||
|
||||
/**
|
||||
* The code rules the pages show. The server owns them (a code lives 10 minutes, the third wrong
|
||||
* code blocks the number for 10 minutes); the 2-minute resend wait is the product's, longer than
|
||||
* the server's 60-second cooldown.
|
||||
* code blocks the number for 10 minutes, at most 5 codes per number in an hour); the 2-minute
|
||||
* resend wait is the product's, longer than the server's 60-second cooldown.
|
||||
*/
|
||||
export const CODE_RULES = {
|
||||
length: 6,
|
||||
resendWaitSeconds: 120,
|
||||
maxMisses: 3,
|
||||
blockSeconds: 600,
|
||||
/** The window of the hourly code limit; it drives the limited wait's ring. */
|
||||
sendWindowSeconds: 3600,
|
||||
} as const;
|
||||
|
||||
/** Step 4 warns this long before the registration token runs out. */
|
||||
export const REGISTRATION_WARNING_SECONDS = 120;
|
||||
|
||||
/** How long typing must pause before a username's availability is checked. */
|
||||
export const USERNAME_CHECK_DELAY_MS = 500;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ export type { LoginOutcome } from './actions/login';
|
|||
export { logout } from './actions/logout';
|
||||
export { registerCreator } from './actions/register-creator';
|
||||
export { registerInvestor } from './actions/register-investor';
|
||||
export { renewRegistration } from './actions/renew-registration';
|
||||
export { restoreSession } from './actions/restore-session';
|
||||
export { saveInvestorProfile } from './actions/save-investor-profile';
|
||||
export type {
|
||||
|
|
@ -36,11 +37,14 @@ export type {
|
|||
UseInvestorProfilePageOptions,
|
||||
} from './models/investor-profile';
|
||||
export { useLoginPage } from './models/login';
|
||||
export type { LoginPageModel, UseLoginPageOptions } from './models/login';
|
||||
export type {
|
||||
LoginPageModel,
|
||||
SubscribeIntro,
|
||||
UseLoginPageOptions,
|
||||
} from './models/login';
|
||||
export { useLoginVerifyPage } from './models/login-verify';
|
||||
export type {
|
||||
LoginVerifyPageModel,
|
||||
LoginVerifyView,
|
||||
SignedInViewer,
|
||||
UseLoginVerifyPageOptions,
|
||||
} from './models/login-verify';
|
||||
|
|
@ -57,7 +61,16 @@ export type {
|
|||
RegistrationTimePhase,
|
||||
UseDetailsPartOptions,
|
||||
UseRegisterDetailsPageOptions,
|
||||
UsernameAvailability,
|
||||
UsernameAvailabilityStatus,
|
||||
} from './models/register-details';
|
||||
export { useLoginSuspendedPage } from './models/login-suspended';
|
||||
export type {
|
||||
LoginSuspendedPageModel,
|
||||
UseLoginSuspendedPageOptions,
|
||||
} from './models/login-suspended';
|
||||
export { usePhoneStep } from './models/phone-step';
|
||||
export type { PhoneStepModel, UsePhoneStepOptions } from './models/phone-step';
|
||||
export { useRegisterPhonePage } from './models/register-phone';
|
||||
export type {
|
||||
RegisterPhonePageModel,
|
||||
|
|
|
|||
|
|
@ -31,11 +31,17 @@ export type CodeStepModel = {
|
|||
/** Remounts the cells after a wrong code or a new one, so focus is back on the first cell. */
|
||||
attempt: number;
|
||||
submit: () => Promise<void>;
|
||||
/** Typing again clears the last code's message. */
|
||||
clearError: () => void;
|
||||
/** The 6th digit submits on its own. */
|
||||
complete: (code: string) => void;
|
||||
resend: {
|
||||
/** When the wait (or the block) ends, ms since epoch. */
|
||||
/** When the wait (or the block, or the hourly limit) ends, ms since epoch. */
|
||||
endsAt: number | undefined;
|
||||
/** No new code may be asked for until `endsAt`: blocked, or too many codes in an hour. */
|
||||
isLimited: boolean;
|
||||
/** The limited wait's full length in seconds, for its ring. */
|
||||
limitTotal: number;
|
||||
phase: ResendPhase;
|
||||
onResend: () => void;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,13 +11,20 @@ import { useAuthFlowStore } from '../../../../stores/auth-flow';
|
|||
import { sendCode } from '../../actions/send-code';
|
||||
import { CODE_RULES } from '../../constants';
|
||||
import {
|
||||
asBlockError,
|
||||
AUTH_ERROR_CODES,
|
||||
authErrorCode,
|
||||
blockEndOf,
|
||||
codeWaitOf,
|
||||
} from '../../repositories/auth';
|
||||
import { useLiftAt } from './use-lift-at';
|
||||
import { SENT_NOTICE_MS } from './constants';
|
||||
import type { CodeStepModel, ResendPhase, UseCodeStepOptions } from './types';
|
||||
|
||||
/** When the block or the hourly limit is over, the number may ask for a code again. */
|
||||
const liftBlock = () => useAuthFlowStore.getState().block(null);
|
||||
const liftLimit = () => useAuthFlowStore.getState().limit(null);
|
||||
|
||||
/** A wrong code counts; the third one blocks the number until the returned time. Event handlers only. */
|
||||
function countMiss(): number | null {
|
||||
useAuthFlowStore.getState().codeMissed();
|
||||
|
|
@ -43,11 +50,15 @@ export function useCodeStep({
|
|||
const [phone] = useState(() => useAuthFlowStore.getState().phone);
|
||||
const codeSentAt = useAuthFlowStore((state) => state.codeSentAt);
|
||||
const blockedUntil = useAuthFlowStore((state) => state.blockedUntil);
|
||||
const limitedUntil = useAuthFlowStore((state) => state.limitedUntil);
|
||||
const [attempt, setAttempt] = useState(0);
|
||||
const [phase, setPhase] = useState<ResendPhase>('auto');
|
||||
const [isLeaving, setIsLeaving] = useState(false);
|
||||
const form = useForm<CodeFormValues>({
|
||||
resolver: valibotResolver(codeSchema),
|
||||
// Checked only on submit: after a wrong code, typing the next one must not swap its message
|
||||
// for «کد ۶ رقمی را کامل وارد کنید.» at the first digit. The message clears on edit instead.
|
||||
reValidateMode: 'onSubmit',
|
||||
defaultValues: { code: '' },
|
||||
});
|
||||
|
||||
|
|
@ -56,14 +67,8 @@ export function useCodeStep({
|
|||
if (!phone) router.replace(phoneHref);
|
||||
}, [phone, phoneHref, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (blockedUntil === null) return undefined;
|
||||
const timer = setTimeout(
|
||||
() => useAuthFlowStore.getState().block(null),
|
||||
Math.max(0, blockedUntil - Date.now()),
|
||||
);
|
||||
return () => clearTimeout(timer);
|
||||
}, [blockedUntil]);
|
||||
useLiftAt(blockedUntil, liftBlock);
|
||||
useLiftAt(limitedUntil, liftLimit);
|
||||
|
||||
useEffect(() => {
|
||||
if (phase !== 'sent') return undefined;
|
||||
|
|
@ -87,7 +92,7 @@ export function useCodeStep({
|
|||
}
|
||||
if (blockEnd !== null) {
|
||||
useAuthFlowStore.getState().block(blockEnd);
|
||||
showActionError(error, options);
|
||||
showActionError(isWrong ? asBlockError(error) : error, options);
|
||||
return;
|
||||
}
|
||||
if (isWrong) {
|
||||
|
|
@ -121,13 +126,13 @@ export function useCodeStep({
|
|||
setPhase('sent');
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
// A block or the hourly limit is already in the flow store (`sendCode`), and the wait
|
||||
// shows it; trying again before it ends would fail the same way.
|
||||
setPhase('auto');
|
||||
const blockEnd = blockEndOf(error);
|
||||
if (blockEnd !== null) useAuthFlowStore.getState().block(blockEnd);
|
||||
showActionError(error, {
|
||||
t,
|
||||
failedMessage: t('code.resend-failed'),
|
||||
retry: onResend,
|
||||
retry: codeWaitOf(error) === null ? onResend : undefined,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
@ -143,6 +148,9 @@ export function useCodeStep({
|
|||
: 'idle',
|
||||
attempt,
|
||||
submit: () => submit(),
|
||||
clearError: () => {
|
||||
if (form.formState.errors.code) form.clearErrors('code');
|
||||
},
|
||||
complete: (code) => {
|
||||
form.setValue('code', code);
|
||||
void submit();
|
||||
|
|
@ -150,9 +158,15 @@ export function useCodeStep({
|
|||
resend: {
|
||||
endsAt:
|
||||
blockedUntil ??
|
||||
limitedUntil ??
|
||||
(codeSentAt === null
|
||||
? undefined
|
||||
: codeSentAt + CODE_RULES.resendWaitSeconds * 1000),
|
||||
isLimited: blockedUntil !== null || limitedUntil !== null,
|
||||
limitTotal:
|
||||
blockedUntil === null && limitedUntil !== null
|
||||
? CODE_RULES.sendWindowSeconds
|
||||
: CODE_RULES.blockSeconds,
|
||||
phase,
|
||||
onResend,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
import { useEffect } from 'react';
|
||||
|
||||
/** Runs `lift` once at `until` (ms since epoch); nothing while `until` is `null`. Pass a stable `lift`. */
|
||||
export function useLiftAt(until: number | null, lift: () => void): void {
|
||||
useEffect(() => {
|
||||
if (until === null) return undefined;
|
||||
const timer = setTimeout(lift, Math.max(0, until - Date.now()));
|
||||
return () => clearTimeout(timer);
|
||||
}, [until, lift]);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue