Compare commits
6 Commits
dcf99e6fa5
...
46958936dc
| Author | SHA1 | Date |
|---|---|---|
|
|
46958936dc | |
|
|
7d381758ab | |
|
|
fbb3a59677 | |
|
|
d43e74237f | |
|
|
025c68dd0d | |
|
|
64048e8224 |
|
|
@ -0,0 +1,9 @@
|
|||
<!-- BEGIN:nextjs-agent-rules -->
|
||||
|
||||
# This is NOT the Next.js you know
|
||||
|
||||
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.
|
||||
|
||||
This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
|
||||
|
||||
<!-- END:nextjs-agent-rules -->
|
||||
|
|
@ -0,0 +1 @@
|
|||
@AGENTS.md
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
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';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return { title: i18n.t('auth:login.meta-title'), robots: { index: false } };
|
||||
}
|
||||
|
||||
/** Login, the number. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset preset="form" label={i18n.t('auth:loading')} />
|
||||
}
|
||||
>
|
||||
<LoginStep size="md" supportPlacement="popover" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { LoginVerifyStep } from '@lumina/market/app/screens/(auth)/auth/login/verify/organisms/login-verify-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:login.verify-meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Login, the code. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function LoginVerifyPage() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset preset="form" label={i18n.t('auth:loading')} />
|
||||
}
|
||||
>
|
||||
<LoginVerifyStep size="md" supportPlacement="popover" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { RegisterDetailsStep } from '@lumina/market/app/screens/(auth)/auth/register/details/organisms/register-details-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:register.details.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Registration step 4, account details or identity. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function RegisterDetailsPage() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={3}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<RegisterDetailsStep
|
||||
size="md"
|
||||
supportPlacement="popover"
|
||||
haltPlacement="modal"
|
||||
/>
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
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';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('auth:register.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Registration step 1, the account type. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function RegisterTypePage() {
|
||||
return (
|
||||
<AuthTemplate width="wide">
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<RegisterTypeStep size="md" supportPlacement="popover" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { RegisterPhoneStep } from '@lumina/market/app/screens/(auth)/auth/register/phone/organisms/register-phone-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:register.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Registration step 2, the number. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function RegisterPhonePage() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<RegisterPhoneStep size="md" supportPlacement="popover" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { RegisterVerifyStep } from '@lumina/market/app/screens/(auth)/auth/register/verify/organisms/register-verify-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:register.verify.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Registration step 3, the code. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function RegisterVerifyPage() {
|
||||
return (
|
||||
<AuthTemplate>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<RegisterVerifyStep size="md" supportPlacement="popover" />
|
||||
</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 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,58 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { cn } from '@lumina/island/tools/cn';
|
||||
import { ROUTES } from '@lumina/market/app/navigation';
|
||||
import { SupportEntry } from '@lumina/market/app/screens/(auth)/organisms/support-entry';
|
||||
import NextLink from 'next/link';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import type { AuthTemplateProps } from './types';
|
||||
|
||||
/**
|
||||
* Login and registration on desktop: the logged-out header (the brand and support) and each
|
||||
* step in one centred card, its buttons inside the card under the fields. Browser back is the
|
||||
* way back; there is no back button.
|
||||
*/
|
||||
export function AuthTemplate({
|
||||
width = 'narrow',
|
||||
children,
|
||||
}: AuthTemplateProps) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" className="min-h-dvh bg-bg-page">
|
||||
<FlexBox
|
||||
tag="header"
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-between"
|
||||
className="min-h-16 border-b border-border-subtle bg-surface px-8"
|
||||
>
|
||||
<Typography
|
||||
tag={NextLink}
|
||||
href={ROUTES.home}
|
||||
aria-label={i18n.t('auth:header.home')}
|
||||
variant="heading-sm"
|
||||
color="brand"
|
||||
className="rounded-xs no-underline focus-visible:focus-ring"
|
||||
>
|
||||
{i18n.t('auth:header.brand')}
|
||||
</Typography>
|
||||
<SupportEntry trigger="icon" placement="popover" />
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
className="px-4 pt-28 pb-16"
|
||||
>
|
||||
<Card
|
||||
padding="none"
|
||||
className={cn(
|
||||
'w-full p-10',
|
||||
width === 'wide' ? 'max-w-form' : 'max-w-checkout',
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</Card>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { AuthTemplate } from './AuthTemplate';
|
||||
export type { AuthTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
export type AuthTemplateProps = {
|
||||
/** narrow (480): the number and the code. wide (560): the account type and step 4. */
|
||||
width?: 'narrow' | 'wide';
|
||||
children: ReactNode;
|
||||
};
|
||||
|
|
@ -12,6 +12,9 @@ import { rootMetadata } from '../configs';
|
|||
import { i18n } from '../i18n';
|
||||
import { AppProviders } from './organisms/app-providers';
|
||||
|
||||
// Every request renders fresh: nothing is prerendered or cached on the server.
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return rootMetadata();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
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';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return { title: i18n.t('auth:login.meta-title'), robots: { index: false } };
|
||||
}
|
||||
|
||||
/** Login, the number. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset preset="form" label={i18n.t('auth:loading')} />
|
||||
}
|
||||
>
|
||||
<LoginStep size="lg" supportPlacement="bottom" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
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 { LoginVerifyStep } from '@lumina/market/app/screens/(auth)/auth/login/verify/organisms/login-verify-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:login.verify-meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar title={i18n.t('auth:login.header')} backHref={backHref} />
|
||||
}
|
||||
>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset preset="form" label={i18n.t('auth:loading')} />
|
||||
}
|
||||
>
|
||||
<LoginVerifyStep size="lg" supportPlacement="bottom" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
|
||||
import { RegisterDetailsStep } from '@lumina/market/app/screens/(auth)/auth/register/details/organisms/register-details-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:register.details.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Registration step 4, account details or identity. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function RegisterDetailsPage() {
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
|
||||
>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={3}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<RegisterDetailsStep
|
||||
size="lg"
|
||||
supportPlacement="bottom"
|
||||
haltPlacement="sheet"
|
||||
/>
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
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';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return {
|
||||
title: i18n.t('auth:register.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
/** Registration step 1, the account type. The frame renders on the server; the step only in the browser (0013). */
|
||||
export default function RegisterTypePage() {
|
||||
return (
|
||||
<AuthTemplate header={<AuthTopBar />}>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={2}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<RegisterTypeStep size="lg" supportPlacement="bottom" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
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 { RegisterPhoneStep } from '@lumina/market/app/screens/(auth)/auth/register/phone/organisms/register-phone-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:register.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar
|
||||
title={i18n.t('auth:register.header')}
|
||||
backHref={backHref}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<RegisterPhoneStep size="lg" supportPlacement="bottom" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
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 { RegisterVerifyStep } from '@lumina/market/app/screens/(auth)/auth/register/verify/organisms/register-verify-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:register.verify.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
|
||||
return (
|
||||
<AuthTemplate
|
||||
header={
|
||||
<AuthTopBar
|
||||
title={i18n.t('auth:register.header')}
|
||||
backHref={backHref}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<GuestGuard
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
label={i18n.t('auth:loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<RegisterVerifyStep size="lg" supportPlacement="bottom" />
|
||||
</GuestGuard>
|
||||
</AuthTemplate>
|
||||
);
|
||||
}
|
||||
|
|
@ -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 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,57 @@
|
|||
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';
|
||||
import { SupportEntry } from '@lumina/market/app/screens/(auth)/organisms/support-entry';
|
||||
import NextLink from 'next/link';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import type { AuthTopBarProps } from './types';
|
||||
|
||||
/**
|
||||
* The logged-out top bar: the brand and support on a first step; back, the step's name and
|
||||
* 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) {
|
||||
return (
|
||||
<FlexBox
|
||||
tag="header"
|
||||
alignItems="items-center"
|
||||
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}
|
||||
/>
|
||||
)}
|
||||
{title ? (
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="heading-sm"
|
||||
className={backHref ? 'flex-1' : 'flex-1 px-2'}
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
) : (
|
||||
<FlexBox className="flex-1 px-2">
|
||||
<Typography
|
||||
tag={NextLink}
|
||||
href={ROUTES.home}
|
||||
aria-label={i18n.t('auth:header.home')}
|
||||
variant="heading-sm"
|
||||
color="brand"
|
||||
className="rounded-xs no-underline focus-visible:focus-ring"
|
||||
>
|
||||
{i18n.t('auth:header.brand')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
)}
|
||||
<SupportEntry trigger="icon" placement="bottom" />
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { AuthTopBar } from './AuthTopBar';
|
||||
export type { AuthTopBarProps } from './types';
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
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;
|
||||
};
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
|
||||
import type { AuthTemplateProps } from './types';
|
||||
|
||||
/**
|
||||
* Login and registration on mobile: the logged-out top bar over one white column. The submit
|
||||
* buttons sit under their fields, never pinned to the bottom, so they stay above the keyboard.
|
||||
*/
|
||||
export function AuthTemplate({ header, children }: AuthTemplateProps) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" className="min-h-dvh bg-surface">
|
||||
{header}
|
||||
<FlexBox
|
||||
tag="main"
|
||||
direction="flex-col"
|
||||
className="w-full flex-1 px-4 pt-6 pb-5"
|
||||
>
|
||||
{children}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { AuthTemplate } from './AuthTemplate';
|
||||
export type { AuthTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
export type AuthTemplateProps = {
|
||||
/** The top bar: the brand, or back and the step's name. */
|
||||
header: ReactNode;
|
||||
/** The step; it fills the height, so support sits at the bottom. */
|
||||
children: ReactNode;
|
||||
};
|
||||
|
|
@ -12,6 +12,9 @@ import { rootMetadata } from '../configs';
|
|||
import { i18n } from '../i18n';
|
||||
import { AppProviders } from './organisms/app-providers';
|
||||
|
||||
// Every request renders fresh: nothing is prerendered or cached on the server.
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export function generateMetadata(): Metadata {
|
||||
return rootMetadata();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
# 0013 Auth pages render in the browser
|
||||
|
||||
Status: Accepted · Area: architecture · Date: 2026-10-05 · Decided by: user
|
||||
|
||||
## Context
|
||||
|
||||
Login and registration are interactive, guest-only forms that hold the number, the code timing and the registration token in memory between steps. The user asked for every auth page to be fully client-side rendered.
|
||||
|
||||
## Decision
|
||||
|
||||
- Every page under the `(auth)` route group renders its steps only in the browser. The server sends the page frame (the logged-out header and, on desktop, the card) with a same-size form skeleton, and `metadata` with `robots: { index: false }`.
|
||||
- The page wraps its step in the platform's `GuestGuard`; the step's organism, its model and its form never render on the server. A visitor who is already signed in is sent on to `?redirect=` or home.
|
||||
- The flow's state (number, code timing, registration token, the step-4 draft) lives in the in-memory `auth-flow` store, never in the URL, a cookie or local storage. A reload starts the flow again at its number step.
|
||||
|
||||
## Alternatives
|
||||
|
||||
- Server-render the form and hydrate it: not discussed; the form is useless before hydration and depends on the viewer being a guest.
|
||||
|
||||
## Consequences
|
||||
|
||||
- Search engines see only the frame and the skeleton, so auth pages are not indexed.
|
||||
- The step's JavaScript is part of the route's first load; keep auth organisms light.
|
||||
- The registration token sits in JavaScript memory, because the API returns it in the body. It never reaches storage; an HttpOnly cookie would need a back-end change.
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
- 0001 Share one platform, `platforms/market`, between `apps/bull` and `apps/bear`; tag all three `scope:market`.
|
||||
- 0012 Wrap each app's `next.config` in island's `withIconSprite` and `withFontCopy`; they write `symbol-defs.svg` and the fonts into `public/` unhashed, served immutable; link the sprite as `?v=<ICON_SPRITE_VERSION>`.
|
||||
- 0013 Render every `(auth)` page's steps only in the browser behind `GuestGuard`: the server sends the frame, a same-size skeleton and `noindex`; flow state stays in memory, never in the URL or storage.
|
||||
|
||||
## Proposed
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { linkVariants } from './variants';
|
|||
export function Link({
|
||||
standalone,
|
||||
icon,
|
||||
iconStart,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
|
|
@ -24,6 +25,7 @@ export function Link({
|
|||
className={cn(linkVariants({ standalone }), className)}
|
||||
{...props}
|
||||
>
|
||||
{iconStart && <Icon name={iconStart} size={18} />}
|
||||
<Typography tag="span" variant="inherit" color="inherit">
|
||||
{children}
|
||||
</Typography>
|
||||
|
|
|
|||
|
|
@ -9,4 +9,6 @@ export type LinkProps = ComponentPropsWithRef<typeof NextLink> &
|
|||
VariantProps<typeof linkVariants> & {
|
||||
/** Trailing icon, such as `external` or `chevron-left` ("go to" points left in RTL). */
|
||||
icon?: IconName;
|
||||
/** Leading icon, for an action named by its verb, such as `edit` before «ویرایش شماره». */
|
||||
iconStart?: IconName;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,192 @@
|
|||
'use client';
|
||||
|
||||
import { useEffect, useId, useRef } from 'react';
|
||||
import type { ChangeEvent } from 'react';
|
||||
|
||||
import { Button } from '../../atoms/button';
|
||||
import { FlexBox } from '../../atoms/flex-box';
|
||||
import { Icon } from '../../atoms/icon';
|
||||
import { Typography } from '../../atoms/typography';
|
||||
import { Element } from '../../primitives/element';
|
||||
import { cn } from '../../tools/cn';
|
||||
import type { FileFieldProps } from './types';
|
||||
import { fileDropVariants, filePickedVariants } from './variants';
|
||||
|
||||
/**
|
||||
* One file to send with a form, such as a national ID card image. Empty, the whole dashed box
|
||||
* opens the picker; picked, it shows a thumbnail (for images), the name and the size with a
|
||||
* remove button; uploading, a bar with the percent replaces remove. The file stays in memory.
|
||||
*/
|
||||
export function FileField({
|
||||
label,
|
||||
hint,
|
||||
file,
|
||||
size,
|
||||
onChange,
|
||||
onBlur,
|
||||
accept,
|
||||
error,
|
||||
progress,
|
||||
disabled = false,
|
||||
labels,
|
||||
id: idProp,
|
||||
name,
|
||||
className,
|
||||
}: FileFieldProps) {
|
||||
const generatedId = useId();
|
||||
const id = idProp ?? generatedId;
|
||||
const messageId = `${id}-message`;
|
||||
const isInvalid = error != null && error !== false;
|
||||
const isUploading = progress !== undefined;
|
||||
|
||||
const pick = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
onChange(event.target.files?.[0] ?? null);
|
||||
// The same file can be picked again after it was removed or rejected.
|
||||
event.target.value = '';
|
||||
};
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-2"
|
||||
className={cn('min-w-0', className)}
|
||||
>
|
||||
<Typography tag="span" variant="label" id={`${id}-label`}>
|
||||
{label}
|
||||
</Typography>
|
||||
{file ? (
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
className={filePickedVariants({ invalid: isInvalid })}
|
||||
>
|
||||
{file.type.startsWith('image/') ? (
|
||||
<Thumbnail file={file} />
|
||||
) : (
|
||||
<Icon
|
||||
name="upload"
|
||||
size={24}
|
||||
className="flex-none text-text-secondary"
|
||||
/>
|
||||
)}
|
||||
<FlexBox direction="flex-col" gap="gap-1" className="min-w-0 flex-1">
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="body-sm"
|
||||
dir="ltr"
|
||||
className="truncate text-start font-semibold"
|
||||
>
|
||||
{file.name}
|
||||
</Typography>
|
||||
{isUploading ? (
|
||||
<>
|
||||
<Element
|
||||
tag="progress"
|
||||
value={progress}
|
||||
max={100}
|
||||
aria-labelledby={`${id}-label`}
|
||||
className="h-1 w-full appearance-none overflow-hidden rounded-full bg-surface-sunken [&::-moz-progress-bar]:bg-action-primary [&::-webkit-progress-bar]:bg-surface-sunken [&::-webkit-progress-value]:bg-action-primary"
|
||||
/>
|
||||
{labels.uploading && (
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
{labels.uploading(progress)}
|
||||
</Typography>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
size != null && (
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
{size}
|
||||
</Typography>
|
||||
)
|
||||
)}
|
||||
</FlexBox>
|
||||
{!isUploading && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="trash"
|
||||
label={labels.remove}
|
||||
disabled={disabled}
|
||||
onClick={() => onChange(null)}
|
||||
/>
|
||||
)}
|
||||
</FlexBox>
|
||||
) : (
|
||||
<FlexBox
|
||||
tag="label"
|
||||
htmlFor={id}
|
||||
direction="flex-col"
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-center"
|
||||
gap="gap-1"
|
||||
className={fileDropVariants({ invalid: isInvalid, disabled })}
|
||||
>
|
||||
<Icon name="upload" size={24} className="text-text-secondary" />
|
||||
<Typography tag="span" variant="label" color="link">
|
||||
{labels.pick}
|
||||
</Typography>
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
{labels.rules}
|
||||
</Typography>
|
||||
<Element
|
||||
tag="input"
|
||||
type="file"
|
||||
id={id}
|
||||
name={name}
|
||||
accept={accept}
|
||||
disabled={disabled}
|
||||
onChange={pick}
|
||||
onBlur={onBlur}
|
||||
aria-labelledby={`${id}-label`}
|
||||
aria-invalid={isInvalid || undefined}
|
||||
aria-describedby={isInvalid || hint != null ? messageId : undefined}
|
||||
className="sr-only"
|
||||
/>
|
||||
</FlexBox>
|
||||
)}
|
||||
{isInvalid && error !== true ? (
|
||||
<FlexBox alignItems="items-center" gap="gap-1">
|
||||
<Icon name="alert" size={16} className="flex-none text-danger" />
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="caption"
|
||||
color="danger"
|
||||
role="alert"
|
||||
id={messageId}
|
||||
>
|
||||
{error}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
) : (
|
||||
hint != null && (
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="caption"
|
||||
color="secondary"
|
||||
id={messageId}
|
||||
>
|
||||
{hint}
|
||||
</Typography>
|
||||
)
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
||||
/** An image file's thumbnail from an object URL, revoked when the file changes or leaves. */
|
||||
function Thumbnail({ file }: { file: File }) {
|
||||
const ref = useRef<HTMLImageElement>(null);
|
||||
useEffect(() => {
|
||||
const url = URL.createObjectURL(file);
|
||||
if (ref.current) ref.current.src = url;
|
||||
return () => URL.revokeObjectURL(url);
|
||||
}, [file]);
|
||||
return (
|
||||
<Element
|
||||
tag="img"
|
||||
ref={ref}
|
||||
alt=""
|
||||
className="size-12 flex-none rounded-sm bg-surface-sunken object-cover"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export { FileField } from './FileField';
|
||||
export type { FileFieldLabels, FileFieldProps } from './types';
|
||||
export { fileDropVariants, filePickedVariants } from './variants';
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
/** Every text the field shows, from the translations. */
|
||||
export type FileFieldLabels = {
|
||||
/** «انتخاب فایل». */
|
||||
pick: ReactNode;
|
||||
/** The accepted types and size, under the pick text: «JPG یا PNG، حداکثر ۵ مگابایت». */
|
||||
rules: ReactNode;
|
||||
/** The remove button's accessible name: «حذف تصویر». */
|
||||
remove: string;
|
||||
/** While uploading, given the percent: «در حال بارگذاری… ۶۴٪». */
|
||||
uploading?: (percent: number) => ReactNode;
|
||||
};
|
||||
|
||||
export type FileFieldProps = {
|
||||
label: ReactNode;
|
||||
/** A rule given before picking: «یک تصویر واضح … آپلود کنید.». */
|
||||
hint?: ReactNode;
|
||||
file: File | null;
|
||||
/** The picked file's size, formatted by the caller: «۱٫۸ مگابایت». */
|
||||
size?: ReactNode;
|
||||
/** A picked file, or `null` when removed. Check type and size here, when it is picked. */
|
||||
onChange: (file: File | null) => void;
|
||||
onBlur?: () => void;
|
||||
/** MIME types for the picker, such as `image/jpeg,image/png`. */
|
||||
accept?: string;
|
||||
/** Inline error under the box; a rejected file leaves the box empty. */
|
||||
error?: ReactNode;
|
||||
/** 0–100 while the file uploads: the bar replaces the remove button. */
|
||||
progress?: number;
|
||||
disabled?: boolean;
|
||||
labels: FileFieldLabels;
|
||||
id?: string;
|
||||
name?: string;
|
||||
className?: string;
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import { cva } from 'class-variance-authority';
|
||||
|
||||
/** The empty box: the whole box is the picker's label, so it is one large target. */
|
||||
export const fileDropVariants = cva(
|
||||
'min-h-30 rounded-md border border-dashed bg-surface-sunken px-4 py-5 text-center transition-colors duration-120 ease-standard has-focus-visible:focus-ring',
|
||||
{
|
||||
variants: {
|
||||
invalid: {
|
||||
true: 'border-danger',
|
||||
false:
|
||||
'border-border-default actionable:cursor-pointer hover:border-text-secondary',
|
||||
},
|
||||
disabled: { true: 'frozen', false: '' },
|
||||
},
|
||||
defaultVariants: { invalid: false, disabled: false },
|
||||
},
|
||||
);
|
||||
|
||||
/** The picked file's row: thumbnail, name and size, then remove or the upload bar. */
|
||||
export const filePickedVariants = cva(
|
||||
'min-h-18 rounded-md border bg-surface p-3',
|
||||
{
|
||||
variants: {
|
||||
invalid: { true: 'border-danger', false: 'border-border-default' },
|
||||
},
|
||||
defaultVariants: { invalid: false },
|
||||
},
|
||||
);
|
||||
|
|
@ -18,6 +18,7 @@ export function Toast({
|
|||
action,
|
||||
announce = true,
|
||||
children,
|
||||
description,
|
||||
className,
|
||||
}: ToastProps) {
|
||||
const role = tone === 'error' ? 'alert' : 'status';
|
||||
|
|
@ -29,9 +30,16 @@ export function Toast({
|
|||
className={cn(toastVariants(), className)}
|
||||
>
|
||||
{icon && <Icon name={icon} className={toastIconVariants({ tone })} />}
|
||||
<Typography tag="span" color="inverse" className="min-w-0 flex-1">
|
||||
{children}
|
||||
</Typography>
|
||||
<FlexBox direction="flex-col" gap="gap-1" className="min-w-0 flex-1">
|
||||
<Typography tag="span" color="inverse">
|
||||
{children}
|
||||
</Typography>
|
||||
{description != null && (
|
||||
<Typography tag="span" variant="body-sm" color="inverse">
|
||||
{description}
|
||||
</Typography>
|
||||
)}
|
||||
</FlexBox>
|
||||
{action && (
|
||||
<Element
|
||||
tag="button"
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ import type { ShowToastOptions } from './types';
|
|||
* closes the toast. Returns the toast's id for `dismissToast`.
|
||||
*/
|
||||
export function showToast({
|
||||
id,
|
||||
message,
|
||||
action,
|
||||
duration,
|
||||
...props
|
||||
}: ShowToastOptions): string | number {
|
||||
return toast.custom(
|
||||
(id) => (
|
||||
(toastId) => (
|
||||
<Toast
|
||||
{...props}
|
||||
// The region already reads toasts politely; only an error keeps its own alert.
|
||||
|
|
@ -24,7 +25,7 @@ export function showToast({
|
|||
action && {
|
||||
label: action.label,
|
||||
onClick: () => {
|
||||
toast.dismiss(id);
|
||||
toast.dismiss(toastId);
|
||||
action.onClick();
|
||||
},
|
||||
}
|
||||
|
|
@ -34,6 +35,7 @@ export function showToast({
|
|||
</Toast>
|
||||
),
|
||||
{
|
||||
id,
|
||||
duration:
|
||||
duration ??
|
||||
(action ? TOAST_WITH_ACTION_DURATION_MS : TOAST_DURATION_MS),
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ export type ToastProps = {
|
|||
announce?: boolean;
|
||||
/** One line, past tense, no exclamation mark: «اشتراک شما فعال شد.» */
|
||||
children: ReactNode;
|
||||
/** A second line under it: a failed action's reason and what to do, or the reference code. */
|
||||
description?: ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
|
|
@ -32,6 +34,8 @@ export type ShowToastOptions = Omit<
|
|||
'announce' | 'children' | 'className'
|
||||
> & {
|
||||
message: ReactNode;
|
||||
/** A toast shown again under the same id replaces the old one instead of stacking. */
|
||||
id?: string;
|
||||
/** Defaults to 4 seconds, 6 with an action. */
|
||||
duration?: number;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { SkeletonRegion } from '../../atoms/skeleton';
|
||||
import { FigureSkeleton } from './components/FigureSkeleton';
|
||||
import { FormSkeleton } from './components/FormSkeleton';
|
||||
import { HeaderSkeleton } from './components/HeaderSkeleton';
|
||||
import { ListSkeleton } from './components/ListSkeleton';
|
||||
import { PostSkeleton } from './components/PostSkeleton';
|
||||
|
|
@ -44,6 +45,7 @@ export function SkeletonPreset({
|
|||
{preset === 'figure' && <FigureSkeleton />}
|
||||
{preset === 'list' && <ListSkeleton rows={n} avatar={avatar} />}
|
||||
{preset === 'table' && <TableSkeleton rows={n} columns={columns} />}
|
||||
{preset === 'form' && <FormSkeleton fields={n} />}
|
||||
</SkeletonRegion>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
import { FlexBox } from '../../../atoms/flex-box';
|
||||
import { Skeleton } from '../../../atoms/skeleton';
|
||||
import type { FormSkeletonProps } from '../types';
|
||||
|
||||
/**
|
||||
* A form step: the heading and its one-line description, n labelled fields, the full-width submit
|
||||
* button and the switch link under it. No card: it fills whatever frame the screen draws.
|
||||
*/
|
||||
export function FormSkeleton({ fields }: FormSkeletonProps) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-5" aria-hidden>
|
||||
<FlexBox direction="flex-col" gap="gap-2">
|
||||
<Skeleton className="h-6 w-[55%]" />
|
||||
<Skeleton className="w-[75%]" />
|
||||
</FlexBox>
|
||||
{Array.from({ length: fields }, (_, field) => (
|
||||
<FlexBox
|
||||
// Static placeholders that never reorder, so the index is a stable key.
|
||||
key={field}
|
||||
direction="flex-col"
|
||||
gap="gap-2"
|
||||
>
|
||||
<Skeleton className="w-24" />
|
||||
<Skeleton shape="rect" className="h-input-height w-full" />
|
||||
</FlexBox>
|
||||
))}
|
||||
<Skeleton shape="pill" className="h-control-lg w-full" />
|
||||
<Skeleton className="mx-auto w-40" />
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ export const PRESET_REPEATS: Partial<
|
|||
prediction: { initial: 1, max: 3 },
|
||||
list: { initial: 4, max: 4 },
|
||||
table: { initial: 5, max: 5 },
|
||||
form: { initial: 1, max: 6 },
|
||||
};
|
||||
|
||||
export const DEFAULT_TABLE_COLUMNS = 5;
|
||||
|
|
|
|||
|
|
@ -17,14 +17,17 @@ export type SkeletonPresetName =
|
|||
/** Admin tables, with a sunken header row. */
|
||||
| 'table'
|
||||
/** A money hero («قابل واریز») with two tiles under it. */
|
||||
| 'figure';
|
||||
| 'figure'
|
||||
/** A form step: heading, description, `count` fields, the submit button and a link. */
|
||||
| 'form';
|
||||
|
||||
export type SkeletonPresetProps = {
|
||||
/** The component the screen is waiting for. */
|
||||
preset: SkeletonPresetName;
|
||||
/**
|
||||
* Repeats, capped at one screen: posts and predictions (default 1, at most 3), list rows
|
||||
* (default 4, at most 4), table rows (default 5, at most 5). Other presets ignore it.
|
||||
* (default 4, at most 4), table rows (default 5, at most 5), form fields (default 1, at most 6).
|
||||
* Other presets ignore it.
|
||||
*/
|
||||
count?: number;
|
||||
/** `table` only (default 5). */
|
||||
|
|
@ -52,6 +55,10 @@ export type ListSkeletonProps = {
|
|||
avatar: boolean;
|
||||
};
|
||||
|
||||
export type FormSkeletonProps = {
|
||||
fields: number;
|
||||
};
|
||||
|
||||
export type TableSkeletonProps = {
|
||||
rows: number;
|
||||
columns: number;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,33 @@
|
|||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { useViewerStatus } from '../../../stores/auth';
|
||||
import { safeReturnPath } from '../../navigation';
|
||||
import type { GuestGuardProps } from './types';
|
||||
|
||||
/**
|
||||
* Wraps login and registration. A signed-in visitor goes on to `?redirect=` (a path on this site
|
||||
* only) or home; a guest sees the page. The skeleton covers the moment before the viewer is known.
|
||||
* 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
|
||||
* 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 router = useRouter();
|
||||
const [wasGuest, setWasGuest] = useState(false);
|
||||
// Remembered during render, so the render that turns member already knows.
|
||||
if (status === 'guest' && !wasGuest) setWasGuest(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (status !== 'member') return;
|
||||
if (status !== 'member' || wasGuest) return;
|
||||
const redirect = new URLSearchParams(window.location.search).get(
|
||||
'redirect',
|
||||
);
|
||||
router.replace(safeReturnPath(redirect));
|
||||
}, [status, router]);
|
||||
}, [status, wasGuest, router]);
|
||||
|
||||
return status === 'guest' ? children : fallback;
|
||||
const showsPage = status === 'guest' || (status === 'member' && wasGuest);
|
||||
return showsPage ? children : fallback;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
import { useSearchParams } from 'next/navigation';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import type { SignedInViewer } from '../../../features/auth';
|
||||
import { ROUTES, withReturnPath } from '../navigation';
|
||||
import { safeReturnPath } from '../return-path';
|
||||
import type { AuthRoutes } from '../types';
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
return useMemo(() => {
|
||||
const step = (path: string) => withReturnPath(path, redirect);
|
||||
return {
|
||||
login: step(ROUTES.login),
|
||||
loginVerify: step(ROUTES.loginVerify),
|
||||
register: {
|
||||
type: step(ROUTES.register.type),
|
||||
phone: step(ROUTES.register.phone),
|
||||
verify: step(ROUTES.register.verify),
|
||||
details: step(ROUTES.register.details),
|
||||
},
|
||||
profile: {
|
||||
investor: step(ROUTES.onboarding.investorProfile),
|
||||
creator: step(ROUTES.onboarding.creatorProfile),
|
||||
},
|
||||
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;
|
||||
},
|
||||
};
|
||||
}, [redirect]);
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
export { CHANNEL_PREFIX } from './constants';
|
||||
export { loginRoute, ROUTES } from './navigation';
|
||||
export { useAuthRoutes } from './hooks/use-auth-routes';
|
||||
export { loginRoute, ROUTES, withReturnPath } from './navigation';
|
||||
export { safeReturnPath } from './return-path';
|
||||
export type { AuthRoutes } from './types';
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ const channel = (username: string) =>
|
|||
export const ROUTES = {
|
||||
home: '/',
|
||||
login: '/auth/login',
|
||||
loginVerify: '/auth/login/verify',
|
||||
register: {
|
||||
type: '/auth/register',
|
||||
phone: '/auth/register/phone',
|
||||
verify: '/auth/register/verify',
|
||||
details: '/auth/register/details',
|
||||
},
|
||||
account: '/account',
|
||||
channel,
|
||||
post: (username: string, id: string) =>
|
||||
|
|
@ -34,7 +41,16 @@ export const ROUTES = {
|
|||
|
||||
/** `/auth/login?redirect=…`: auth returns to the page that asked for it. */
|
||||
export function loginRoute(returnTo?: string): string {
|
||||
return returnTo
|
||||
? `${ROUTES.login}?redirect=${encodeURIComponent(returnTo)}`
|
||||
: ROUTES.login;
|
||||
return withReturnPath(ROUTES.login, returnTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* An auth step's path that keeps `?redirect=`, so every step of login and registration returns
|
||||
* to the page that asked for it.
|
||||
*/
|
||||
export function withReturnPath(
|
||||
path: string,
|
||||
returnTo: string | null | undefined,
|
||||
): string {
|
||||
return returnTo ? `${path}?redirect=${encodeURIComponent(returnTo)}` : path;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
import type { SignedInViewer } from '../../features/auth';
|
||||
|
||||
/** The auth steps' paths with `?redirect=` kept, and where a signed-in person lands. */
|
||||
export type AuthRoutes = {
|
||||
login: string;
|
||||
loginVerify: string;
|
||||
register: {
|
||||
type: string;
|
||||
phone: string;
|
||||
verify: string;
|
||||
details: string;
|
||||
};
|
||||
/** Registration step 5, per account type. */
|
||||
profile: { investor: string; creator: string };
|
||||
landing: (viewer: SignedInViewer) => string;
|
||||
};
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Link } from '@lumina/island/atoms/link';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import { TextInput } from '@lumina/island/molecules/text-input';
|
||||
import type { FormEvent } from 'react';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useLoginPage } from '../../../../../../../features/auth';
|
||||
import { translateMessage } from '../../../../../../../shared/utils';
|
||||
import { useAuthRoutes } from '../../../../../../navigation';
|
||||
import { SupportEntry } from '../../../../organisms/support-entry';
|
||||
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.
|
||||
*/
|
||||
export function LoginStep({ size, supportPlacement }: LoginStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const routes = useAuthRoutes();
|
||||
const {
|
||||
form,
|
||||
submit,
|
||||
isSubmitting,
|
||||
formError,
|
||||
isUnknownPhone,
|
||||
registerHref,
|
||||
carryPhone,
|
||||
} = useLoginPage({
|
||||
codeHref: routes.loginVerify,
|
||||
registerHref: routes.register.type,
|
||||
});
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
{formError && (
|
||||
<Banner tone="danger" title={t('phone.send-failed-banner')}>
|
||||
{formError}
|
||||
</Banner>
|
||||
)}
|
||||
<FlexBox direction="flex-col" className="gap-1.5">
|
||||
<Typography tag="h1" variant="heading-md">
|
||||
{t('login.title')}
|
||||
</Typography>
|
||||
<Typography color="secondary">{t('login.description')}</Typography>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
tag="form"
|
||||
noValidate
|
||||
direction="flex-col"
|
||||
gap="gap-5"
|
||||
onSubmit={(event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
void submit();
|
||||
}}
|
||||
>
|
||||
<FlexBox direction="flex-col" alignItems="items-start" gap="gap-1">
|
||||
<Controller
|
||||
name="phone"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
type="tel"
|
||||
dir="ltr"
|
||||
inputMode="numeric"
|
||||
autoComplete="tel"
|
||||
label={t('phone.label')}
|
||||
placeholder={t('phone.placeholder')}
|
||||
error={translateMessage(t, fieldState.error?.message)}
|
||||
className="w-full"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{isUnknownPhone && (
|
||||
<Link
|
||||
href={registerHref}
|
||||
onClick={carryPhone}
|
||||
icon="arrow-left"
|
||||
standalone
|
||||
>
|
||||
{t('login.register-with-phone')}
|
||||
</Link>
|
||||
)}
|
||||
</FlexBox>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="primary"
|
||||
size={size}
|
||||
block
|
||||
isLoading={isSubmitting}
|
||||
>
|
||||
{t('login.submit')}
|
||||
</Button>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-center"
|
||||
className="gap-1.5"
|
||||
>
|
||||
<Typography tag="span" variant="body-sm" color="secondary">
|
||||
{t('login.no-account')}
|
||||
</Typography>
|
||||
<Link href={registerHref} onClick={carryPhone}>
|
||||
{t('login.register')}
|
||||
</Link>
|
||||
</FlexBox>
|
||||
<FlexBox justifyContent="justify-center" className="mt-auto">
|
||||
<SupportEntry trigger="link" placement={supportPlacement} />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { LoginStep } from './LoginStep';
|
||||
export type { LoginStepProps } from './types';
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import type { SupportEntryProps } from '../../../../organisms/support-entry';
|
||||
|
||||
export type LoginStepProps = {
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
};
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
'use client';
|
||||
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
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.
|
||||
*/
|
||||
export function LoginVerifyStep({
|
||||
size,
|
||||
supportPlacement,
|
||||
}: LoginVerifyStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const routes = useAuthRoutes();
|
||||
const model = useLoginVerifyPage({
|
||||
phoneHref: routes.login,
|
||||
landing: routes.landing,
|
||||
});
|
||||
|
||||
if (model.view === 'suspended') {
|
||||
return <SuspendedNotice size={size} supportPlacement={supportPlacement} />;
|
||||
}
|
||||
if (!model.phone) {
|
||||
return <SkeletonPreset preset="form" label={t('loading')} />;
|
||||
}
|
||||
return (
|
||||
<CodeStep
|
||||
model={model}
|
||||
submitLabel={t('login.verify-submit')}
|
||||
editHref={routes.login}
|
||||
size={size}
|
||||
supportPlacement={supportPlacement}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
'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>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { LoginVerifyStep } from './LoginVerifyStep';
|
||||
export type { LoginVerifyStepProps } from './types';
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import type { SupportEntryProps } from '../../../../../organisms/support-entry';
|
||||
|
||||
export type LoginVerifyStepProps = {
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
};
|
||||
|
||||
export type SuspendedNoticeProps = LoginVerifyStepProps;
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Link } from '@lumina/island/atoms/link';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import { OtpInput } from '@lumina/island/molecules/otp-input';
|
||||
import { ResendCode } from '@lumina/island/molecules/resend-code';
|
||||
import type { FormEvent } from 'react';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { formatMobile, translateMessage } from '../../../../../../shared/utils';
|
||||
import { SupportEntry } from '../../../organisms/support-entry';
|
||||
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.
|
||||
*/
|
||||
export function CodeStep({
|
||||
model,
|
||||
submitLabel,
|
||||
editHref,
|
||||
size,
|
||||
supportPlacement,
|
||||
progress,
|
||||
}: CodeStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const { form, status, attempt, submit, complete, resend } = model;
|
||||
const isBlocked = status === 'blocked';
|
||||
const formError = form.formState.errors.root?.server?.message;
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
{isBlocked && (
|
||||
<Banner tone="warning" title={t('code.blocked-title')}>
|
||||
{t('code.blocked-description')}
|
||||
</Banner>
|
||||
)}
|
||||
{formError && !isBlocked && <Banner tone="danger">{formError}</Banner>}
|
||||
{progress}
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
alignItems="items-start"
|
||||
className="gap-1.5"
|
||||
>
|
||||
<Typography tag="h1" variant="heading-md">
|
||||
{t('code.title')}
|
||||
</Typography>
|
||||
<Typography color="secondary">
|
||||
{t('code.description', {
|
||||
// Isolated left to right inside the sentence.
|
||||
phone: `${formatMobile(model.phone ?? '')}`,
|
||||
})}
|
||||
</Typography>
|
||||
<Link href={editHref} iconStart="edit" standalone>
|
||||
{t('code.edit-phone')}
|
||||
</Link>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
tag="form"
|
||||
noValidate
|
||||
direction="flex-col"
|
||||
gap="gap-5"
|
||||
onSubmit={(event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
void submit();
|
||||
}}
|
||||
>
|
||||
<Controller
|
||||
name="code"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<OtpInput
|
||||
// A new key empties the cells' own state and focuses the first cell again.
|
||||
key={attempt}
|
||||
name={field.name}
|
||||
value={field.value}
|
||||
onChange={field.onChange}
|
||||
onComplete={complete}
|
||||
label={t('code.label')}
|
||||
error={translateMessage(t, fieldState.error?.message)}
|
||||
status={status === 'verifying' ? 'verifying' : 'idle'}
|
||||
disabled={isBlocked || status === 'verifying'}
|
||||
// The step exists to type the code, so focus starts in the cells.
|
||||
// oxlint-disable-next-line jsx-a11y/no-autofocus
|
||||
autoFocus
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<FlexBox justifyContent="justify-center">
|
||||
<ResendCode
|
||||
// A new code (or block) starts a new wait, and its announcement plays again.
|
||||
key={resend.endsAt}
|
||||
endsAt={resend.endsAt}
|
||||
status={
|
||||
resend.phase === 'auto'
|
||||
? isBlocked
|
||||
? 'limited'
|
||||
: 'auto'
|
||||
: resend.phase
|
||||
}
|
||||
onResend={resend.onResend}
|
||||
labels={{
|
||||
counting: t('code.resend.counting'),
|
||||
ready: t('code.resend.ready'),
|
||||
sending: t('code.resend.sending'),
|
||||
sent: t('code.resend.sent'),
|
||||
limited: t('code.resend.limited'),
|
||||
hint: t('code.resend.hint'),
|
||||
readyAnnouncement: t('code.resend.ready-announcement'),
|
||||
}}
|
||||
/>
|
||||
</FlexBox>
|
||||
{!isBlocked && (
|
||||
<Button
|
||||
type="submit"
|
||||
variant="primary"
|
||||
size={size}
|
||||
block
|
||||
isLoading={status === 'verifying'}
|
||||
>
|
||||
{submitLabel}
|
||||
</Button>
|
||||
)}
|
||||
</FlexBox>
|
||||
<FlexBox justifyContent="justify-center" className="mt-auto">
|
||||
<SupportEntry trigger="link" placement={supportPlacement} />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { CodeStep } from './CodeStep';
|
||||
export type { CodeStepProps } from './types';
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
import type { CodeStepModel } from '../../../../../../features/auth';
|
||||
import type { SupportEntryProps } from '../../../organisms/support-entry';
|
||||
|
||||
export type CodeStepProps = {
|
||||
/** The page model's code step (`useCodeStep`). */
|
||||
model: CodeStepModel;
|
||||
/** «ورود» for login, «تأیید و ادامه» for registration. */
|
||||
submitLabel: string;
|
||||
/** «ویرایش شماره»: back to the number step, which keeps the number. */
|
||||
editHref: string;
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
/** Registration's step bar, above the heading. */
|
||||
progress?: ReactNode;
|
||||
};
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
'use client';
|
||||
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useRegisterDetailsPage } from '../../../../../../../../features/auth';
|
||||
import { useAuthRoutes } from '../../../../../../../navigation';
|
||||
import { CreatorIdentityForm } from './components/CreatorIdentityForm';
|
||||
import { InvestorDetailsForm } from './components/InvestorDetailsForm';
|
||||
import type { RegisterDetailsStepProps } from './types';
|
||||
|
||||
/**
|
||||
* Registration step 4, on the 15-minute token: account details for an investor, identity for a
|
||||
* creator. There is no back: the code is used. Without a token (after a reload) it waits in its
|
||||
* skeleton while the page sends the person back to the number.
|
||||
*/
|
||||
export function RegisterDetailsStep(props: RegisterDetailsStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const routes = useAuthRoutes();
|
||||
const page = useRegisterDetailsPage({
|
||||
phoneHref: routes.register.phone,
|
||||
codeHref: routes.register.verify,
|
||||
});
|
||||
|
||||
if (!page.role || page.expiresAt === null) {
|
||||
return <SkeletonPreset preset="form" count={3} label={t('loading')} />;
|
||||
}
|
||||
const partOptions = {
|
||||
profileHref: routes.profile[page.role],
|
||||
onExpired: page.expire,
|
||||
};
|
||||
return page.role === 'creator' ? (
|
||||
<CreatorIdentityForm {...props} page={page} partOptions={partOptions} />
|
||||
) : (
|
||||
<InvestorDetailsForm {...props} page={page} partOptions={partOptions} />
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Icon } from '@lumina/island/atoms/icon';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { FileField } from '@lumina/island/molecules/file-field';
|
||||
import { TextInput } from '@lumina/island/molecules/text-input';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useId } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useCreatorIdentityPart } from '../../../../../../../../../features/auth';
|
||||
import type { IdCardSide } from '../../../../../../../../../features/auth';
|
||||
import { translateMessage } from '../../../../../../../../../shared/utils';
|
||||
import { ID_CARD_IMAGE } from '../../../../../../../../../shared/validations';
|
||||
import type { DetailsFormProps } from '../types';
|
||||
import { DetailsFrame } from './DetailsFrame';
|
||||
import { NameFields } from './NameFields';
|
||||
import { TermsLine } from './TermsLine';
|
||||
import { UsernameField } from './UsernameField';
|
||||
|
||||
const ID_CARD_SIDES = [
|
||||
{ side: 'idCardFront', label: 'id-card-front' },
|
||||
{ side: 'idCardBack', label: 'id-card-back' },
|
||||
] as const satisfies readonly { side: IdCardSide; label: string }[];
|
||||
|
||||
const BYTES_PER_MB = 1024 * 1024;
|
||||
|
||||
/** A labelled group with its privacy line: what investors see, and what only the review sees. */
|
||||
function Group({
|
||||
title,
|
||||
note,
|
||||
noteIcon,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
note: string;
|
||||
noteIcon?: 'lock';
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const titleId = useId();
|
||||
return (
|
||||
<FlexBox
|
||||
tag="section"
|
||||
aria-labelledby={titleId}
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
>
|
||||
<FlexBox direction="flex-col" gap="gap-1">
|
||||
<Typography tag="h2" variant="heading-sm" id={titleId}>
|
||||
{title}
|
||||
</Typography>
|
||||
<FlexBox alignItems="items-center" gap="gap-1">
|
||||
{noteIcon && (
|
||||
<Icon
|
||||
name={noteIcon}
|
||||
size={16}
|
||||
className="flex-none text-text-secondary"
|
||||
/>
|
||||
)}
|
||||
<Typography tag="span" variant="body-sm" color="secondary">
|
||||
{note}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
{children}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 4 for a creator: the public username, then the private identity (names, national code,
|
||||
* both sides of the ID card) for the admin review. The images upload with a bar and can be
|
||||
* cancelled; a failure keeps every value and image.
|
||||
*/
|
||||
export function CreatorIdentityForm(props: DetailsFormProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const {
|
||||
form,
|
||||
submit,
|
||||
isSubmitting,
|
||||
formError,
|
||||
pickImage,
|
||||
progress,
|
||||
cancelUpload,
|
||||
draft,
|
||||
} = useCreatorIdentityPart(props.partOptions);
|
||||
|
||||
return (
|
||||
<DetailsFrame
|
||||
{...props}
|
||||
title={t('register.identity.title')}
|
||||
description={t('register.identity.description')}
|
||||
formError={formError}
|
||||
draft={draft}
|
||||
onSubmit={() => void submit()}
|
||||
footer={
|
||||
<>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="primary"
|
||||
size={props.size}
|
||||
block
|
||||
isLoading={isSubmitting}
|
||||
>
|
||||
{t('register.identity.submit')}
|
||||
</Button>
|
||||
{progress !== undefined && (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size={props.size}
|
||||
block
|
||||
onClick={cancelUpload}
|
||||
>
|
||||
{t('register.identity.cancel')}
|
||||
</Button>
|
||||
)}
|
||||
<TermsLine before={t('register.identity.terms-before')} />
|
||||
</>
|
||||
}
|
||||
>
|
||||
<Group
|
||||
title={t('register.identity.public-title')}
|
||||
note={t('register.identity.public-description')}
|
||||
>
|
||||
<UsernameField
|
||||
control={form.control}
|
||||
name="username"
|
||||
placeholder="ali_trader"
|
||||
hint={t('register.identity.username-note')}
|
||||
/>
|
||||
</Group>
|
||||
<Group
|
||||
title={t('register.identity.private-title')}
|
||||
note={t('register.identity.private-description')}
|
||||
noteIcon="lock"
|
||||
>
|
||||
<NameFields control={form.control} isPaired={props.size === 'md'} />
|
||||
<Controller
|
||||
name="nationalId"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
dir="ltr"
|
||||
inputMode="numeric"
|
||||
autoComplete="off"
|
||||
maxLength={10}
|
||||
label={t('register.fields.national-id')}
|
||||
placeholder={t('register.fields.national-id-placeholder')}
|
||||
error={translateMessage(t, fieldState.error?.message)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{ID_CARD_SIDES.map(({ side, label }) => (
|
||||
<Controller
|
||||
key={side}
|
||||
name={side}
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<FileField
|
||||
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')}
|
||||
size={
|
||||
field.value &&
|
||||
t('register.fields.file-size', {
|
||||
size: number(field.value.size / BYTES_PER_MB, 1),
|
||||
})
|
||||
}
|
||||
error={translateMessage(t, fieldState.error?.message)}
|
||||
progress={progress}
|
||||
disabled={isSubmitting}
|
||||
labels={{
|
||||
pick: t('register.fields.id-card-pick'),
|
||||
rules: t('register.fields.id-card-rules'),
|
||||
remove: t('register.fields.id-card-remove'),
|
||||
uploading: (percent) =>
|
||||
t('register.fields.id-card-uploading', { percent }),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</Group>
|
||||
</DetailsFrame>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import type { FormEvent } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SupportEntry } from '../../../../../../organisms/support-entry';
|
||||
import { RegisterProgress } from '../../../../organisms/register-progress';
|
||||
import type { DetailsFrameProps } from '../types';
|
||||
import { ExpiryHalt } from './ExpiryHalt';
|
||||
import { ExpiryWarning } from './ExpiryWarning';
|
||||
|
||||
/**
|
||||
* What both account types' step 4 share: the token's warning and halt, the server-failure banner,
|
||||
* the step bar and heading, the form with its submit under the fields, and support.
|
||||
*/
|
||||
export function DetailsFrame({
|
||||
page,
|
||||
title,
|
||||
description,
|
||||
formError,
|
||||
footer,
|
||||
draft,
|
||||
onSubmit,
|
||||
supportPlacement,
|
||||
haltPlacement,
|
||||
children,
|
||||
}: DetailsFrameProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
{page.phase === 'warning' && page.expiresAt !== null && (
|
||||
<ExpiryWarning expiresAt={page.expiresAt} />
|
||||
)}
|
||||
{formError && (
|
||||
<Banner tone="danger" title={t('register.details.network-title')}>
|
||||
{formError}
|
||||
</Banner>
|
||||
)}
|
||||
<RegisterProgress current={3} role={page.role} />
|
||||
<FlexBox direction="flex-col" className="gap-1.5">
|
||||
<Typography tag="h1" variant="heading-md">
|
||||
{title}
|
||||
</Typography>
|
||||
<Typography color="secondary">{description}</Typography>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
tag="form"
|
||||
noValidate
|
||||
direction="flex-col"
|
||||
gap="gap-6"
|
||||
onSubmit={(event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
onSubmit();
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
{footer}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
<FlexBox justifyContent="justify-center" className="mt-auto">
|
||||
<SupportEntry trigger="link" placement={supportPlacement} />
|
||||
</FlexBox>
|
||||
{page.phase === 'expired' && (
|
||||
<ExpiryHalt
|
||||
placement={haltPlacement}
|
||||
isSending={page.isReverifying}
|
||||
onConfirm={() => page.reverify(draft())}
|
||||
/>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { Modal } from '@lumina/island/molecules/modal';
|
||||
import { Sheet } from '@lumina/island/molecules/sheet';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { ExpiryHaltProps } from '../types';
|
||||
|
||||
/**
|
||||
* The registration token ran out: a blocking halt with no ✕ and no cancel. The one way on is a
|
||||
* new code to the same number; after it, step 4 comes back with everything typed.
|
||||
*/
|
||||
export function ExpiryHalt({
|
||||
placement,
|
||||
isSending,
|
||||
onConfirm,
|
||||
}: ExpiryHaltProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const title = t('register.expiry.title');
|
||||
const description = t('register.expiry.description');
|
||||
const button = (
|
||||
<Button
|
||||
variant="primary"
|
||||
size={placement === 'sheet' ? 'lg' : 'md'}
|
||||
block
|
||||
isLoading={isSending}
|
||||
onClick={onConfirm}
|
||||
>
|
||||
{t('register.expiry.submit')}
|
||||
</Button>
|
||||
);
|
||||
|
||||
return placement === 'sheet' ? (
|
||||
<Sheet open title={title} dismissible={false} alert footer={button}>
|
||||
{description}
|
||||
</Sheet>
|
||||
) : (
|
||||
<Modal open title={title} dismissible={false} alert actions={button}>
|
||||
{description}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
'use client';
|
||||
|
||||
import { Countdown } from '@lumina/island/atoms/countdown';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
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.
|
||||
*/
|
||||
export function ExpiryWarning({ expiresAt }: ExpiryWarningProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
|
||||
return (
|
||||
<Banner
|
||||
tone="warning"
|
||||
icon="clock"
|
||||
title={t('register.expiry.warning-title')}
|
||||
>
|
||||
{t('register.expiry.warning-before')}{' '}
|
||||
<Countdown kind="otp" endsAt={expiresAt} />{' '}
|
||||
{t('register.expiry.warning-after')}
|
||||
</Banner>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useInvestorDetailsPart } from '../../../../../../../../../features/auth';
|
||||
import type { DetailsFormProps } from '../types';
|
||||
import { DetailsFrame } from './DetailsFrame';
|
||||
import { NameFields } from './NameFields';
|
||||
import { TermsLine } from './TermsLine';
|
||||
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 } =
|
||||
useInvestorDetailsPart(props.partOptions);
|
||||
|
||||
return (
|
||||
<DetailsFrame
|
||||
{...props}
|
||||
title={t('register.details.title')}
|
||||
description={t('register.details.description')}
|
||||
formError={formError}
|
||||
draft={draft}
|
||||
onSubmit={() => void submit()}
|
||||
footer={
|
||||
<>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="primary"
|
||||
size={props.size}
|
||||
block
|
||||
isLoading={isSubmitting}
|
||||
>
|
||||
{t('register.details.submit')}
|
||||
</Button>
|
||||
<TermsLine before={t('register.details.terms-before')} />
|
||||
</>
|
||||
}
|
||||
>
|
||||
<NameFields control={form.control} isPaired={props.size === 'md'} />
|
||||
<UsernameField
|
||||
control={form.control}
|
||||
name="username"
|
||||
placeholder={t('register.fields.username-placeholder')}
|
||||
hint={t('register.fields.username-hint')}
|
||||
/>
|
||||
</DetailsFrame>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
'use client';
|
||||
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { TextInput } from '@lumina/island/molecules/text-input';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import type { FieldValues, Path } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { translateMessage } from '../../../../../../../../../shared/utils';
|
||||
import type { NameFieldsProps } from '../types';
|
||||
|
||||
const NAME_FIELDS = [
|
||||
{ name: 'firstName', label: 'first-name', autoComplete: 'given-name' },
|
||||
{ name: 'lastName', label: 'last-name', autoComplete: 'family-name' },
|
||||
] as const;
|
||||
|
||||
/** First and last name in Persian: stacked on mobile, side by side on desktop. Private. */
|
||||
export function NameFields<T extends FieldValues>({
|
||||
control,
|
||||
isPaired,
|
||||
}: NameFieldsProps<T>) {
|
||||
const { t } = useTranslation('auth');
|
||||
|
||||
return (
|
||||
<GridBox cols={isPaired ? 'grid-cols-2' : 'grid-cols-1'} gap="gap-5">
|
||||
{NAME_FIELDS.map(({ name, label, autoComplete }) => (
|
||||
<Controller
|
||||
key={name}
|
||||
name={name as Path<T>}
|
||||
control={control}
|
||||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
value={field.value as string}
|
||||
autoComplete={autoComplete}
|
||||
label={t(`register.fields.${label}`)}
|
||||
placeholder={t(`register.fields.${label}-placeholder`)}
|
||||
error={translateMessage(t, fieldState.error?.message)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</GridBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { TermsLineProps } from '../types';
|
||||
|
||||
/**
|
||||
* Accepting the rules by submitting, with no checkbox. The rules page isn't designed yet, so the
|
||||
* line names it without a link.
|
||||
*/
|
||||
export function TermsLine({ before }: TermsLineProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
|
||||
return (
|
||||
<Typography variant="body-sm" color="secondary" className="text-center">
|
||||
{before}
|
||||
{t('register.terms-link')}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
'use client';
|
||||
|
||||
import { TextInput } from '@lumina/island/molecules/text-input';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import type { FieldValues } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
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. */
|
||||
export function UsernameField<T extends FieldValues>({
|
||||
control,
|
||||
name,
|
||||
placeholder,
|
||||
hint,
|
||||
}: 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)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { RegisterDetailsStep } from './RegisterDetailsStep';
|
||||
export type { RegisterDetailsStepProps } from './types';
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
import type { ReactNode } from 'react';
|
||||
import type { Control, FieldValues, Path } from 'react-hook-form';
|
||||
|
||||
import type {
|
||||
RegisterDetailsPageModel,
|
||||
UseDetailsPartOptions,
|
||||
} from '../../../../../../../../features/auth';
|
||||
import type { SupportEntryProps } from '../../../../../organisms/support-entry';
|
||||
|
||||
export type RegisterDetailsStepProps = {
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
/** The halt when the token runs out: a bottom sheet on mobile, a modal on desktop. */
|
||||
haltPlacement: 'sheet' | 'modal';
|
||||
};
|
||||
|
||||
/** What each account type's form gets from the step. */
|
||||
export type DetailsFormProps = RegisterDetailsStepProps & {
|
||||
page: RegisterDetailsPageModel;
|
||||
partOptions: UseDetailsPartOptions;
|
||||
};
|
||||
|
||||
export type DetailsFrameProps = DetailsFormProps & {
|
||||
/** Step 4's name in the bar and the heading. */
|
||||
title: string;
|
||||
description: string;
|
||||
formError: string | undefined;
|
||||
/** The submit button and what sits under it. */
|
||||
footer: ReactNode;
|
||||
/** The values to keep for the halt's new code. */
|
||||
draft: () => Parameters<RegisterDetailsPageModel['reverify']>[0];
|
||||
onSubmit: () => void;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export type ExpiryWarningProps = {
|
||||
expiresAt: number;
|
||||
};
|
||||
|
||||
export type ExpiryHaltProps = {
|
||||
placement: RegisterDetailsStepProps['haltPlacement'];
|
||||
isSending: boolean;
|
||||
onConfirm: () => void;
|
||||
};
|
||||
|
||||
export type TermsLineProps = {
|
||||
/** «با ساخت حساب، » or «با ثبت اطلاعات، ». */
|
||||
before: string;
|
||||
};
|
||||
|
||||
export type UsernameFieldProps<T extends FieldValues> = {
|
||||
control: Control<T>;
|
||||
name: Path<T>;
|
||||
placeholder: string;
|
||||
/** A rule shown before typing, replaced by an error. */
|
||||
hint?: string;
|
||||
};
|
||||
|
||||
export type NameFieldsProps<T extends FieldValues> = {
|
||||
control: Control<T>;
|
||||
/** Side by side on desktop. */
|
||||
isPaired: boolean;
|
||||
};
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
'use client';
|
||||
|
||||
import { StepProgress } from '@lumina/island/molecules/step-progress';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { RegisterProgressProps } from './types';
|
||||
|
||||
/** «مرحله n از ۵» over every registration step; step 4's name follows the account type. */
|
||||
export function RegisterProgress({ current, role }: RegisterProgressProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const steps = [
|
||||
t('register.steps.type'),
|
||||
t('register.steps.phone'),
|
||||
t('register.steps.code'),
|
||||
role === 'creator'
|
||||
? t('register.steps.identity')
|
||||
: t('register.steps.details'),
|
||||
t('register.steps.profile'),
|
||||
];
|
||||
|
||||
return (
|
||||
<StepProgress
|
||||
steps={steps}
|
||||
current={current}
|
||||
label={t('register.steps-label')}
|
||||
countLabel={(step, total) => t('register.step-count', { step, total })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { RegisterProgress } from './RegisterProgress';
|
||||
export type { RegisterProgressProps } from './types';
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import type { UserRole } from '../../../../../../../features/auth';
|
||||
|
||||
export type RegisterProgressProps = {
|
||||
/** 0-based: account type, number, code, details or identity, profile. */
|
||||
current: number;
|
||||
/** Names step 4: «احراز هویت» for a creator, «اطلاعات حساب» otherwise. */
|
||||
role: UserRole | null;
|
||||
};
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Icon } from '@lumina/island/atoms/icon';
|
||||
import { Link } from '@lumina/island/atoms/link';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { ChoiceCard } from '@lumina/island/molecules/choice-card';
|
||||
import type { FormEvent } from 'react';
|
||||
import { Controller, useWatch } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useRegisterTypePage } from '../../../../../../../features/auth';
|
||||
import type { UserRole } from '../../../../../../../features/auth';
|
||||
import { translateMessage } from '../../../../../../../shared/utils';
|
||||
import { useAuthRoutes } from '../../../../../../navigation';
|
||||
import { SupportEntry } from '../../../../organisms/support-entry';
|
||||
import { RegisterProgress } from '../register-progress';
|
||||
import type { RegisterTypeStepProps } from './types';
|
||||
|
||||
const ACCOUNT_TYPES = [
|
||||
{ value: 'investor', icon: 'investor' },
|
||||
{ value: 'creator', icon: 'analyst' },
|
||||
] as const satisfies readonly { value: UserRole; icon: string }[];
|
||||
|
||||
/**
|
||||
* Registration step 1: two cards, one line each on what the account is for, nothing
|
||||
* pre-selected. The account type can't change later, so the note says so before the choice.
|
||||
*/
|
||||
export function RegisterTypeStep({
|
||||
size,
|
||||
supportPlacement,
|
||||
}: RegisterTypeStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const routes = useAuthRoutes();
|
||||
const { form, submit } = useRegisterTypePage({
|
||||
phoneHref: routes.register.phone,
|
||||
});
|
||||
const role = useWatch({ control: form.control, name: 'role' });
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
<RegisterProgress
|
||||
current={0}
|
||||
role={role === 'creator' || role === 'investor' ? role : null}
|
||||
/>
|
||||
<FlexBox direction="flex-col" className="gap-1.5">
|
||||
<Typography tag="h1" variant="heading-md">
|
||||
{t('register.type.title')}
|
||||
</Typography>
|
||||
<Typography color="secondary">
|
||||
{t('register.type.description')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
tag="form"
|
||||
noValidate
|
||||
direction="flex-col"
|
||||
gap="gap-5"
|
||||
onSubmit={(event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
void submit();
|
||||
}}
|
||||
>
|
||||
<Controller
|
||||
name="role"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => {
|
||||
const error = translateMessage(t, fieldState.error?.message);
|
||||
return (
|
||||
<FlexBox
|
||||
tag="fieldset"
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
className="m-0 min-w-0 border-0 p-0"
|
||||
>
|
||||
<Typography tag="legend" className="sr-only">
|
||||
{t('register.type.label')}
|
||||
</Typography>
|
||||
{ACCOUNT_TYPES.map(({ value, icon }) => (
|
||||
<ChoiceCard
|
||||
key={value}
|
||||
name={field.name}
|
||||
value={value}
|
||||
icon={icon}
|
||||
checked={field.value === value}
|
||||
onChange={() => field.onChange(value)}
|
||||
title={t(`register.type.${value}`)}
|
||||
description={t(`register.type.${value}-description`)}
|
||||
invalid={error !== undefined}
|
||||
/>
|
||||
))}
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-1"
|
||||
role={error ? 'alert' : undefined}
|
||||
>
|
||||
<Icon
|
||||
name={error ? 'alert' : 'info'}
|
||||
size={16}
|
||||
className={error ? 'text-danger' : 'text-text-secondary'}
|
||||
/>
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="caption"
|
||||
color={error ? 'danger' : 'secondary'}
|
||||
>
|
||||
{error ?? t('register.type.note')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Button type="submit" variant="primary" size={size} block>
|
||||
{t('register.type.submit')}
|
||||
</Button>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-center"
|
||||
className="gap-1.5"
|
||||
>
|
||||
<Typography tag="span" variant="body-sm" color="secondary">
|
||||
{t('register.has-account')}
|
||||
</Typography>
|
||||
<Link href={routes.login}>{t('register.login')}</Link>
|
||||
</FlexBox>
|
||||
<FlexBox justifyContent="justify-center" className="mt-auto">
|
||||
<SupportEntry trigger="link" placement={supportPlacement} />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { RegisterTypeStep } from './RegisterTypeStep';
|
||||
export type { RegisterTypeStepProps } from './types';
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import type { SupportEntryProps } from '../../../../organisms/support-entry';
|
||||
|
||||
export type RegisterTypeStepProps = {
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
};
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Icon } from '@lumina/island/atoms/icon';
|
||||
import { Link } from '@lumina/island/atoms/link';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import { TextInput } from '@lumina/island/molecules/text-input';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import type { FormEvent } from 'react';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useRegisterPhonePage } from '../../../../../../../../features/auth';
|
||||
import { translateMessage } from '../../../../../../../../shared/utils';
|
||||
import { useAuthRoutes } from '../../../../../../../navigation';
|
||||
import { SupportEntry } from '../../../../../organisms/support-entry';
|
||||
import { RegisterProgress } from '../../../organisms/register-progress';
|
||||
import type { RegisterPhoneStepProps } from './types';
|
||||
|
||||
/**
|
||||
* Registration step 2: the number, with the chosen account type still in view and «تغییر» back
|
||||
* to step 1. A number that already has an account offers to sign in with it.
|
||||
*/
|
||||
export function RegisterPhoneStep({
|
||||
size,
|
||||
supportPlacement,
|
||||
}: RegisterPhoneStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const routes = useAuthRoutes();
|
||||
const {
|
||||
role,
|
||||
form,
|
||||
submit,
|
||||
isSubmitting,
|
||||
formError,
|
||||
isTakenPhone,
|
||||
loginWithPhone,
|
||||
isLoggingIn,
|
||||
carryPhone,
|
||||
} = useRegisterPhonePage({
|
||||
typeHref: routes.register.type,
|
||||
codeHref: routes.register.verify,
|
||||
loginCodeHref: routes.loginVerify,
|
||||
});
|
||||
|
||||
if (!role) return <SkeletonPreset preset="form" label={t('loading')} />;
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
|
||||
{formError && (
|
||||
<Banner tone="danger" title={t('phone.send-failed-banner')}>
|
||||
{formError}
|
||||
</Banner>
|
||||
)}
|
||||
<RegisterProgress current={1} role={role} />
|
||||
<FlexBox direction="flex-col" className="gap-1.5">
|
||||
<Typography tag="h1" variant="heading-md">
|
||||
{t('register.phone.title')}
|
||||
</Typography>
|
||||
<Typography color="secondary">
|
||||
{t('register.phone.description')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-2"
|
||||
className="rounded-md bg-surface-sunken ps-3 pe-1"
|
||||
>
|
||||
<Icon
|
||||
name={role === 'creator' ? 'analyst' : 'investor'}
|
||||
className="flex-none text-text-secondary"
|
||||
/>
|
||||
<Typography tag="span" variant="body-sm" className="flex-1">
|
||||
{role === 'creator'
|
||||
? t('register.phone.as-creator')
|
||||
: t('register.phone.as-investor')}
|
||||
</Typography>
|
||||
<Link href={routes.register.type} standalone className="px-2">
|
||||
{t('register.phone.change')}
|
||||
</Link>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
tag="form"
|
||||
noValidate
|
||||
direction="flex-col"
|
||||
gap="gap-5"
|
||||
onSubmit={(event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
void submit();
|
||||
}}
|
||||
>
|
||||
<FlexBox direction="flex-col" alignItems="items-start" gap="gap-1">
|
||||
<Controller
|
||||
name="phone"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
type="tel"
|
||||
dir="ltr"
|
||||
inputMode="numeric"
|
||||
autoComplete="tel"
|
||||
label={t('phone.label')}
|
||||
placeholder={t('phone.placeholder')}
|
||||
error={translateMessage(t, fieldState.error?.message)}
|
||||
className="w-full"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{isTakenPhone && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
iconEnd="arrow-left"
|
||||
isLoading={isLoggingIn}
|
||||
onClick={loginWithPhone}
|
||||
className="-ms-3"
|
||||
>
|
||||
{t('register.login-with-phone')}
|
||||
</Button>
|
||||
)}
|
||||
</FlexBox>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="primary"
|
||||
size={size}
|
||||
block
|
||||
isLoading={isSubmitting}
|
||||
>
|
||||
{t('register.phone.submit')}
|
||||
</Button>
|
||||
</FlexBox>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-center"
|
||||
className="gap-1.5"
|
||||
>
|
||||
<Typography tag="span" variant="body-sm" color="secondary">
|
||||
{t('register.has-account')}
|
||||
</Typography>
|
||||
<Link href={routes.login} onClick={carryPhone}>
|
||||
{t('register.login')}
|
||||
</Link>
|
||||
</FlexBox>
|
||||
<FlexBox justifyContent="justify-center" className="mt-auto">
|
||||
<SupportEntry trigger="link" placement={supportPlacement} />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { RegisterPhoneStep } from './RegisterPhoneStep';
|
||||
export type { RegisterPhoneStepProps } from './types';
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import type { SupportEntryProps } from '../../../../../organisms/support-entry';
|
||||
|
||||
export type RegisterPhoneStepProps = {
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
};
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
'use client';
|
||||
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useRegisterVerifyPage } from '../../../../../../../../features/auth';
|
||||
import { useAuthRoutes } from '../../../../../../../navigation';
|
||||
import { CodeStep } from '../../../../organisms/code-step';
|
||||
import { RegisterProgress } from '../../../organisms/register-progress';
|
||||
import type { RegisterVerifyStepProps } from './types';
|
||||
|
||||
/**
|
||||
* Registration step 3: login's code step with the step bar and «تأیید و ادامه». A verified code
|
||||
* opens step 4 on the 15-minute registration token.
|
||||
*/
|
||||
export function RegisterVerifyStep({
|
||||
size,
|
||||
supportPlacement,
|
||||
}: RegisterVerifyStepProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const routes = useAuthRoutes();
|
||||
const model = useRegisterVerifyPage({
|
||||
phoneHref: routes.register.phone,
|
||||
detailsHref: routes.register.details,
|
||||
});
|
||||
|
||||
if (!model.phone) {
|
||||
return <SkeletonPreset preset="form" label={t('loading')} />;
|
||||
}
|
||||
return (
|
||||
<CodeStep
|
||||
model={model}
|
||||
progress={<RegisterProgress current={2} role={model.role} />}
|
||||
submitLabel={t('register.verify.submit')}
|
||||
editHref={routes.register.phone}
|
||||
size={size}
|
||||
supportPlacement={supportPlacement}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { RegisterVerifyStep } from './RegisterVerifyStep';
|
||||
export type { RegisterVerifyStepProps } from './types';
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import type { SupportEntryProps } from '../../../../../organisms/support-entry';
|
||||
|
||||
export type RegisterVerifyStepProps = {
|
||||
/** `lg` on mobile, `md` on desktop. */
|
||||
size: 'md' | 'lg';
|
||||
supportPlacement: SupportEntryProps['placement'];
|
||||
};
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SupportLink } from '@lumina/island/atoms/support-link';
|
||||
import { SupportSheet } from '@lumina/island/organisms/support-sheet';
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { getEnv } from '../../../../../env';
|
||||
import { ROUTES } from '../../../../navigation';
|
||||
import { SUPPORT_CHAT_URLS } from './constants';
|
||||
import type { SupportEntryProps } from './types';
|
||||
|
||||
/**
|
||||
* One way into support: its trigger and the support sheet it opens (a bottom sheet on mobile, a
|
||||
* popover under the trigger on desktop). The chats and hours come from config.
|
||||
*/
|
||||
export function SupportEntry({
|
||||
trigger,
|
||||
placement,
|
||||
size = 'lg',
|
||||
}: SupportEntryProps) {
|
||||
const { t } = useTranslation('auth');
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const { baleHandle, telegramHandle, supportHours } = getEnv();
|
||||
const toggle = () => setIsOpen((open) => !open);
|
||||
const dialogProps = {
|
||||
'aria-haspopup': 'dialog',
|
||||
'aria-expanded': isOpen,
|
||||
onClick: toggle,
|
||||
} as const;
|
||||
|
||||
const button =
|
||||
trigger === 'icon' ? (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="headset"
|
||||
label={t('header.support')}
|
||||
{...dialogProps}
|
||||
/>
|
||||
) : trigger === 'link' ? (
|
||||
<SupportLink standalone {...dialogProps}>
|
||||
{t('support.link')}
|
||||
</SupportLink>
|
||||
) : (
|
||||
<Button
|
||||
variant="primary"
|
||||
icon="headset"
|
||||
size={size}
|
||||
block
|
||||
{...dialogProps}
|
||||
>
|
||||
{t('support.link')}
|
||||
</Button>
|
||||
);
|
||||
|
||||
const sheet = (
|
||||
<SupportSheet
|
||||
placement={placement}
|
||||
open={isOpen}
|
||||
onClose={() => setIsOpen(false)}
|
||||
baleHref={SUPPORT_CHAT_URLS.bale(baleHandle)}
|
||||
telegramHref={SUPPORT_CHAT_URLS.telegram(telegramHandle)}
|
||||
termsHref={ROUTES.terms}
|
||||
labels={{
|
||||
title: t('support.title'),
|
||||
bale: t('support.bale'),
|
||||
telegram: t('support.telegram'),
|
||||
hours: t('support.hours', { hours: supportHours }),
|
||||
terms: t('support.terms'),
|
||||
close: t('support.close'),
|
||||
opensNewTab: t('support.opens-new-tab'),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
// A popover hangs from a positioned parent that also holds its trigger.
|
||||
return placement === 'popover' ? (
|
||||
<FlexBox
|
||||
display={trigger === 'button' ? 'flex' : 'inline-flex'}
|
||||
className="relative"
|
||||
>
|
||||
{button}
|
||||
{sheet}
|
||||
</FlexBox>
|
||||
) : (
|
||||
<>
|
||||
{button}
|
||||
{sheet}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/** The support chats' addresses; only the handles come from config. */
|
||||
export const SUPPORT_CHAT_URLS = {
|
||||
bale: (handle: string) => `https://ble.ir/${handle}`,
|
||||
telegram: (handle: string) => `https://t.me/${handle}`,
|
||||
} as const;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { SupportEntry } from './SupportEntry';
|
||||
export type { SupportEntryProps } from './types';
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import type { SupportPlacement } from '@lumina/island/organisms/support-sheet';
|
||||
|
||||
export type SupportEntryProps = {
|
||||
/**
|
||||
* icon: the headset in a header. link: «تماس با پشتیبانی» on its own line under a form.
|
||||
* button: the primary action of a screen that leaves nothing else to do (suspended).
|
||||
*/
|
||||
trigger: 'icon' | 'link' | 'button';
|
||||
/** bottom: the mobile sheet. popover: desktop, hanging under its trigger. */
|
||||
placement: Extract<SupportPlacement, 'bottom' | 'popover'>;
|
||||
/** The button trigger's size: `lg` on mobile, `md` on desktop. */
|
||||
size?: 'md' | 'lg';
|
||||
};
|
||||
|
|
@ -1,25 +1,35 @@
|
|||
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 { SessionPayload, VerifyOtpArgs } from '../../repositories/auth';
|
||||
import type { 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. Emits `auth.login`.
|
||||
* 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. Emits `auth.login` when
|
||||
* the person is signed in.
|
||||
*/
|
||||
export async function login(
|
||||
args: VerifyOtpArgs,
|
||||
{ emit = true }: { emit?: boolean } = {},
|
||||
): Promise<SessionPayload> {
|
||||
const session = await authRepository.verifyLoginOtp(args);
|
||||
useAuthStore.getState().setSession({ account: session.account });
|
||||
): Promise<LoginOutcome> {
|
||||
const { account } = await authRepository.verifyLoginOtp(args);
|
||||
if (account.status === 'suspended') {
|
||||
await authRepository.logout();
|
||||
useAuthFlowStore.getState().reset();
|
||||
return { status: 'suspended' };
|
||||
}
|
||||
useAuthFlowStore.getState().reset();
|
||||
useAuthStore.getState().setSession({ account });
|
||||
if (emit) {
|
||||
eventEmitter.emit(AUTH_EVENTS.login, {
|
||||
userId: session.account.id,
|
||||
role: session.account.role,
|
||||
userId: account.id,
|
||||
role: account.role,
|
||||
});
|
||||
}
|
||||
return session;
|
||||
return { status: 'signed-in', account };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
export { login } from './actions';
|
||||
export type { LoginOutcome } from './types';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
import type { AccountPayload } from '../../repositories/account';
|
||||
|
||||
/** Signed in, or turned away because the account is suspended (no session). */
|
||||
export type LoginOutcome =
|
||||
| { status: 'signed-in'; account: AccountPayload }
|
||||
| { status: 'suspended' };
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { eventEmitter } from '@lumina/libs/event-emitter';
|
||||
import type { UploadProgress } from '@lumina/libs/http';
|
||||
|
||||
import { useAuthStore } from '../../../../stores/auth';
|
||||
import { useAuthFlowStore } from '../../../../stores/auth-flow';
|
||||
import { AUTH_EVENTS } from '../../constants';
|
||||
import { authRepository } from '../../repositories/auth';
|
||||
import type {
|
||||
|
|
@ -8,12 +10,28 @@ import type {
|
|||
RegisterCreatorArgs,
|
||||
} from '../../repositories/auth';
|
||||
|
||||
/** Creates a creator account with lite KYC and signs it in (cookies and auth store). Emits `auth.register`. */
|
||||
/**
|
||||
* Creates a creator account with lite KYC (the ID images upload with progress and can be
|
||||
* cancelled) and signs it in (cookies and auth store); the flow's number and token are dropped.
|
||||
* Emits `auth.register`.
|
||||
*/
|
||||
export async function registerCreator(
|
||||
args: RegisterCreatorArgs,
|
||||
{ emit = true }: { emit?: boolean } = {},
|
||||
{
|
||||
emit = true,
|
||||
signal,
|
||||
onProgress,
|
||||
}: {
|
||||
emit?: boolean;
|
||||
signal?: AbortSignal;
|
||||
onProgress?: (progress: UploadProgress) => void;
|
||||
} = {},
|
||||
): Promise<CreatorRegisteredPayload> {
|
||||
const registration = await authRepository.registerCreator(args);
|
||||
const registration = await authRepository.registerCreator(args, {
|
||||
signal,
|
||||
onProgress,
|
||||
});
|
||||
useAuthFlowStore.getState().reset();
|
||||
useAuthStore.getState().setSession({ account: registration.account });
|
||||
if (emit) {
|
||||
eventEmitter.emit(AUTH_EVENTS.register, {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
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 {
|
||||
|
|
@ -8,12 +9,13 @@ import type {
|
|||
SessionPayload,
|
||||
} from '../../repositories/auth';
|
||||
|
||||
/** Creates an investor account and signs it in (cookies and auth store). Emits `auth.register`. */
|
||||
/** Creates an investor account and signs it in (cookies and auth store); the flow's number and token are dropped. Emits `auth.register`. */
|
||||
export async function registerInvestor(
|
||||
args: RegisterInvestorArgs,
|
||||
{ emit = true }: { emit?: boolean } = {},
|
||||
): Promise<SessionPayload> {
|
||||
const session = await authRepository.registerInvestor(args);
|
||||
useAuthFlowStore.getState().reset();
|
||||
useAuthStore.getState().setSession({ account: session.account });
|
||||
if (emit) {
|
||||
eventEmitter.emit(AUTH_EVENTS.register, {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
import { eventEmitter } from '@lumina/libs/event-emitter';
|
||||
|
||||
import { useAuthFlowStore } from '../../../../stores/auth-flow';
|
||||
import { AUTH_EVENTS } from '../../constants';
|
||||
import {
|
||||
AUTH_ERROR_CODES,
|
||||
authErrorCode,
|
||||
authRepository,
|
||||
} from '../../repositories/auth';
|
||||
import type { SendCodeArgs } 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, so that counts as sent. Emits `auth.code-sent`.
|
||||
*/
|
||||
export async function sendCode(
|
||||
{ purpose, phone }: SendCodeArgs,
|
||||
{ emit = true }: { emit?: boolean } = {},
|
||||
): Promise<'ok'> {
|
||||
try {
|
||||
if (purpose === 'login') await authRepository.requestLoginOtp({ phone });
|
||||
else await authRepository.sendRegistrationOtp({ phone });
|
||||
} catch (error) {
|
||||
const flow = useAuthFlowStore.getState();
|
||||
const isSameCode =
|
||||
authErrorCode(error) === AUTH_ERROR_CODES.cooldown &&
|
||||
flow.purpose === purpose &&
|
||||
flow.phone === phone &&
|
||||
flow.codeSentAt !== null;
|
||||
if (!isSameCode) throw error;
|
||||
return 'ok';
|
||||
}
|
||||
useAuthFlowStore.getState().codeSent(purpose, phone, Date.now());
|
||||
if (emit) eventEmitter.emit(AUTH_EVENTS.codeSent, { purpose });
|
||||
return 'ok';
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { sendCode } from './actions';
|
||||
export type { SendCodeArgs } from './types';
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import type { AuthPurpose } from '../../types';
|
||||
|
||||
export type SendCodeArgs = {
|
||||
purpose: AuthPurpose;
|
||||
/** 09XXXXXXXXX; the repository sends E.164. */
|
||||
phone: string;
|
||||
};
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import { eventEmitter } from '@lumina/libs/event-emitter';
|
||||
|
||||
import { useAuthFlowStore } from '../../../../stores/auth-flow';
|
||||
import { AUTH_EVENTS } from '../../constants';
|
||||
import { authRepository } from '../../repositories/auth';
|
||||
import type { VerifyOtpArgs } from '../../repositories/auth';
|
||||
|
||||
/**
|
||||
* Proves the number for a new account. The registration token it returns lives in memory only
|
||||
* (the flow store), for step 4, and is never stored. Emits `auth.phone-verified`.
|
||||
*/
|
||||
export async function verifyRegistrationCode(
|
||||
args: VerifyOtpArgs,
|
||||
{ emit = true }: { emit?: boolean } = {},
|
||||
): Promise<'ok'> {
|
||||
const { registrationToken, expiresInSeconds } =
|
||||
await authRepository.verifyRegistrationOtp(args);
|
||||
useAuthFlowStore.getState().phoneVerified({
|
||||
token: registrationToken,
|
||||
expiresAt: Date.now() + expiresInSeconds * 1000,
|
||||
});
|
||||
if (emit) {
|
||||
eventEmitter.emit(AUTH_EVENTS.phoneVerified, { purpose: 'register' });
|
||||
}
|
||||
return 'ok';
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { verifyRegistrationCode } from './actions';
|
||||
|
|
@ -1,7 +1,27 @@
|
|||
/** Events auth actions emit when they succeed; the AppShell reacts to them. */
|
||||
export const AUTH_EVENTS = {
|
||||
restore: 'auth.restore',
|
||||
codeSent: 'auth.code-sent',
|
||||
phoneVerified: 'auth.phone-verified',
|
||||
login: 'auth.login',
|
||||
register: 'auth.register',
|
||||
logout: 'auth.logout',
|
||||
} as const;
|
||||
|
||||
/** Why a code is sent: to sign in to an account, or to prove the number for a new one. */
|
||||
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.
|
||||
*/
|
||||
export const CODE_RULES = {
|
||||
length: 6,
|
||||
resendWaitSeconds: 120,
|
||||
maxMisses: 3,
|
||||
blockSeconds: 600,
|
||||
} as const;
|
||||
|
||||
/** Step 4 warns this long before the registration token runs out. */
|
||||
export const REGISTRATION_WARNING_SECONDS = 120;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,78 @@
|
|||
import './types';
|
||||
|
||||
export { login } from './actions/login';
|
||||
export type { LoginOutcome } from './actions/login';
|
||||
export { logout } from './actions/logout';
|
||||
export { registerCreator } from './actions/register-creator';
|
||||
export { registerInvestor } from './actions/register-investor';
|
||||
export { restoreSession } from './actions/restore-session';
|
||||
export { AUTH_EVENTS } from './constants';
|
||||
export { sendCode } from './actions/send-code';
|
||||
export type { SendCodeArgs } from './actions/send-code';
|
||||
export { verifyRegistrationCode } from './actions/verify-registration-code';
|
||||
export {
|
||||
AUTH_EVENTS,
|
||||
AUTH_PURPOSES,
|
||||
CODE_RULES,
|
||||
REGISTRATION_WARNING_SECONDS,
|
||||
} from './constants';
|
||||
export type { UserRole, UserStatus } from './entities/user';
|
||||
export { useCodeStep } from './models/code-step';
|
||||
export type {
|
||||
CodeStepModel,
|
||||
CodeStepStatus,
|
||||
CodeVerifiedOutcome,
|
||||
ResendPhase,
|
||||
UseCodeStepOptions,
|
||||
} from './models/code-step';
|
||||
export { useLoginPage } from './models/login';
|
||||
export type { LoginPageModel, UseLoginPageOptions } from './models/login';
|
||||
export { useLoginVerifyPage } from './models/login-verify';
|
||||
export type {
|
||||
LoginVerifyPageModel,
|
||||
LoginVerifyView,
|
||||
SignedInViewer,
|
||||
UseLoginVerifyPageOptions,
|
||||
} from './models/login-verify';
|
||||
export {
|
||||
useCreatorIdentityPart,
|
||||
useInvestorDetailsPart,
|
||||
useRegisterDetailsPage,
|
||||
} from './models/register-details';
|
||||
export type {
|
||||
CreatorIdentityPartModel,
|
||||
IdCardSide,
|
||||
InvestorDetailsPartModel,
|
||||
RegisterDetailsPageModel,
|
||||
RegistrationTimePhase,
|
||||
UseDetailsPartOptions,
|
||||
UseRegisterDetailsPageOptions,
|
||||
} from './models/register-details';
|
||||
export { useRegisterPhonePage } from './models/register-phone';
|
||||
export type {
|
||||
RegisterPhonePageModel,
|
||||
UseRegisterPhonePageOptions,
|
||||
} from './models/register-phone';
|
||||
export { useRegisterTypePage } from './models/register-type';
|
||||
export type {
|
||||
RegisterTypePageModel,
|
||||
UseRegisterTypePageOptions,
|
||||
} from './models/register-type';
|
||||
export { useRegisterVerifyPage } from './models/register-verify';
|
||||
export type {
|
||||
RegisterVerifyPageModel,
|
||||
UseRegisterVerifyPageOptions,
|
||||
} from './models/register-verify';
|
||||
export { accountKeys, accountRepository } from './repositories/account';
|
||||
export type { AccountPayload, UpdateAccountArgs } from './repositories/account';
|
||||
export { AUTH_ENDPOINTS, authRepository } from './repositories/auth';
|
||||
export {
|
||||
AUTH_ENDPOINTS,
|
||||
AUTH_ERROR_CODES,
|
||||
AUTH_ERROR_COPY,
|
||||
authErrorCode,
|
||||
authRepository,
|
||||
} from './repositories/auth';
|
||||
export type {
|
||||
AuthErrorCode,
|
||||
CreatorRegisteredPayload,
|
||||
OtpSentPayload,
|
||||
RegisterCreatorArgs,
|
||||
|
|
@ -21,4 +83,4 @@ export type {
|
|||
SessionStatePayload,
|
||||
VerifyOtpArgs,
|
||||
} from './repositories/auth';
|
||||
export type { LogoutReason } from './types';
|
||||
export type { AuthPurpose, LogoutReason } from './types';
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue