From 01c838e869fbd2fd25ed1b13dd2e9a5854849870 Mon Sep 17 00:00:00 2001 From: Amiram_se Date: Mon, 2 Nov 2026 01:28:42 +0400 Subject: [PATCH] feat(legal): add rules caption, analyst agreement and re-acceptance gate Reads the three legal documents from the API, so /terms and /terms/subscription render in the browser under a (tabs) route group, and adds /terms/analyst-agreement. The login and sign-up phone pages accept the rules through a caption, the analyst sign-up requires the agreement and sends its version, and a blocking gate opens from the session or a 403 agreement_required. Account rows and the rules_updated notification follow. Co-Authored-By: Claude Opus 5.5 --- .../app/(auth)/auth/register/details/page.tsx | 14 -- .../app/(flow)/terms/{ => (tabs)}/layout.tsx | 8 +- .../app/(flow)/terms/{ => (tabs)}/loading.tsx | 4 +- .../bear/src/app/(flow)/terms/(tabs)/page.tsx | 23 ++++ .../{ => (tabs)}/subscription/loading.tsx | 2 +- .../(flow)/terms/(tabs)/subscription/page.tsx | 23 ++++ .../(flow)/terms/analyst-agreement/layout.tsx | 44 ++++++ .../terms/analyst-agreement/loading.tsx | 8 ++ .../(flow)/terms/analyst-agreement/page.tsx | 22 +++ apps/bear/src/app/(flow)/terms/page.tsx | 29 ---- .../app/(flow)/terms/subscription/page.tsx | 41 ------ .../organisms/app-providers/AppProviders.tsx | 2 +- apps/bear/src/bootstrap/bootstrap.client.ts | 2 + .../app/(auth)/auth/register/details/page.tsx | 14 -- .../app/(flow)/terms/{ => (tabs)}/layout.tsx | 10 +- .../app/(flow)/terms/{ => (tabs)}/loading.tsx | 4 +- .../bull/src/app/(flow)/terms/(tabs)/page.tsx | 18 +++ .../{ => (tabs)}/subscription/loading.tsx | 2 +- .../(flow)/terms/(tabs)/subscription/page.tsx | 18 +++ .../(flow)/terms/analyst-agreement/layout.tsx | 37 +++++ .../terms/analyst-agreement/loading.tsx | 8 ++ .../(flow)/terms/analyst-agreement/page.tsx | 19 +++ apps/bull/src/app/(flow)/terms/page.tsx | 26 ---- .../app/(flow)/terms/subscription/page.tsx | 39 ------ .../organisms/app-providers/AppProviders.tsx | 2 +- apps/bull/src/bootstrap/bootstrap.client.ts | 2 + docs/pages/README.md | 9 +- docs/pages/market/account.md | 22 +-- docs/pages/market/auth-login.md | 1 + docs/pages/market/auth-register-details.md | 27 ++-- docs/pages/market/auth-register-phone.md | 19 +-- docs/pages/market/feed.md | 2 +- docs/pages/market/layout-terms.md | 6 +- docs/pages/market/terms-analyst-agreement.md | 28 ++++ docs/pages/market/terms-subscription.md | 30 ++--- docs/pages/market/terms.md | 33 ++--- packages/tools/src/format/format.ts | 5 + packages/tools/src/format/index.ts | 1 + .../market/src/app/app-shell/AppShell.tsx | 12 +- platforms/market/src/app/app-shell/types.ts | 2 + .../market/src/app/navigation/navigation.ts | 3 +- .../login/organisms/login-step/LoginStep.tsx | 2 + .../rules-caption/RulesCaption.test.tsx | 67 ++++++++++ .../organisms/rules-caption/RulesCaption.tsx | 46 +++++++ .../auth/organisms/rules-caption/index.ts | 2 + .../auth/organisms/rules-caption/types.ts | 4 + .../components/AgreementBlock.tsx | 66 +++++++++ .../components/CreatorIdentityForm.tsx | 29 ++-- .../components/IdentitySubmit.test.tsx | 48 +++++++ .../components/IdentitySubmit.tsx | 27 ++++ .../components/InvestorDetailsForm.tsx | 26 ++-- .../components/TermsLine.tsx | 37 ----- .../organisms/register-details-step/types.ts | 34 ++--- .../register-phone-step/RegisterPhoneStep.tsx | 2 + .../analyst-agreement/AnalystAgreement.tsx | 29 ++++ .../organisms/analyst-agreement/index.ts | 2 + .../organisms/analyst-agreement/types.ts | 3 + .../terms/organisms/rules-tabs/RulesTabs.tsx | 2 +- .../terms/organisms/rules-tabs/types.ts | 4 +- .../subscription-terms/SubscriptionTerms.tsx | 102 ++++---------- .../organisms/subscription-terms/index.ts | 7 +- .../organisms/subscription-terms/labels.ts | 54 -------- .../organisms/subscription-terms/types.ts | 26 ---- .../account-overview/AccountOverview.tsx | 20 ++- .../notification-centre/constants.ts | 1 + .../agreement-gate/AgreementGate.test.tsx | 126 ++++++++++++++++++ .../agreement-gate/AgreementGate.tsx | 54 ++++++++ .../agreement-gate/components/GateActions.tsx | 35 +++++ .../agreement-gate/components/GateBody.tsx | 80 +++++++++++ .../screens/organisms/agreement-gate/index.ts | 2 + .../screens/organisms/agreement-gate/types.ts | 11 ++ .../organisms/general-rules/GeneralRules.tsx | 48 ------- .../screens/organisms/general-rules/index.ts | 7 - .../screens/organisms/general-rules/labels.ts | 17 --- .../screens/organisms/general-rules/types.ts | 23 ---- .../legal-document/LegalDocumentDialog.tsx} | 28 ++-- .../legal-document/LegalDocumentView.tsx | 59 ++++++++ .../components/LegalDocumentBody.tsx | 94 +++++++++++++ .../components/LegalDocumentSkeleton.tsx | 15 +++ .../screens/organisms/legal-document/index.ts | 9 ++ .../screens/organisms/legal-document/types.ts | 25 ++++ .../actions/agreement-required/actions.ts | 19 +++ .../auth/actions/agreement-required/index.ts | 1 + .../auth/actions/register-creator/actions.ts | 2 + .../auth/actions/restore-session/actions.ts | 5 +- platforms/market/src/features/auth/index.ts | 1 + .../auth/models/register-details/types.ts | 11 ++ .../use-creator-identity-part.ts | 31 ++++- .../auth/repositories/auth/mappers.ts | 10 +- .../features/auth/repositories/auth/types.ts | 24 +++- .../legal/actions/accept-agreement/actions.ts | 28 ++++ .../legal/actions/accept-agreement/index.ts | 1 + .../market/src/features/legal/constants.ts | 9 ++ .../legal/entities/legal-document/index.ts | 5 + .../legal/entities/legal-document/types.ts | 22 +++ platforms/market/src/features/legal/http.ts | 3 + platforms/market/src/features/legal/index.ts | 26 ++++ .../models/agreement-acceptance/index.ts | 1 + .../use-agreement-acceptance.ts | 20 +++ .../legal/models/agreement-gate/index.ts | 2 + .../legal/models/agreement-gate/types.ts | 17 +++ .../agreement-gate/use-agreement-gate.ts | 67 ++++++++++ .../legal/models/legal-document/index.ts | 2 + .../legal/models/legal-document/types.ts | 10 ++ .../legal-document/use-legal-document.ts | 28 ++++ .../legal/repositories/legal/constants.ts | 14 ++ .../legal/repositories/legal/index.ts | 9 ++ .../legal/repositories/legal/legal.ts | 52 ++++++++ .../legal/repositories/legal/mappers.ts | 52 ++++++++ .../legal/repositories/legal/types.ts | 25 ++++ platforms/market/src/features/legal/types.ts | 7 + .../legal/utils/parse-legal-markdown.test.ts | 74 ++++++++++ .../legal/utils/parse-legal-markdown.ts | 60 +++++++++ .../entities/notification/types.ts | 3 + .../use-notification-centre.ts | 1 + platforms/market/src/index.ts | 25 ++++ .../market/src/shared/locales/fa/account.json | 4 +- .../market/src/shared/locales/fa/auth.json | 7 +- .../market/src/shared/locales/fa/legal.json | 40 ++++++ .../market/src/shared/locales/fa/rules.json | 44 ++---- .../market/src/shared/locales/fa/terms.json | 52 +------- .../market/src/shared/locales/resources.ts | 2 + .../src/shared/locales/server-resources.ts | 6 +- .../market/src/stores/auth/auth-store.ts | 6 + platforms/market/src/stores/auth/index.ts | 1 + platforms/market/src/stores/auth/types.ts | 7 + tools/vitest-setup.ts | 14 ++ 127 files changed, 2019 insertions(+), 725 deletions(-) rename apps/bear/src/app/(flow)/terms/{ => (tabs)}/layout.tsx (81%) rename apps/bear/src/app/(flow)/terms/{ => (tabs)}/loading.tsx (79%) create mode 100644 apps/bear/src/app/(flow)/terms/(tabs)/page.tsx rename apps/bear/src/app/(flow)/terms/{ => (tabs)}/subscription/loading.tsx (93%) create mode 100644 apps/bear/src/app/(flow)/terms/(tabs)/subscription/page.tsx create mode 100644 apps/bear/src/app/(flow)/terms/analyst-agreement/layout.tsx create mode 100644 apps/bear/src/app/(flow)/terms/analyst-agreement/loading.tsx create mode 100644 apps/bear/src/app/(flow)/terms/analyst-agreement/page.tsx delete mode 100644 apps/bear/src/app/(flow)/terms/page.tsx delete mode 100644 apps/bear/src/app/(flow)/terms/subscription/page.tsx rename apps/bull/src/app/(flow)/terms/{ => (tabs)}/layout.tsx (74%) rename apps/bull/src/app/(flow)/terms/{ => (tabs)}/loading.tsx (75%) create mode 100644 apps/bull/src/app/(flow)/terms/(tabs)/page.tsx rename apps/bull/src/app/(flow)/terms/{ => (tabs)}/subscription/loading.tsx (92%) create mode 100644 apps/bull/src/app/(flow)/terms/(tabs)/subscription/page.tsx create mode 100644 apps/bull/src/app/(flow)/terms/analyst-agreement/layout.tsx create mode 100644 apps/bull/src/app/(flow)/terms/analyst-agreement/loading.tsx create mode 100644 apps/bull/src/app/(flow)/terms/analyst-agreement/page.tsx delete mode 100644 apps/bull/src/app/(flow)/terms/page.tsx delete mode 100644 apps/bull/src/app/(flow)/terms/subscription/page.tsx create mode 100644 docs/pages/market/terms-analyst-agreement.md create mode 100644 platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/RulesCaption.test.tsx create mode 100644 platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/RulesCaption.tsx create mode 100644 platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/index.ts create mode 100644 platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/types.ts create mode 100644 platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/AgreementBlock.tsx create mode 100644 platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/IdentitySubmit.test.tsx create mode 100644 platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/IdentitySubmit.tsx delete mode 100644 platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/TermsLine.tsx create mode 100644 platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/AnalystAgreement.tsx create mode 100644 platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/index.ts create mode 100644 platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/types.ts delete mode 100644 platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/labels.ts create mode 100644 platforms/market/src/app/screens/organisms/agreement-gate/AgreementGate.test.tsx create mode 100644 platforms/market/src/app/screens/organisms/agreement-gate/AgreementGate.tsx create mode 100644 platforms/market/src/app/screens/organisms/agreement-gate/components/GateActions.tsx create mode 100644 platforms/market/src/app/screens/organisms/agreement-gate/components/GateBody.tsx create mode 100644 platforms/market/src/app/screens/organisms/agreement-gate/index.ts create mode 100644 platforms/market/src/app/screens/organisms/agreement-gate/types.ts delete mode 100644 platforms/market/src/app/screens/organisms/general-rules/GeneralRules.tsx delete mode 100644 platforms/market/src/app/screens/organisms/general-rules/index.ts delete mode 100644 platforms/market/src/app/screens/organisms/general-rules/labels.ts delete mode 100644 platforms/market/src/app/screens/organisms/general-rules/types.ts rename platforms/market/src/app/screens/{(auth)/auth/register/details/organisms/register-details-step/components/RulesSheet.tsx => organisms/legal-document/LegalDocumentDialog.tsx} (63%) create mode 100644 platforms/market/src/app/screens/organisms/legal-document/LegalDocumentView.tsx create mode 100644 platforms/market/src/app/screens/organisms/legal-document/components/LegalDocumentBody.tsx create mode 100644 platforms/market/src/app/screens/organisms/legal-document/components/LegalDocumentSkeleton.tsx create mode 100644 platforms/market/src/app/screens/organisms/legal-document/index.ts create mode 100644 platforms/market/src/app/screens/organisms/legal-document/types.ts create mode 100644 platforms/market/src/features/auth/actions/agreement-required/actions.ts create mode 100644 platforms/market/src/features/auth/actions/agreement-required/index.ts create mode 100644 platforms/market/src/features/legal/actions/accept-agreement/actions.ts create mode 100644 platforms/market/src/features/legal/actions/accept-agreement/index.ts create mode 100644 platforms/market/src/features/legal/constants.ts create mode 100644 platforms/market/src/features/legal/entities/legal-document/index.ts create mode 100644 platforms/market/src/features/legal/entities/legal-document/types.ts create mode 100644 platforms/market/src/features/legal/http.ts create mode 100644 platforms/market/src/features/legal/index.ts create mode 100644 platforms/market/src/features/legal/models/agreement-acceptance/index.ts create mode 100644 platforms/market/src/features/legal/models/agreement-acceptance/use-agreement-acceptance.ts create mode 100644 platforms/market/src/features/legal/models/agreement-gate/index.ts create mode 100644 platforms/market/src/features/legal/models/agreement-gate/types.ts create mode 100644 platforms/market/src/features/legal/models/agreement-gate/use-agreement-gate.ts create mode 100644 platforms/market/src/features/legal/models/legal-document/index.ts create mode 100644 platforms/market/src/features/legal/models/legal-document/types.ts create mode 100644 platforms/market/src/features/legal/models/legal-document/use-legal-document.ts create mode 100644 platforms/market/src/features/legal/repositories/legal/constants.ts create mode 100644 platforms/market/src/features/legal/repositories/legal/index.ts create mode 100644 platforms/market/src/features/legal/repositories/legal/legal.ts create mode 100644 platforms/market/src/features/legal/repositories/legal/mappers.ts create mode 100644 platforms/market/src/features/legal/repositories/legal/types.ts create mode 100644 platforms/market/src/features/legal/types.ts create mode 100644 platforms/market/src/features/legal/utils/parse-legal-markdown.test.ts create mode 100644 platforms/market/src/features/legal/utils/parse-legal-markdown.ts create mode 100644 platforms/market/src/shared/locales/fa/legal.json diff --git a/apps/bear/src/app/(auth)/auth/register/details/page.tsx b/apps/bear/src/app/(auth)/auth/register/details/page.tsx index 2184ac2..d912169 100644 --- a/apps/bear/src/app/(auth)/auth/register/details/page.tsx +++ b/apps/bear/src/app/(auth)/auth/register/details/page.tsx @@ -1,14 +1,6 @@ -// First: the rules sheet reads a server-only namespace, which the server bootstrap adds to i18n -// when this module loads (0055). -import '../../../../../bootstrap/bootstrap.server'; - import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset'; import { GuestGuard } from '@lumina/market/app/guards/guest-guard'; import { ROUTES } from '@lumina/market/app/navigation'; -import { - GeneralRules, - generalRulesLabels, -} from '@lumina/market/app/screens/organisms/general-rules'; import { RegisterDetailsStep } from '@lumina/market/app/screens/(auth)/auth/register/details/organisms/register-details-step'; import type { Metadata } from 'next'; @@ -37,12 +29,6 @@ export default function RegisterDetailsPage() { size="md" supportPlacement="popover" haltPlacement="modal" - rules={ - - } /> diff --git a/apps/bear/src/app/(flow)/terms/layout.tsx b/apps/bear/src/app/(flow)/terms/(tabs)/layout.tsx similarity index 81% rename from apps/bear/src/app/(flow)/terms/layout.tsx rename to apps/bear/src/app/(flow)/terms/(tabs)/layout.tsx index 147aef5..5142d87 100644 --- a/apps/bear/src/app/(flow)/terms/layout.tsx +++ b/apps/bear/src/app/(flow)/terms/(tabs)/layout.tsx @@ -1,6 +1,6 @@ // First: the static `metadata` below reads a server-only namespace, which the server bootstrap // adds to i18n when this module loads, whichever module Next loads first (0055). -import '../../../bootstrap/bootstrap.server'; +import '../../../../bootstrap/bootstrap.server'; import { FlexBox } from '@lumina/island/atoms/flex-box'; import { DesktopHeader, DesktopPageTitle } from '@lumina/market/app/navigation'; @@ -8,7 +8,7 @@ import { RulesTabs } from '@lumina/market/app/screens/(flow)/terms/organisms/rul import type { Metadata } from 'next'; import type { ReactNode } from 'react'; -import { i18n } from '../../../i18n'; +import { i18n } from '../../../../i18n'; // Only the landing is indexed (0071); both tabs inherit this. export const metadata: Metadata = { @@ -18,8 +18,8 @@ export const metadata: Metadata = { }; /** - * «قوانین لومینا» on desktop (G-2r): the 640 column under the header, with back beside the title - * «قوانین لومینا» and the tab row «قوانین عمومی» · «شرایط اشتراک»; each tab's text sits in a panel. + * «قوانین و مقررات لومینا» on desktop (G-2r): the 640 column under the header, with back beside the title + * «قوانین و مقررات لومینا» and the tab row «قوانین و مقررات» · «شرایط اشتراک»; each tab's text sits in a panel. * Each tab is its own route with its own loading, so the title and the row stay while one loads; * back returns to where the rules were opened. No nav item is active. */ diff --git a/apps/bear/src/app/(flow)/terms/loading.tsx b/apps/bear/src/app/(flow)/terms/(tabs)/loading.tsx similarity index 79% rename from apps/bear/src/app/(flow)/terms/loading.tsx rename to apps/bear/src/app/(flow)/terms/(tabs)/loading.tsx index b35db5a..ba0c1cf 100644 --- a/apps/bear/src/app/(flow)/terms/loading.tsx +++ b/apps/bear/src/app/(flow)/terms/(tabs)/loading.tsx @@ -1,9 +1,9 @@ import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton'; import { Card } from '@lumina/island/molecules/card'; -import { i18n } from '../../../i18n'; +import { i18n } from '../../../../i18n'; -/** «قوانین عمومی» before it arrives, under the section's title and tabs: its panel of lines. */ +/** «قوانین و مقررات» before it arrives, under the section's title and tabs: its panel of lines. */ export default function Loading() { return ( diff --git a/apps/bear/src/app/(flow)/terms/(tabs)/page.tsx b/apps/bear/src/app/(flow)/terms/(tabs)/page.tsx new file mode 100644 index 0000000..c670937 --- /dev/null +++ b/apps/bear/src/app/(flow)/terms/(tabs)/page.tsx @@ -0,0 +1,23 @@ +// First: the static `metadata` below reads a server-only namespace, which the server bootstrap +// adds to i18n when this module loads, whichever module Next loads first (0055). +import '../../../../bootstrap/bootstrap.server'; + +import { Card } from '@lumina/island/molecules/card'; +import { LegalDocumentView } from '@lumina/market/app/screens/organisms/legal-document'; +import type { Metadata } from 'next'; + +import { i18n } from '../../../../i18n'; + +export const metadata: Metadata = { + title: i18n.t('rules:meta-title'), + description: i18n.t('rules:meta-description'), +}; + +/** «قوانین و مقررات», the first tab of «قوانین و مقررات لومینا» (G-2r); its text is read in the browser (0070). */ +export default function RulesPage() { + return ( + + + + ); +} diff --git a/apps/bear/src/app/(flow)/terms/subscription/loading.tsx b/apps/bear/src/app/(flow)/terms/(tabs)/subscription/loading.tsx similarity index 93% rename from apps/bear/src/app/(flow)/terms/subscription/loading.tsx rename to apps/bear/src/app/(flow)/terms/(tabs)/subscription/loading.tsx index 6aaccb2..06310df 100644 --- a/apps/bear/src/app/(flow)/terms/subscription/loading.tsx +++ b/apps/bear/src/app/(flow)/terms/(tabs)/subscription/loading.tsx @@ -1,7 +1,7 @@ import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton'; import { Card } from '@lumina/island/molecules/card'; -import { i18n } from '../../../../i18n'; +import { i18n } from '../../../../../i18n'; /** The terms before they arrive, under the section's title and tabs: their panel of lines. */ export default function Loading() { diff --git a/apps/bear/src/app/(flow)/terms/(tabs)/subscription/page.tsx b/apps/bear/src/app/(flow)/terms/(tabs)/subscription/page.tsx new file mode 100644 index 0000000..0085be8 --- /dev/null +++ b/apps/bear/src/app/(flow)/terms/(tabs)/subscription/page.tsx @@ -0,0 +1,23 @@ +// First: the static `metadata` below reads a server-only namespace, which the server bootstrap +// adds to i18n when this module loads, whichever module Next loads first (0055). +import '../../../../../bootstrap/bootstrap.server'; + +import { Card } from '@lumina/island/molecules/card'; +import { SubscriptionTerms } from '@lumina/market/app/screens/(flow)/terms/subscription/organisms/subscription-terms'; +import type { Metadata } from 'next'; + +import { i18n } from '../../../../../i18n'; + +export const metadata: Metadata = { + title: i18n.t('terms:meta-title'), + description: i18n.t('terms:meta-description'), +}; + +/** «شرایط اشتراک», the second tab of «قوانین و مقررات لومینا» (S5, G-2); its text is read in the browser (0070). */ +export default function SubscriptionTermsPage() { + return ( + + + + ); +} diff --git a/apps/bear/src/app/(flow)/terms/analyst-agreement/layout.tsx b/apps/bear/src/app/(flow)/terms/analyst-agreement/layout.tsx new file mode 100644 index 0000000..642a05b --- /dev/null +++ b/apps/bear/src/app/(flow)/terms/analyst-agreement/layout.tsx @@ -0,0 +1,44 @@ +// First: the static `metadata` below reads a server-only namespace, which the server bootstrap +// adds to i18n when this module loads, whichever module Next loads first (0055). +import '../../../../bootstrap/bootstrap.server'; + +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { DesktopHeader, DesktopPageTitle } from '@lumina/market/app/navigation'; +import type { Metadata } from 'next'; +import type { ReactNode } from 'react'; + +import { i18n } from '../../../../i18n'; + +export const metadata: Metadata = { + title: i18n.t('rules:agreement.meta-title'), + robots: { index: false }, +}; + +/** «توافق‌نامه تحلیلگر» on desktop: the 640 column under the header, with back beside the title. */ +export default function AnalystAgreementLayout({ + children, +}: { + children: ReactNode; +}) { + const t = i18n.getFixedT(null, 'rules'); + + return ( + + + + + + {children} + + + + ); +} diff --git a/apps/bear/src/app/(flow)/terms/analyst-agreement/loading.tsx b/apps/bear/src/app/(flow)/terms/analyst-agreement/loading.tsx new file mode 100644 index 0000000..693c5d5 --- /dev/null +++ b/apps/bear/src/app/(flow)/terms/analyst-agreement/loading.tsx @@ -0,0 +1,8 @@ +import { LegalDocumentSkeleton } from '@lumina/market/app/screens/organisms/legal-document'; + +import { i18n } from '../../../../i18n'; + +/** The agreement before it arrives, under the page's bar or title. */ +export default function Loading() { + return ; +} diff --git a/apps/bear/src/app/(flow)/terms/analyst-agreement/page.tsx b/apps/bear/src/app/(flow)/terms/analyst-agreement/page.tsx new file mode 100644 index 0000000..82ba0d9 --- /dev/null +++ b/apps/bear/src/app/(flow)/terms/analyst-agreement/page.tsx @@ -0,0 +1,22 @@ +import { Card } from '@lumina/island/molecules/card'; +import { AuthGuard } from '@lumina/market/app/guards/auth-guard'; +import { AnalystAgreement } from '@lumina/market/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement'; +import { LegalDocumentSkeleton } from '@lumina/market/app/screens/organisms/legal-document'; + +import { i18n } from '../../../../i18n'; + +/** The agreement and the analyst's own record; both read in the browser (0070). Analysts only. */ +export default function AnalystAgreementPage() { + return ( + + } + > + + + + + ); +} diff --git a/apps/bear/src/app/(flow)/terms/page.tsx b/apps/bear/src/app/(flow)/terms/page.tsx deleted file mode 100644 index 6ebb630..0000000 --- a/apps/bear/src/app/(flow)/terms/page.tsx +++ /dev/null @@ -1,29 +0,0 @@ -// First: the static `metadata` below reads a server-only namespace, which the server bootstrap -// adds to i18n when this module loads, whichever module Next loads first (0055). -import '../../../bootstrap/bootstrap.server'; - -import { Card } from '@lumina/island/molecules/card'; -import { - GeneralRules, - generalRulesLabels, -} from '@lumina/market/app/screens/organisms/general-rules'; -import type { Metadata } from 'next'; - -import { i18n } from '../../../i18n'; - -export const metadata: Metadata = { - title: i18n.t('rules:meta-title'), - description: i18n.t('rules:meta-description'), -}; - -/** «قوانین عمومی», the first tab of «قوانین لومینا» on desktop (G-2r): the text in a panel. */ -export default function GeneralRulesPage() { - return ( - - - - ); -} diff --git a/apps/bear/src/app/(flow)/terms/subscription/page.tsx b/apps/bear/src/app/(flow)/terms/subscription/page.tsx deleted file mode 100644 index 6929733..0000000 --- a/apps/bear/src/app/(flow)/terms/subscription/page.tsx +++ /dev/null @@ -1,41 +0,0 @@ -// First: the static `metadata` below reads a server-only namespace, which the server bootstrap -// adds to i18n when this module loads, whichever module Next loads first (0055). -import '../../../../bootstrap/bootstrap.server'; - -import { Card } from '@lumina/island/molecules/card'; -import { - SubscriptionTerms, - subscriptionTermsLabels, -} from '@lumina/market/app/screens/(flow)/terms/subscription/organisms/subscription-terms'; -import { supportChatUrls } from '@lumina/market/app/screens/organisms/support-entry'; -import { getEnv } from '@lumina/market/env'; -import type { Metadata } from 'next'; - -import { i18n } from '../../../../i18n'; - -export const metadata: Metadata = { - title: i18n.t('terms:meta-title'), - description: i18n.t('terms:meta-description'), -}; - -/** - * «شرایط اشتراک», the second tab of «قوانین لومینا» on desktop (S5 ۲.۱, G-2): the text in a panel - * of the section's 640 column, about 75 characters a line; the title and tabs come from the layout. - */ -export default function SubscriptionTermsPage() { - const labels = subscriptionTermsLabels( - i18n.getFixedT(null, 'terms'), - i18n.getFixedT(null, 'auth'), - getEnv().supportHours, - ); - - return ( - - - - ); -} diff --git a/apps/bear/src/app/organisms/app-providers/AppProviders.tsx b/apps/bear/src/app/organisms/app-providers/AppProviders.tsx index e6b3522..c27db66 100644 --- a/apps/bear/src/app/organisms/app-providers/AppProviders.tsx +++ b/apps/bear/src/app/organisms/app-providers/AppProviders.tsx @@ -12,7 +12,7 @@ import type { AppProvidersProps } from './types'; /** The app's root client component: runs the client bootstrap, then the platform's shell. */ export function AppProviders({ children }: AppProvidersProps) { return ( - + {children} ); diff --git a/apps/bear/src/bootstrap/bootstrap.client.ts b/apps/bear/src/bootstrap/bootstrap.client.ts index de32613..3e6efc6 100644 --- a/apps/bear/src/bootstrap/bootstrap.client.ts +++ b/apps/bear/src/bootstrap/bootstrap.client.ts @@ -9,6 +9,7 @@ import { AUTH_EVENTS, endSuspendedSession, isSessionSuspended, + noteAgreementRequired, suspendedSessionOf, } from '@lumina/market/features/auth'; @@ -45,6 +46,7 @@ http.configure({ http.interceptors.response.use(undefined, (error) => { const suspension = suspendedSessionOf(error); if (suspension) endSuspendedSession(suspension); + noteAgreementRequired(error); return error; }); configureErrorHandler(ERROR_HANDLER_CONFIG); diff --git a/apps/bull/src/app/(auth)/auth/register/details/page.tsx b/apps/bull/src/app/(auth)/auth/register/details/page.tsx index 285969f..16ac215 100644 --- a/apps/bull/src/app/(auth)/auth/register/details/page.tsx +++ b/apps/bull/src/app/(auth)/auth/register/details/page.tsx @@ -1,14 +1,6 @@ -// First: the rules sheet reads a server-only namespace, which the server bootstrap adds to i18n -// when this module loads (0055). -import '../../../../../bootstrap/bootstrap.server'; - import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset'; import { GuestGuard } from '@lumina/market/app/guards/guest-guard'; import { ROUTES } from '@lumina/market/app/navigation'; -import { - GeneralRules, - generalRulesLabels, -} from '@lumina/market/app/screens/organisms/general-rules'; import { RegisterDetailsStep } from '@lumina/market/app/screens/(auth)/auth/register/details/organisms/register-details-step'; import type { Metadata } from 'next'; @@ -45,12 +37,6 @@ export default function RegisterDetailsPage() { size="lg" supportPlacement="bottom" haltPlacement="sheet" - rules={ - - } /> diff --git a/apps/bull/src/app/(flow)/terms/layout.tsx b/apps/bull/src/app/(flow)/terms/(tabs)/layout.tsx similarity index 74% rename from apps/bull/src/app/(flow)/terms/layout.tsx rename to apps/bull/src/app/(flow)/terms/(tabs)/layout.tsx index 08e65ce..39efb50 100644 --- a/apps/bull/src/app/(flow)/terms/layout.tsx +++ b/apps/bull/src/app/(flow)/terms/(tabs)/layout.tsx @@ -1,6 +1,6 @@ // First: the static `metadata` below reads a server-only namespace, which the server bootstrap // adds to i18n when this module loads, whichever module Next loads first (0055). -import '../../../bootstrap/bootstrap.server'; +import '../../../../bootstrap/bootstrap.server'; import { FlexBox } from '@lumina/island/atoms/flex-box'; import { MobileTopBar } from '@lumina/market/app/navigation'; @@ -8,7 +8,7 @@ import { RulesTabs } from '@lumina/market/app/screens/(flow)/terms/organisms/rul import type { Metadata } from 'next'; import type { ReactNode } from 'react'; -import { i18n } from '../../../i18n'; +import { i18n } from '../../../../i18n'; // Only the landing is indexed (0071); both tabs inherit this. export const metadata: Metadata = { @@ -18,9 +18,9 @@ export const metadata: Metadata = { }; /** - * «قوانین لومینا» on mobile (G-2r): a task page pushed from حساب کاربری, checkout, a suspended card - * or the support sheet: back · «قوانین لومینا» · support, no bottom nav, then the tab row - * «قوانین عمومی» · «شرایط اشتراک». Each tab is its own route with its own loading, so the bar and + * «قوانین و مقررات لومینا» on mobile (G-2r): a task page pushed from حساب کاربری, checkout, a suspended card + * or the support sheet: back · «قوانین و مقررات لومینا» · support, no bottom nav, then the tab row + * «قوانین و مقررات» · «شرایط اشتراک». Each tab is its own route with its own loading, so the bar and * the row stay while one loads; back returns to where the rules were opened. */ export default function RulesLayout({ children }: { children: ReactNode }) { diff --git a/apps/bull/src/app/(flow)/terms/loading.tsx b/apps/bull/src/app/(flow)/terms/(tabs)/loading.tsx similarity index 75% rename from apps/bull/src/app/(flow)/terms/loading.tsx rename to apps/bull/src/app/(flow)/terms/(tabs)/loading.tsx index d6762e6..ea2ec2b 100644 --- a/apps/bull/src/app/(flow)/terms/loading.tsx +++ b/apps/bull/src/app/(flow)/terms/(tabs)/loading.tsx @@ -1,8 +1,8 @@ import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton'; -import { i18n } from '../../../i18n'; +import { i18n } from '../../../../i18n'; -/** «قوانین عمومی» before it arrives, under the section's bar and tabs: a few sections' worth of lines. */ +/** «قوانین و مقررات» before it arrives, under the section's bar and tabs: a few sections' worth of lines. */ export default function Loading() { return ( diff --git a/apps/bull/src/app/(flow)/terms/(tabs)/page.tsx b/apps/bull/src/app/(flow)/terms/(tabs)/page.tsx new file mode 100644 index 0000000..0ce5136 --- /dev/null +++ b/apps/bull/src/app/(flow)/terms/(tabs)/page.tsx @@ -0,0 +1,18 @@ +// First: the static `metadata` below reads a server-only namespace, which the server bootstrap +// adds to i18n when this module loads, whichever module Next loads first (0055). +import '../../../../bootstrap/bootstrap.server'; + +import { LegalDocumentView } from '@lumina/market/app/screens/organisms/legal-document'; +import type { Metadata } from 'next'; + +import { i18n } from '../../../../i18n'; + +export const metadata: Metadata = { + title: i18n.t('rules:meta-title'), + description: i18n.t('rules:meta-description'), +}; + +/** «قوانین و مقررات», the first tab of «قوانین و مقررات لومینا» (G-2r); its text is read in the browser (0070). */ +export default function RulesPage() { + return ; +} diff --git a/apps/bull/src/app/(flow)/terms/subscription/loading.tsx b/apps/bull/src/app/(flow)/terms/(tabs)/subscription/loading.tsx similarity index 92% rename from apps/bull/src/app/(flow)/terms/subscription/loading.tsx rename to apps/bull/src/app/(flow)/terms/(tabs)/subscription/loading.tsx index 097d60f..b923aad 100644 --- a/apps/bull/src/app/(flow)/terms/subscription/loading.tsx +++ b/apps/bull/src/app/(flow)/terms/(tabs)/subscription/loading.tsx @@ -1,6 +1,6 @@ import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton'; -import { i18n } from '../../../../i18n'; +import { i18n } from '../../../../../i18n'; /** The terms before they arrive, under the section's bar and tabs: a few paragraphs' worth of lines. */ export default function Loading() { diff --git a/apps/bull/src/app/(flow)/terms/(tabs)/subscription/page.tsx b/apps/bull/src/app/(flow)/terms/(tabs)/subscription/page.tsx new file mode 100644 index 0000000..3fd5909 --- /dev/null +++ b/apps/bull/src/app/(flow)/terms/(tabs)/subscription/page.tsx @@ -0,0 +1,18 @@ +// First: the static `metadata` below reads a server-only namespace, which the server bootstrap +// adds to i18n when this module loads, whichever module Next loads first (0055). +import '../../../../../bootstrap/bootstrap.server'; + +import { SubscriptionTerms } from '@lumina/market/app/screens/(flow)/terms/subscription/organisms/subscription-terms'; +import type { Metadata } from 'next'; + +import { i18n } from '../../../../../i18n'; + +export const metadata: Metadata = { + title: i18n.t('terms:meta-title'), + description: i18n.t('terms:meta-description'), +}; + +/** «شرایط اشتراک», the second tab of «قوانین و مقررات لومینا» (S5, G-2); its text is read in the browser (0070). */ +export default function SubscriptionTermsPage() { + return ; +} diff --git a/apps/bull/src/app/(flow)/terms/analyst-agreement/layout.tsx b/apps/bull/src/app/(flow)/terms/analyst-agreement/layout.tsx new file mode 100644 index 0000000..e7c242a --- /dev/null +++ b/apps/bull/src/app/(flow)/terms/analyst-agreement/layout.tsx @@ -0,0 +1,37 @@ +// First: the static `metadata` below reads a server-only namespace, which the server bootstrap +// adds to i18n when this module loads, whichever module Next loads first (0055). +import '../../../../bootstrap/bootstrap.server'; + +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { MobileTopBar } from '@lumina/market/app/navigation'; +import type { Metadata } from 'next'; +import type { ReactNode } from 'react'; + +import { i18n } from '../../../../i18n'; + +export const metadata: Metadata = { + title: i18n.t('rules:agreement.meta-title'), + robots: { index: false }, +}; + +/** «توافق‌نامه تحلیلگر» on mobile: a task page pushed from حساب کاربری, with back and no bottom nav. */ +export default function AnalystAgreementLayout({ + children, +}: { + children: ReactNode; +}) { + const t = i18n.getFixedT(null, 'rules'); + + return ( + + + + {children} + + + ); +} diff --git a/apps/bull/src/app/(flow)/terms/analyst-agreement/loading.tsx b/apps/bull/src/app/(flow)/terms/analyst-agreement/loading.tsx new file mode 100644 index 0000000..693c5d5 --- /dev/null +++ b/apps/bull/src/app/(flow)/terms/analyst-agreement/loading.tsx @@ -0,0 +1,8 @@ +import { LegalDocumentSkeleton } from '@lumina/market/app/screens/organisms/legal-document'; + +import { i18n } from '../../../../i18n'; + +/** The agreement before it arrives, under the page's bar or title. */ +export default function Loading() { + return ; +} diff --git a/apps/bull/src/app/(flow)/terms/analyst-agreement/page.tsx b/apps/bull/src/app/(flow)/terms/analyst-agreement/page.tsx new file mode 100644 index 0000000..3d2ebee --- /dev/null +++ b/apps/bull/src/app/(flow)/terms/analyst-agreement/page.tsx @@ -0,0 +1,19 @@ +import { AuthGuard } from '@lumina/market/app/guards/auth-guard'; +import { AnalystAgreement } from '@lumina/market/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement'; +import { LegalDocumentSkeleton } from '@lumina/market/app/screens/organisms/legal-document'; + +import { i18n } from '../../../../i18n'; + +/** The agreement and the analyst's own record; both read in the browser (0070). Analysts only. */ +export default function AnalystAgreementPage() { + return ( + + } + > + + + ); +} diff --git a/apps/bull/src/app/(flow)/terms/page.tsx b/apps/bull/src/app/(flow)/terms/page.tsx deleted file mode 100644 index 2ead918..0000000 --- a/apps/bull/src/app/(flow)/terms/page.tsx +++ /dev/null @@ -1,26 +0,0 @@ -// First: the static `metadata` below reads a server-only namespace, which the server bootstrap -// adds to i18n when this module loads, whichever module Next loads first (0055). -import '../../../bootstrap/bootstrap.server'; - -import { - GeneralRules, - generalRulesLabels, -} from '@lumina/market/app/screens/organisms/general-rules'; -import type { Metadata } from 'next'; - -import { i18n } from '../../../i18n'; - -export const metadata: Metadata = { - title: i18n.t('rules:meta-title'), - description: i18n.t('rules:meta-description'), -}; - -/** «قوانین عمومی», the first tab of «قوانین لومینا» on mobile (G-2r), under the section's bar. */ -export default function GeneralRulesPage() { - return ( - - ); -} diff --git a/apps/bull/src/app/(flow)/terms/subscription/page.tsx b/apps/bull/src/app/(flow)/terms/subscription/page.tsx deleted file mode 100644 index c7db727..0000000 --- a/apps/bull/src/app/(flow)/terms/subscription/page.tsx +++ /dev/null @@ -1,39 +0,0 @@ -// First: the static `metadata` below reads a server-only namespace, which the server bootstrap -// adds to i18n when this module loads, whichever module Next loads first (0055). -import '../../../../bootstrap/bootstrap.server'; - -import { - SubscriptionTerms, - subscriptionTermsLabels, -} from '@lumina/market/app/screens/(flow)/terms/subscription/organisms/subscription-terms'; -import { supportChatUrls } from '@lumina/market/app/screens/organisms/support-entry'; -import { getEnv } from '@lumina/market/env'; -import type { Metadata } from 'next'; - -import { i18n } from '../../../../i18n'; - -export const metadata: Metadata = { - title: i18n.t('terms:meta-title'), - description: i18n.t('terms:meta-description'), -}; - -/** - * «شرایط اشتراک», the second tab of «قوانین لومینا» on mobile (S5 ۱.۱, G-2): the section's bar and - * tabs come from its layout; back returns to where the rules were opened (checkout, a suspended - * card, the support sheet). - */ -export default function SubscriptionTermsPage() { - const labels = subscriptionTermsLabels( - i18n.getFixedT(null, 'terms'), - i18n.getFixedT(null, 'auth'), - getEnv().supportHours, - ); - - return ( - - ); -} diff --git a/apps/bull/src/app/organisms/app-providers/AppProviders.tsx b/apps/bull/src/app/organisms/app-providers/AppProviders.tsx index e6b3522..7a7dd6f 100644 --- a/apps/bull/src/app/organisms/app-providers/AppProviders.tsx +++ b/apps/bull/src/app/organisms/app-providers/AppProviders.tsx @@ -12,7 +12,7 @@ import type { AppProvidersProps } from './types'; /** The app's root client component: runs the client bootstrap, then the platform's shell. */ export function AppProviders({ children }: AppProvidersProps) { return ( - + {children} ); diff --git a/apps/bull/src/bootstrap/bootstrap.client.ts b/apps/bull/src/bootstrap/bootstrap.client.ts index de32613..3e6efc6 100644 --- a/apps/bull/src/bootstrap/bootstrap.client.ts +++ b/apps/bull/src/bootstrap/bootstrap.client.ts @@ -9,6 +9,7 @@ import { AUTH_EVENTS, endSuspendedSession, isSessionSuspended, + noteAgreementRequired, suspendedSessionOf, } from '@lumina/market/features/auth'; @@ -45,6 +46,7 @@ http.configure({ http.interceptors.response.use(undefined, (error) => { const suspension = suspendedSessionOf(error); if (suspension) endSuspendedSession(suspension); + noteAgreementRequired(error); return error; }); configureErrorHandler(ERROR_HANDLER_CONFIG); diff --git a/docs/pages/README.md b/docs/pages/README.md index 0e34535..6e83bf2 100644 --- a/docs/pages/README.md +++ b/docs/pages/README.md @@ -6,13 +6,13 @@ bull (mobile) and bear (desktop) share one doc per route under `market/`, with b ## market -Only `/` is indexable (0071), and it is the only page whose content the server renders (0070). Every other page is `noindex`; all but the rules pages render their content in the browser. +Only `/` is indexable (0071), and it is the only page whose content the server renders (0070). Every other page is `noindex` and renders its content in the browser. Layouts and error pages: - root layout · [layout.md](market/layout.md) · — · — · browser: NetworkStatus, Toaster, ToastPlacementMarker (bear) - `(main)` layout · [layout-main.md](market/layout-main.md) · — · — · browser: bear header nav, search field, publish menu, notification bell, notification panel, login button or account menu, `@modal` slot; bull BottomNav -- `(flow)/terms` layout · [layout-terms.md](market/layout-terms.md) · — · — · browser: MobileTopBar title (bull), DesktopHeader viewer parts (bear) +- `(flow)/terms/(tabs)` layout · [layout-terms.md](market/layout-terms.md) · — · — · browser: MobileTopBar title (bull), DesktopHeader viewer parts (bear) - `(main)/dashboard/(creator)` layout · [layout-dashboard-creator.md](market/layout-dashboard-creator.md) · — · — · browser: OnboardingGuard redirect, notification bell and account avatar (bull) - `(main)/dashboard/(investor)` layout · [layout-dashboard-investor.md](market/layout-dashboard-investor.md) · — · — · browser: notification bell and account avatar (bull) - not-found and error · [not-found.md](market/not-found.md) · noindex · none · browser: not-found top bar, every group `error.tsx`, `global-error.tsx` @@ -20,8 +20,6 @@ Layouts and error pages: Rendered on the server: - `/` · [home.md](market/home.md) · index · FAQPage · browser: LandingRedirect -- `/terms` · [terms.md](market/terms.md) · noindex · none · browser: none -- `/terms/subscription` · [terms-subscription.md](market/terms-subscription.md) · noindex · none · browser: none `(main)`: @@ -44,6 +42,9 @@ Rendered on the server: `(flow)`: +- `/terms` · [terms.md](market/terms.md) · noindex · none · browser: LegalDocumentView +- `/terms/subscription` · [terms-subscription.md](market/terms-subscription.md) · noindex · none · browser: SubscriptionTerms +- `/terms/analyst-agreement` · [terms-analyst-agreement.md](market/terms-analyst-agreement.md) · noindex · none · browser: top-bar title, AnalystAgreement - `/account/profile` · [account-profile.md](market/account-profile.md) · noindex · none · browser: AccountProfile (investor form or creator profile edit), LeaveDialog - `/checkout/[username]` · [checkout-username.md](market/checkout-username.md) · noindex · none · browser: CheckoutCreator, CheckoutPanel, CheckoutForm (tiers, code, pay footer), CheckoutHalts, NoCodeSheet - `/compose/post` · [compose-post.md](market/compose-post.md) · noindex · none · browser: PostComposer, ComposerForm, LeaveConfirm, PostComposerDialog (bear `@modal`) diff --git a/docs/pages/market/account.md b/docs/pages/market/account.md index 5d09208..0764c48 100644 --- a/docs/pages/market/account.md +++ b/docs/pages/market/account.md @@ -17,17 +17,17 @@ In bull's document order. -| Section | Data | HTML | JS | Index | Notes | -| ------------------------------- | ------------- | ----------- | ------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| MobileTopBar (bull) | config | first flush | hydrate | no | a pushed page's bar: back and support | -| ↳ Title or login link (bull) | viewer | skeleton | hydrate | no | | -| DesktopPageTitle (bear) | config | first flush | hydrate | no | «بازگشت» and the H1 | -| AccountOverview | viewer | skeleton | hydrate | no | `AuthGuard` with `AccountOverviewSkeleton`, in `PartBoundary name="account-overview"`; bear: `framed` | -| ↳ IdentityCard, CreatorFacts | viewer, query | skeleton | hydrate | no | creators also get the review badge, followers and subscribers: browser `useQuery`s that never throw and leave out what fails | -| ↳ PrivacyNote | config | skeleton | hydrate | no | investors only | -| ↳ Settings and help lists | viewer | skeleton | hydrate | no | `ListRow` links to `/account/profile`, `/dashboard/finance#…` (creators), `/account/notifications`, `/account/install` (not in the installed app), `/terms`; پشتیبانی opens `SupportDialog` | -| ↳ Sign-out button | — | skeleton | hydrate | no | `SignOutConfirm` asks first (0041) | -| ↳ SupportDialog, SignOutConfirm | — | none | hydrate | no | rendered with `open`; statically imported | +| Section | Data | HTML | JS | Index | Notes | +| ------------------------------- | ------------- | ----------- | ------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| MobileTopBar (bull) | config | first flush | hydrate | no | a pushed page's bar: back and support | +| ↳ Title or login link (bull) | viewer | skeleton | hydrate | no | | +| DesktopPageTitle (bear) | config | first flush | hydrate | no | «بازگشت» and the H1 | +| AccountOverview | viewer | skeleton | hydrate | no | `AuthGuard` with `AccountOverviewSkeleton`, in `PartBoundary name="account-overview"`; bear: `framed` | +| ↳ IdentityCard, CreatorFacts | viewer, query | skeleton | hydrate | no | creators also get the review badge, followers and subscribers: browser `useQuery`s that never throw and leave out what fails | +| ↳ PrivacyNote | config | skeleton | hydrate | no | investors only | +| ↳ Settings and help lists | viewer | skeleton | hydrate | no | `ListRow` links to `/account/profile`, `/dashboard/finance#…` (creators), `/account/notifications`, `/account/install` (not in the installed app), `/terms`, `/terms/analyst-agreement` (creators, with version and date from `GET /me/legal-acceptances`); پشتیبانی opens `SupportDialog` | +| ↳ Sign-out button | — | skeleton | hydrate | no | `SignOutConfirm` asks first (0041) | +| ↳ SupportDialog, SignOutConfirm | — | none | hydrate | no | rendered with `open`; statically imported | ## Notes diff --git a/docs/pages/market/auth-login.md b/docs/pages/market/auth-login.md index 8ac2b18..5bc63a8 100644 --- a/docs/pages/market/auth-login.md +++ b/docs/pages/market/auth-login.md @@ -26,6 +26,7 @@ In bull's document order. | ↳ SupportDialog | config | none | hydrate | no | island `Dialog` mounts its content only while open | | NetworkBar | — | none | hydrate | no | under the bar, only while offline or reconnecting | | LoginStep | viewer | skeleton | hydrate | no | `GuestGuard` shows `SkeletonPreset preset="form"` until the viewer is known; guest: H1, phone form, register link, support; member: replaced to `?redirect=`, home, or step 5 when `needsProfile` | +| ↳ RulesCaption | config | none | hydrate | no | under the submit button; its link opens `LegalDocumentDialog`, which reads `GET /legal/platform_rules` only when opened; a sheet on bull, a modal on bear | ## Notes diff --git a/docs/pages/market/auth-register-details.md b/docs/pages/market/auth-register-details.md index 07a258d..461ad3a 100644 --- a/docs/pages/market/auth-register-details.md +++ b/docs/pages/market/auth-register-details.md @@ -17,21 +17,20 @@ In bull's document order. -| Section | Data | HTML | JS | Index | Notes | -| -------------------------- | ------ | ----------- | ------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -| AuthTopBar (bull) | config | first flush | none | no | back button and `auth:register.header` | -| ↳ BackButton (bull) | URL | first flush | hydrate | no | ``, keeping `?redirect=` | -| AuthTemplate header (bear) | config | first flush | none | no | brand `` | -| StepBack (bear) | URL | first flush | hydrate | no | «بازگشت» above the card to `/` | -| SupportEntry | — | first flush | hydrate | no | in the bar; the dialog mounts only when open | -| NetworkBar | — | none | hydrate | no | under the bar, only while offline or reconnecting | -| RegisterDetailsStep | viewer | skeleton | hydrate | no | `GuestGuard` fallback `SkeletonPreset preset="form" count={3}`; investor: `InvestorDetailsForm`; creator: `CreatorIdentityForm`, both in `DetailsFrame` | -| ↳ ExpiryWarning | clock | none | hydrate | no | two minutes before the token ends; `Countdown kind="otp"` and «تمدید زمان» | -| ↳ ExpiryHalt | viewer | none | hydrate | no | when the token ends; bull: sheet; bear: modal | -| ↳ LeaveRegistrationDialog | — | none | hydrate | no | back asks whether to leave and resume later (J02-3f) | -| ↳ RulesSheet | config | none | hydrate | no | «قوانین لومینا» in `TermsLine`; `GeneralRules` rendered on the server and passed as `rules`; bull: sheet; bear: modal; mounts when opened | +| Section | Data | HTML | JS | Index | Notes | +| -------------------------- | ------ | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| AuthTopBar (bull) | config | first flush | none | no | back button and `auth:register.header` | +| ↳ BackButton (bull) | URL | first flush | hydrate | no | ``, keeping `?redirect=` | +| AuthTemplate header (bear) | config | first flush | none | no | brand `` | +| StepBack (bear) | URL | first flush | hydrate | no | «بازگشت» above the card to `/` | +| SupportEntry | — | first flush | hydrate | no | in the bar; the dialog mounts only when open | +| NetworkBar | — | none | hydrate | no | under the bar, only while offline or reconnecting | +| RegisterDetailsStep | viewer | skeleton | hydrate | no | `GuestGuard` fallback `SkeletonPreset preset="form" count={3}`; investor: `InvestorDetailsForm`; creator: `CreatorIdentityForm`, both in `DetailsFrame` | +| ↳ ExpiryWarning | clock | none | hydrate | no | two minutes before the token ends; `Countdown kind="otp"` and «تمدید زمان» | +| ↳ ExpiryHalt | viewer | none | hydrate | no | when the token ends; bull: sheet; bear: modal | +| ↳ LeaveRegistrationDialog | — | none | hydrate | no | back asks whether to leave and resume later (J02-3f) | +| ↳ AgreementBlock (creator) | query | none | hydrate | no | the first block for an analyst: `GET /legal/analyst_agreement`, «خواندن متن» opens `LegalDocumentDialog`, the checkbox unfreezes «ثبت و ادامه», and the version goes with the form | ## Notes - Decision 0013: the step renders only in the browser on the 15-minute token, held in memory. -- `GeneralRules` is a Server Component passed into the client step, so its text is in the RSC payload of every response, though it reaches the DOM only when the sheet opens. diff --git a/docs/pages/market/auth-register-phone.md b/docs/pages/market/auth-register-phone.md index f351635..0d1afab 100644 --- a/docs/pages/market/auth-register-phone.md +++ b/docs/pages/market/auth-register-phone.md @@ -17,15 +17,16 @@ In bull's document order. -| Section | Data | HTML | JS | Index | Notes | -| -------------------------- | ------ | ----------- | ------- | ----- | -------------------------------------------------------------------------------------------------------- | -| AuthTopBar (bull) | config | first flush | none | no | back button and `auth:register.header` | -| ↳ BackButton (bull) | URL | first flush | hydrate | no | `` to `/auth/register`, keeping `?redirect=` | -| AuthTemplate header (bear) | config | first flush | none | no | brand `` | -| StepBack (bear) | URL | first flush | hydrate | no | «بازگشت» above the card to `/auth/register` | -| SupportEntry | — | first flush | hydrate | no | in the bar; the dialog mounts only when open | -| NetworkBar | — | none | hydrate | no | under the bar, only while offline or reconnecting | -| RegisterPhoneStep | viewer | skeleton | hydrate | no | `GuestGuard` fallback `SkeletonPreset preset="form" count={1}`; guest: progress, H1, phone form, support | +| Section | Data | HTML | JS | Index | Notes | +| -------------------------- | ------ | ----------- | ------- | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | +| AuthTopBar (bull) | config | first flush | none | no | back button and `auth:register.header` | +| ↳ BackButton (bull) | URL | first flush | hydrate | no | `` to `/auth/register`, keeping `?redirect=` | +| AuthTemplate header (bear) | config | first flush | none | no | brand `` | +| StepBack (bear) | URL | first flush | hydrate | no | «بازگشت» above the card to `/auth/register` | +| SupportEntry | — | first flush | hydrate | no | in the bar; the dialog mounts only when open | +| NetworkBar | — | none | hydrate | no | under the bar, only while offline or reconnecting | +| RegisterPhoneStep | viewer | skeleton | hydrate | no | `GuestGuard` fallback `SkeletonPreset preset="form" count={1}`; guest: progress, H1, phone form, support | +| ↳ RulesCaption | config | none | hydrate | no | under the submit button; its link opens `LegalDocumentDialog`, which reads `GET /legal/platform_rules` only when opened; a sheet on bull, a modal on bear | ## Notes diff --git a/docs/pages/market/feed.md b/docs/pages/market/feed.md index a3372e8..27bcef9 100644 --- a/docs/pages/market/feed.md +++ b/docs/pages/market/feed.md @@ -32,4 +32,4 @@ In bull's document order. ## Notes - bear: `@modal/feed/page.tsx` renders null, so a «پست جدید» dialog closes when a navigation lands on خانه (0023). -- Debt: no H1 in either app. Give the page an `sr-only` H1, as `GeneralRules` does. +- Debt: no H1 in either app. Give the page an `sr-only` H1, as `LegalDocumentView` does. diff --git a/docs/pages/market/layout-terms.md b/docs/pages/market/layout-terms.md index dca8bfc..3ac1141 100644 --- a/docs/pages/market/layout-terms.md +++ b/docs/pages/market/layout-terms.md @@ -1,10 +1,10 @@ # Layout: terms -`apps/{bull,bear}/src/app/(flow)/terms/layout.tsx` · wraps `/terms` and `/terms/subscription` · it awaits no read: its text is server i18n (`rules`), so it adds nothing to the first byte +`apps/{bull,bear}/src/app/(flow)/terms/(tabs)/layout.tsx` · wraps `/terms` and `/terms/subscription` · it awaits no read: its bar and tabs are server i18n (`rules`), so it adds nothing to the first byte; each page reads its text in the browser | Section | Data | HTML | JS | Index | Notes | | ------------------------------------ | ------ | ----------- | ------- | ----- | ----------------------------------------------------------------------------------------------------------------------------------------- | -| MobileTopBar (bull) | viewer | skeleton | hydrate | no | back to where the rules were opened, and support, in the first flush; the title «قوانین لومینا» waits for the viewer | +| MobileTopBar (bull) | viewer | skeleton | hydrate | no | back to where the rules were opened, and support, in the first flush; the title «قوانین و مقررات لومینا» waits for the viewer | | DesktopHeader (bear) | viewer | skeleton | hydrate | no | brand `` and support in the first flush; nav, bell, account menu and login wait for the viewer ([layout-main.md](layout-main.md)) | | DesktopPageTitle, with the H1 (bear) | config | first flush | hydrate | no | «بازگشت» and the H1 `rules:title`; bull puts its H1 in each page instead | | RulesTabs | config | first flush | hydrate | no | `TabLinks`: `` to `/terms` and `/terms/subscription`; `usePathname` marks the current tab | @@ -13,4 +13,4 @@ Scripts: none. - (flow) adds `force-dynamic` and no UI. The layout's static `metadata` gives `rules:meta-title` and `rules:meta-description`; each page overrides them. - bull: a white page with no bottom nav; bear: `DesktopHeader` over the 640px column, since (flow) has no header of its own. -- Debt: bear's H1 lives here, so `/terms/subscription` gets «قوانین لومینا» on bear and «شرایط اشتراک» on bull (`apps/bear/src/app/(flow)/terms/layout.tsx:40`). Pass each page's own title to `DesktopPageTitle`, or render the H1 in the page as bull does. +- Debt: bear's H1 lives here, so `/terms/subscription` gets «قوانین و مقررات لومینا» on bear and «شرایط اشتراک» on bull (`apps/bear/src/app/(flow)/terms/(tabs)/layout.tsx`). Pass each page's own title to `DesktopPageTitle`, or render the H1 in the page as bull does. diff --git a/docs/pages/market/terms-analyst-agreement.md b/docs/pages/market/terms-analyst-agreement.md new file mode 100644 index 0000000..e81207a --- /dev/null +++ b/docs/pages/market/terms-analyst-agreement.md @@ -0,0 +1,28 @@ +# Analyst agreement + +`/terms/analyst-agreement` · `apps/{bull,bear}/src/app/(flow)/terms/analyst-agreement/page.tsx` · Type: account and data · Layout: its own, [layout.md](layout.md) + +| Field | Value | +| ----------- | ------------------------------------------------------------------------ | +| Robots | `noindex` (the page's layout, 0071) | +| Status | `200` | +| loading.tsx | `apps/{bull,bear}/src/app/(flow)/terms/analyst-agreement/loading.tsx` | +| First flush | the bar or header and the title `rules:agreement.title` | +| Canonical | none: `noindex` | +| H1 | bull: the document's title, screen-reader-only; bear: `DesktopPageTitle` | +| JSON-LD | none | +| Scripts | none | + +## Sections + +In bull's document order. + +| Section | Data | HTML | JS | Index | Notes | +| -------------------------------------- | ------------- | ----------- | ------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------- | +| MobileTopBar (bull) | config | first flush | hydrate | no | back, with «توافق‌نامه تحلیلگر» as the title; no bottom nav | +| DesktopHeader, DesktopPageTitle (bear) | config | first flush | hydrate | no | the 640 column under the header | +| AnalystAgreement | viewer, query | skeleton | hydrate | no | `AuthGuard role="creator"`; `GET /legal/analyst_agreement`, then «نسخه … · پذیرفته‌شده در …، ساعت …» from `GET /me/legal-acceptances` | + +## Notes + +- It sits outside the `(tabs)` route group, so it has neither the tabs nor their title. diff --git a/docs/pages/market/terms-subscription.md b/docs/pages/market/terms-subscription.md index b399b03..8a13acc 100644 --- a/docs/pages/market/terms-subscription.md +++ b/docs/pages/market/terms-subscription.md @@ -1,26 +1,26 @@ # Subscription terms -`/terms/subscription` · `apps/{bull,bear}/src/app/(flow)/terms/subscription/page.tsx` · Type: static and policy · Layout: [layout-terms.md](layout-terms.md), [layout.md](layout.md) +`/terms/subscription` · `apps/{bull,bear}/src/app/(flow)/terms/(tabs)/subscription/page.tsx` · Type: account and data · Layout: [layout-terms.md](layout-terms.md), [layout.md](layout.md) -| Field | Value | -| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -| Robots | `noindex` (`terms` layout `metadata`, 0071) | -| Status | `200` | -| loading.tsx | `apps/{bull,bear}/src/app/(flow)/terms/subscription/loading.tsx` (debt, Notes) | -| First flush | none: config, server i18n (`terms`, `auth`) and `getEnv().supportHours` | -| Canonical | none: `noindex` | -| H1 | bull: `terms:title` «شرایط اشتراک», screen-reader-only, in `SubscriptionTerms`; bear: `rules:title` «قوانین لومینا» from the layout (debt) | -| JSON-LD | none | -| Scripts | none | +| Field | Value | +| ----------- | ------------------------------------------------------------------------------------------------------------------ | +| Robots | `noindex` (`terms` layout `metadata`, 0071) | +| Status | `200` | +| loading.tsx | `apps/{bull,bear}/src/app/(flow)/terms/(tabs)/subscription/loading.tsx` | +| First flush | the layout's bar and tabs | +| Canonical | none: `noindex` | +| H1 | bull: the document's title, screen-reader-only, in `LegalDocumentView`; bear: `rules:title` from the layout (debt) | +| JSON-LD | none | +| Scripts | none | ## Sections In bull's document order. -| Section | Data | HTML | JS | Index | Notes | -| ------------------------- | ------ | ----------- | ---- | ----- | ---------------------------------------------------------------------------------------------- | -| SubscriptionTerms | config | first flush | none | no | one `
` per term with its heading; bear: in a `Card` | -| ↳ Support hours and chats | config | first flush | none | no | island `SupportSheet` rows: `` to the Bale and Telegram chats, inside the last section | +| Section | Data | HTML | JS | Index | Notes | +| ------------------------- | ------ | -------- | ------- | ----- | ------------------------------------------------------------------------------------- | +| SubscriptionTerms | query | skeleton | hydrate | no | `GET /legal/subscription_terms` through `LegalDocumentView`; bear: in a `Card` | +| ↳ Support hours and chats | config | skeleton | hydrate | no | island `SupportSheet` rows: `` to the Bale and Telegram chats, under the text | ## Notes diff --git a/docs/pages/market/terms.md b/docs/pages/market/terms.md index 25030bc..a133d49 100644 --- a/docs/pages/market/terms.md +++ b/docs/pages/market/terms.md @@ -1,24 +1,27 @@ -# General rules +# Rules and regulations -`/terms` · `apps/{bull,bear}/src/app/(flow)/terms/page.tsx` · Type: static and policy · Layout: [layout-terms.md](layout-terms.md), [layout.md](layout.md) +`/terms` · `apps/{bull,bear}/src/app/(flow)/terms/(tabs)/page.tsx` · Type: account and data · Layout: [layout-terms.md](layout-terms.md), [layout.md](layout.md) -| Field | Value | -| ----------- | ------------------------------------------------------------------------------------------------------ | -| Robots | `noindex` (`terms` layout `metadata`, 0071) | -| Status | `200` | -| loading.tsx | `apps/{bull,bear}/src/app/(flow)/terms/loading.tsx` (debt, Notes) | -| First flush | none: config and server i18n (`rules`) | -| Canonical | none: `noindex` | -| H1 | `rules:title`; bull: a screen-reader-only H1 in `GeneralRules`; bear: `DesktopPageTitle` in the layout | -| JSON-LD | none | -| Scripts | none | +| Field | Value | +| ----------- | --------------------------------------------------------------------------------------------------------- | +| Robots | `noindex` (`terms` layout `metadata`, 0071) | +| Status | `200` | +| loading.tsx | `apps/{bull,bear}/src/app/(flow)/terms/(tabs)/loading.tsx` | +| First flush | the layout's bar and tabs | +| Canonical | none: `noindex` | +| H1 | bull: the document's title, screen-reader-only, in `LegalDocumentView`; bear: `rules:title` in the layout | +| JSON-LD | none | +| Scripts | none | ## Sections In bull's document order. -| Section | Data | HTML | JS | Index | Notes | -| ------------ | ------ | ----------- | ---- | ----- | ---------------------------------------------------------------------------------------- | -| GeneralRules | config | first flush | none | no | one `
` per rule with its heading, then the last-updated line; bear: in a `Card` | +| Section | Data | HTML | JS | Index | Notes | +| ----------------- | ----- | -------- | ------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| LegalDocumentView | query | skeleton | hydrate | no | `GET /legal/platform_rules` in the browser (0070), with `ErrorState` and a retry; «قوانین پلتفرم» and «حریم خصوصی», then the footer «نسخه … · آخرین به‌روزرسانی: …»; bear: in a `Card` | ## Notes + +- The text lives in the database, so it changes without a deploy (`features/legal`). `parseLegalMarkdown` turns it into blocks; it never renders as HTML. +- A major `platform_rules` version sends every user the `rules_updated` notification, which opens this page. diff --git a/packages/tools/src/format/format.ts b/packages/tools/src/format/format.ts index af184e3..8e1e2b1 100644 --- a/packages/tools/src/format/format.ts +++ b/packages/tools/src/format/format.ts @@ -156,6 +156,11 @@ export function ratio(a: number, b: number, decimals = 1): string { return iso(`${number(a)} : ${number(b, decimals)}`); } +/** A document's version: `1٫0`; the font shows Persian digits but not the decimal point. */ +export function version(value: string): string { + return value.replaceAll('.', DECIMAL_SEPARATOR); +} + /** Shamsi date in Tehran time: `15 خرداد 1404، ساعت 14:30`, or `15 خرداد 1404` with `{ time: false }`. */ export function date( value: DateInput, diff --git a/packages/tools/src/format/index.ts b/packages/tools/src/format/index.ts index 0d07ee9..70fab13 100644 --- a/packages/tools/src/format/index.ts +++ b/packages/tools/src/format/index.ts @@ -16,6 +16,7 @@ export { signed, signedPercent, time, + version, } from './format'; export { LOCALE, TIME_ZONE } from './constants'; export type { DateFormatOptions, DateInput, ShebaFormatOptions } from './types'; diff --git a/platforms/market/src/app/app-shell/AppShell.tsx b/platforms/market/src/app/app-shell/AppShell.tsx index 8120d73..1072c46 100644 --- a/platforms/market/src/app/app-shell/AppShell.tsx +++ b/platforms/market/src/app/app-shell/AppShell.tsx @@ -5,6 +5,7 @@ import { QueryClientProvider } from '@tanstack/react-query'; import { useEffect } from 'react'; import { I18nextProvider } from 'react-i18next'; +import { AgreementGate } from '../screens/organisms/agreement-gate'; import { useCheckoutDraftStore } from '../../stores/checkout-draft'; import { usePostDraftStore } from '../../stores/post-draft'; import { NetworkBoundary } from './components/NetworkBoundary'; @@ -23,9 +24,15 @@ import type { AppShellProps } from './types'; * * The toasts sit above whatever the screen declares with island's `useToastPlacement`: the bottom * nav (80px), a pinned footer (152px), the desktop app (32px, declared by bear's root layout), and - * low (24px) on a task page or over a sheet. + * low (24px) on a task page or over a sheet. An analyst who owes a newer major agreement gets its + * blocking modal over any page (J01-4). */ -export function AppShell({ queryClient, i18n, children }: AppShellProps) { +export function AppShell({ + queryClient, + i18n, + layout, + children, +}: AppShellProps) { useSession(queryClient); useSuspendedHalt(); useSettleAbandonedPayment(queryClient); @@ -40,6 +47,7 @@ export function AppShell({ queryClient, i18n, children }: AppShellProps) { {children} + {t('login.submit')} + ({ + legalRepository: { getDocument: vi.fn() }, +})); + +const i18n = createInstance(); +void i18n.use(initReactI18next).init({ + lng: 'fa', + resources, + interpolation: { escapeValue: false }, +}); + +const wrapper = ({ children }: { children: ReactNode }) => ( + + {children} + +); + +describe('RulesCaption', () => { + beforeEach(() => { + vi.mocked(legalRepository.getDocument).mockResolvedValue({ + key: 'platform_rules', + version: '1.0', + title: 'قوانین و مقررات لومینا', + bodyMd: '## قوانین پلتفرم\n\nمتن قوانین', + isMajor: false, + changeSummary: null, + publishedAt: '2026-11-01T00:00:00Z', + effectiveAt: '2026-11-01T00:00:00Z', + }); + }); + + it('says signing in accepts the rules, with no checkbox and no read yet', () => { + const { container } = render(, { + wrapper, + }); + expect(container.textContent).toContain( + 'ورود یا ثبت‌نام به معنی پذیرش قوانین و مقررات لومینا است.', + ); + expect(screen.queryByRole('checkbox')).toBeNull(); + expect(legalRepository.getDocument).not.toHaveBeenCalled(); + }); + + it('opens the rules with «متوجه شدم» from its link', async () => { + render(, { wrapper }); + await userEvent.click( + screen.getByRole('button', { name: 'قوانین و مقررات لومینا' }), + ); + expect(await screen.findByText('متن قوانین')).toBeTruthy(); + expect(screen.getByText('متوجه شدم')).toBeTruthy(); + expect(legalRepository.getDocument).toHaveBeenCalledWith( + { key: 'platform_rules' }, + expect.anything(), + ); + }); +}); diff --git a/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/RulesCaption.tsx b/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/RulesCaption.tsx new file mode 100644 index 0000000..ce42ef1 --- /dev/null +++ b/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/RulesCaption.tsx @@ -0,0 +1,46 @@ +'use client'; + +import { LinkButton } from '@lumina/island/atoms/link-button'; +import { Typography } from '@lumina/island/atoms/typography'; +import { useState } from 'react'; +import { Trans, useTranslation } from 'react-i18next'; + +import { LegalDocumentDialog } from '../../../../organisms/legal-document'; +import type { RulesCaptionProps } from './types'; + +/** + * Under «دریافت کد» on the login and sign-up phone pages: signing in or up accepts the rules, with + * no checkbox. The link opens them over the page, so the typed number stays. + */ +export function RulesCaption({ placement }: RulesCaptionProps) { + const { t } = useTranslation(['auth', 'legal']); + const [isOpen, setIsOpen] = useState(false); + + return ( + <> + + setIsOpen(true)} + > + {t('legal:dialog.rules-title')} + + ), + }} + /> + + setIsOpen(false)} + /> + + ); +} diff --git a/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/index.ts b/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/index.ts new file mode 100644 index 0000000..c23b29b --- /dev/null +++ b/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/index.ts @@ -0,0 +1,2 @@ +export { RulesCaption } from './RulesCaption'; +export type { RulesCaptionProps } from './types'; diff --git a/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/types.ts b/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/types.ts new file mode 100644 index 0000000..d45fa94 --- /dev/null +++ b/platforms/market/src/app/screens/(auth)/auth/organisms/rules-caption/types.ts @@ -0,0 +1,4 @@ +export type RulesCaptionProps = { + /** A bottom sheet on mobile, a modal on desktop. */ + placement: 'sheet' | 'modal'; +}; diff --git a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/AgreementBlock.tsx b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/AgreementBlock.tsx new file mode 100644 index 0000000..d82230e --- /dev/null +++ b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/AgreementBlock.tsx @@ -0,0 +1,66 @@ +'use client'; + +import { Checkbox } from '@lumina/island/atoms/checkbox'; +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { LinkButton } from '@lumina/island/atoms/link-button'; +import { Typography } from '@lumina/island/atoms/typography'; +import { Card } from '@lumina/island/molecules/card'; +import { ErrorState } from '@lumina/island/molecules/error-state'; +import { useState } from 'react'; +import { useTranslation } from 'react-i18next'; + +import { LegalDocumentDialog } from '../../../../../../../organisms/legal-document'; +import type { AgreementBlockProps } from '../types'; + +/** + * The first block of the analyst's sign-up (J02-4), before any identity data: read the agreement + * over the form, so nothing typed is lost, and tick that you accept it. The box can't be ticked + * until the version it accepts is known. + */ +export function AgreementBlock({ agreement, placement }: AgreementBlockProps) { + const { t } = useTranslation(['legal', 'errors']); + const [isReading, setIsReading] = useState(false); + + return ( + + + + + {t('agreement.kyc.title')} + + + {t('agreement.kyc.text')} + + + setIsReading(true)}> + {t('agreement.kyc.read')} + + {agreement.isError && ( + + )} + agreement.setTicked(event.target.checked)} + > + {t('agreement.kyc.checkbox')} + + + setIsReading(false)} + /> + + ); +} diff --git a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/CreatorIdentityForm.tsx b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/CreatorIdentityForm.tsx index 6936129..dd1d1b8 100644 --- a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/CreatorIdentityForm.tsx +++ b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/CreatorIdentityForm.tsx @@ -1,6 +1,5 @@ 'use client'; -import { Button } from '@lumina/island/atoms/button'; import { FileField } from '@lumina/island/molecules/file-field'; import { FormSection } from '@lumina/island/molecules/form-section'; import { TextInput } from '@lumina/island/molecules/text-input'; @@ -15,15 +14,16 @@ import { ID_CARD_SIDES, } from '../../../../../../../../../shared/validations'; import type { DetailsFormProps } from '../types'; +import { AgreementBlock } from './AgreementBlock'; import { DetailsFrame } from './DetailsFrame'; +import { IdentitySubmit } from './IdentitySubmit'; import { NameFields } from './NameFields'; -import { TermsLine } from './TermsLine'; import { UsernameField } from './UsernameField'; const BYTES_PER_MB = 1024 * 1024; /** - * Step 4 for a creator: the public username, then the private identity (names, national code, + * Step 4 for a creator: the analyst agreement before any identity data, 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; repeat taps are * ignored while sending, and a failure keeps every value and image. */ @@ -39,6 +39,7 @@ export function CreatorIdentityForm(props: DetailsFormProps) { progress, draft, leave, + agreement, } = useCreatorIdentityPart(props.partOptions); return ( @@ -51,24 +52,14 @@ export function CreatorIdentityForm(props: DetailsFormProps) { leave={leave} onSubmit={() => void submit()} footer={ - <> - - - + } > + {/* What investors see, and what only the review sees (its heading carries the lock). */} ({ + useTranslation: () => ({ t: (key: string) => key }), +})); + +const agreement = (isTicked: boolean) => ({ + version: '1.0', + isLoading: false, + isError: false, + isReloading: false, + reload: vi.fn(), + isTicked, + setTicked: vi.fn(), +}); + +const submit = () => + screen.getByText('register.identity.submit').closest('button')!; + +describe('IdentitySubmit', () => { + it('stays frozen with its reason until the agreement is ticked', () => { + render( + , + ); + expect(submit().classList.contains('frozen')).toBe(true); + expect(submit().getAttribute('type')).not.toBe('submit'); + expect(screen.getByText('legal:agreement.kyc.frozen')).toBeTruthy(); + }); + + it('submits once it is ticked', () => { + render( + , + ); + expect(submit().classList.contains('frozen')).toBe(false); + expect(submit().getAttribute('type')).toBe('submit'); + }); +}); diff --git a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/IdentitySubmit.tsx b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/IdentitySubmit.tsx new file mode 100644 index 0000000..cab85c8 --- /dev/null +++ b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/IdentitySubmit.tsx @@ -0,0 +1,27 @@ +import { Button } from '@lumina/island/atoms/button'; +import { useTranslation } from 'react-i18next'; + +import type { IdentitySubmitProps } from '../types'; + +/** «ثبت و ادامه», frozen with its reason until the agreement is ticked. */ +export function IdentitySubmit({ + agreement, + size, + isSubmitting, +}: IdentitySubmitProps) { + const { t } = useTranslation(['auth', 'legal']); + + return ( + + ); +} diff --git a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/InvestorDetailsForm.tsx b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/InvestorDetailsForm.tsx index a6c4d81..032f6a4 100644 --- a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/InvestorDetailsForm.tsx +++ b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/InvestorDetailsForm.tsx @@ -7,7 +7,6 @@ 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 «ساخت حساب». */ @@ -26,22 +25,15 @@ export function InvestorDetailsForm(props: DetailsFormProps) { leave={leave} onSubmit={() => void submit()} footer={ - <> - - - + } > diff --git a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/TermsLine.tsx b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/TermsLine.tsx deleted file mode 100644 index 4daf212..0000000 --- a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/TermsLine.tsx +++ /dev/null @@ -1,37 +0,0 @@ -'use client'; - -import { LinkButton } from '@lumina/island/atoms/link-button'; -import { Typography } from '@lumina/island/atoms/typography'; -import { useState } from 'react'; -import { useTranslation } from 'react-i18next'; - -import type { TermsLineProps } from '../types'; -import { RulesSheet } from './RulesSheet'; - -/** - * Accepting the rules by submitting, with no checkbox. «قوانین لومینا» opens the general rules in - * a sheet over the form (G-2s), so nothing typed is lost. - */ -export function TermsLine({ before, rules, placement }: TermsLineProps) { - const { t } = useTranslation('auth'); - const [isOpen, setIsOpen] = useState(false); - - return ( - <> - - {before} - setIsOpen(true)}> - {t('register.terms-link')} - - {t('register.terms-after')} - - setIsOpen(false)} - > - {rules} - - - ); -} diff --git a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/types.ts b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/types.ts index 54ba16e..4e23525 100644 --- a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/types.ts +++ b/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/types.ts @@ -2,6 +2,7 @@ import type { ReactNode } from 'react'; import type { Control, FieldValues, Path } from 'react-hook-form'; import type { + CreatorIdentityPartModel, RegisterDetailsPageModel, RegisterLeaveModel, UseDetailsPartOptions, @@ -14,12 +15,10 @@ export type RegisterDetailsStepProps = { size: 'md' | 'lg'; supportPlacement: SupportEntryProps['placement']; /** - * The halt when the token runs out, the leave dialog and the rules: a bottom sheet on mobile, a - * modal on desktop. + * The halt when the token runs out, the leave dialog and the agreement: a bottom sheet on mobile, + * a modal on desktop. */ haltPlacement: 'sheet' | 'modal'; - /** «قوانین عمومی», rendered on the server, for the terms line's rules sheet (G-2s). */ - rules: ReactNode; }; /** What each account type's form gets from the step. */ @@ -65,22 +64,6 @@ export type ExpiryHaltProps = { onConfirm: () => void; }; -export type TermsLineProps = { - /** «با ساخت حساب، » or «با ثبت اطلاعات، ». */ - before: string; - /** The general rules the link opens. */ - rules: ReactNode; - placement: RegisterDetailsStepProps['haltPlacement']; -}; - -export type RulesSheetProps = { - open: boolean; - placement: RegisterDetailsStepProps['haltPlacement']; - onClose: () => void; - /** The rules' text. */ - children: ReactNode; -}; - export type UsernameFieldProps = { control: Control; name: Path; @@ -98,3 +81,14 @@ export type NameFieldsProps = { /** Side by side on desktop. */ isPaired: boolean; }; + +export type AgreementBlockProps = { + agreement: CreatorIdentityPartModel['agreement']; + placement: RegisterDetailsStepProps['haltPlacement']; +}; + +export type IdentitySubmitProps = { + agreement: CreatorIdentityPartModel['agreement']; + size: RegisterDetailsStepProps['size']; + isSubmitting: boolean; +}; diff --git a/platforms/market/src/app/screens/(auth)/auth/register/phone/organisms/register-phone-step/RegisterPhoneStep.tsx b/platforms/market/src/app/screens/(auth)/auth/register/phone/organisms/register-phone-step/RegisterPhoneStep.tsx index 9c10ada..89b2a62 100644 --- a/platforms/market/src/app/screens/(auth)/auth/register/phone/organisms/register-phone-step/RegisterPhoneStep.tsx +++ b/platforms/market/src/app/screens/(auth)/auth/register/phone/organisms/register-phone-step/RegisterPhoneStep.tsx @@ -17,6 +17,7 @@ import { translateMessage } from '../../../../../../../../shared/utils'; import { useAuthRoutes } from '../../../../../../../navigation'; import { SupportEntry } from '../../../../../../organisms/support-entry'; import { RegisterProgress } from '../../../../../../organisms/register-progress'; +import { RulesCaption } from '../../../../organisms/rules-caption'; import type { RegisterPhoneStepProps } from './types'; /** @@ -149,6 +150,7 @@ export function RegisterPhoneStep({ > {t('register.phone.submit')} + + {acceptance && ( + + {t('agreement.record', { + version: version(acceptance.version), + date: date(acceptance.acceptedAt, { time: false }), + time: time(acceptance.acceptedAt), + })} + + )} + + ); +} diff --git a/platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/index.ts b/platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/index.ts new file mode 100644 index 0000000..493cb90 --- /dev/null +++ b/platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/index.ts @@ -0,0 +1,2 @@ +export { AnalystAgreement } from './AnalystAgreement'; +export type { AnalystAgreementProps } from './types'; diff --git a/platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/types.ts b/platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/types.ts new file mode 100644 index 0000000..be62799 --- /dev/null +++ b/platforms/market/src/app/screens/(flow)/terms/analyst-agreement/organisms/analyst-agreement/types.ts @@ -0,0 +1,3 @@ +export type AnalystAgreementProps = { + layout: 'mobile' | 'desktop'; +}; diff --git a/platforms/market/src/app/screens/(flow)/terms/organisms/rules-tabs/RulesTabs.tsx b/platforms/market/src/app/screens/(flow)/terms/organisms/rules-tabs/RulesTabs.tsx index dc54a99..522860a 100644 --- a/platforms/market/src/app/screens/(flow)/terms/organisms/rules-tabs/RulesTabs.tsx +++ b/platforms/market/src/app/screens/(flow)/terms/organisms/rules-tabs/RulesTabs.tsx @@ -7,7 +7,7 @@ import { ROUTES } from '../../../../../navigation'; import type { RulesTabsProps } from './types'; /** - * «قوانین لومینا»'s two tabs (G-2r): «قوانین عمومی» · «شرایط اشتراک», the current one from the URL, + * «قوانین و مقررات لومینا»'s two tabs (G-2r): «قوانین و مقررات» · «شرایط اشتراک», the current one from the URL, * which the server render already knows. The section's layout renders it once, so it stays put * while a tab loads. A tab replaces the history entry, so back still returns to the page that * opened the rules. diff --git a/platforms/market/src/app/screens/(flow)/terms/organisms/rules-tabs/types.ts b/platforms/market/src/app/screens/(flow)/terms/organisms/rules-tabs/types.ts index 843797a..b986591 100644 --- a/platforms/market/src/app/screens/(flow)/terms/organisms/rules-tabs/types.ts +++ b/platforms/market/src/app/screens/(flow)/terms/organisms/rules-tabs/types.ts @@ -1,7 +1,7 @@ export type RulesTabsLabels = { - /** The nav's name: «قوانین لومینا». */ + /** The nav's name: «قوانین و مقررات لومینا». */ label: string; - /** «قوانین عمومی». */ + /** «قوانین و مقررات». */ general: string; /** «شرایط اشتراک». */ subscription: string; diff --git a/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/SubscriptionTerms.tsx b/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/SubscriptionTerms.tsx index ecd05f6..a389e71 100644 --- a/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/SubscriptionTerms.tsx +++ b/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/SubscriptionTerms.tsx @@ -1,85 +1,39 @@ +'use client'; + import { FlexBox } from '@lumina/island/atoms/flex-box'; import { Typography } from '@lumina/island/atoms/typography'; import { SupportSheet } from '@lumina/island/organisms/support-sheet'; -import { Element } from '@lumina/island/primitives/element'; +import { useTranslation } from 'react-i18next'; +import { getEnv } from '../../../../../../../env'; +import { LegalDocumentView } from '../../../../../organisms/legal-document'; +import { supportChatUrls } from '../../../../../organisms/support-entry'; import type { SubscriptionTermsProps } from './types'; -/** - * «شرایط اشتراک» (S5): eight numbered sections, verbatim. In §۳ the two options sit as a numbered - * list on a sunken panel with bold lead-ins, between its first paragraph and the rest; §۸ ends with - * the support hours and the two chat rows. The same for every visitor, so it renders on the server. - */ -export function SubscriptionTerms({ - layout, - chats, - labels, -}: SubscriptionTermsProps) { - const last = labels.sections.length - 1; +/** «شرایط اشتراک» (S5): the versioned text, then the support hours and the two chat rows. */ +export function SubscriptionTerms({ layout }: SubscriptionTermsProps) { + const { t } = useTranslation(['legal', 'auth']); + const chats = supportChatUrls(); return ( - - {/* Desktop's column title is the h1; the mobile bar's name is not a heading. */} - {layout === 'mobile' && ( - - {labels.title} + + + + {t('subscription.hours', { hours: getEnv().supportHours })} - )} - {labels.sections.map((section, index) => { - const [first, ...rest] = section.paragraphs; - const titleId = `terms-${section.id}`; - return ( - - - {section.title} - - {first} - {section.options && ( - - {section.options.map((option) => ( - - - - {option.lead} - {' '} - {option.text} - - - ))} - - )} - {rest.map((paragraph) => ( - {paragraph} - ))} - {index === last && ( - <> - {labels.hours} - - - )} - - ); - })} - + + + ); } diff --git a/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/index.ts b/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/index.ts index 4dc14ab..b8d29e1 100644 --- a/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/index.ts +++ b/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/index.ts @@ -1,7 +1,2 @@ -export { subscriptionTermsLabels } from './labels'; export { SubscriptionTerms } from './SubscriptionTerms'; -export type { - SubscriptionTermsLabels, - SubscriptionTermsProps, - TermsSection, -} from './types'; +export type { SubscriptionTermsProps } from './types'; diff --git a/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/labels.ts b/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/labels.ts deleted file mode 100644 index 8fbdb99..0000000 --- a/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/labels.ts +++ /dev/null @@ -1,54 +0,0 @@ -import type { TFunction } from 'i18next'; - -import type { SubscriptionTermsLabels, TermsSection } from './types'; - -/** The terms' text, from the server's translations (0020), verbatim from S5. */ -export function subscriptionTermsLabels( - t: TFunction<'terms'>, - tAuth: TFunction<'auth'>, - hours: string, -): SubscriptionTermsLabels { - const sections: TermsSection[] = [ - { id: 's1', title: t('s1.title'), paragraphs: [t('s1.p1'), t('s1.p2')] }, - { - id: 's2', - title: t('s2.title'), - paragraphs: [t('s2.p1'), t('s2.p2'), t('s2.p3')], - }, - { - id: 's3', - title: t('s3.title'), - paragraphs: [t('s3.p1'), t('s3.p2'), t('s3.p3'), t('s3.p4')], - options: [ - { lead: t('s3.refund-lead'), text: t('s3.refund') }, - { lead: t('s3.wait-lead'), text: t('s3.wait') }, - ], - }, - { id: 's4', title: t('s4.title'), paragraphs: [t('s4.p1'), t('s4.p2')] }, - { - id: 's5', - title: t('s5.title'), - paragraphs: [t('s5.p1'), t('s5.p2'), t('s5.p3')], - }, - { - id: 's6', - title: t('s6.title'), - paragraphs: [t('s6.p1'), t('s6.p2'), t('s6.p3')], - }, - { id: 's7', title: t('s7.title'), paragraphs: [t('s7.p1'), t('s7.p2')] }, - { id: 's8', title: t('s8.title'), paragraphs: [t('s8.p1')] }, - ]; - - return { - title: t('title'), - sections, - hours: t('s8.hours', { hours }), - support: { - title: tAuth('support.title'), - bale: tAuth('support.bale'), - telegram: tAuth('support.telegram'), - close: tAuth('support.close'), - opensNewTab: tAuth('support.opens-new-tab'), - }, - }; -} diff --git a/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/types.ts b/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/types.ts index 94e32f2..ea8596b 100644 --- a/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/types.ts +++ b/platforms/market/src/app/screens/(flow)/terms/subscription/organisms/subscription-terms/types.ts @@ -1,29 +1,3 @@ -import type { SupportSheetLabels } from '@lumina/island/organisms/support-sheet'; - -/** One numbered section: its paragraphs, and §۳'s two options after its first paragraph. */ -export type TermsSection = { - id: string; - title: string; - paragraphs: string[]; - options?: { lead: string; text: string }[]; -}; - -export type SubscriptionTermsLabels = { - /** The page's name: «شرایط اشتراک». */ - title: string; - sections: TermsSection[]; - /** §۸'s line: «زمان پاسخگویی: …» with the configured hours. */ - hours: string; - support: SupportSheetLabels; -}; - export type SubscriptionTermsProps = { - /** - * Mobile adds the page's h1 for screen readers, since its bar names the page in plain text; - * desktop's column title (DesktopPageTitle) is the h1. - */ layout: 'mobile' | 'desktop'; - /** The support chats' addresses, from config. */ - chats: { bale: string; telegram: string }; - labels: SubscriptionTermsLabels; }; diff --git a/platforms/market/src/app/screens/(main)/account/organisms/account-overview/AccountOverview.tsx b/platforms/market/src/app/screens/(main)/account/organisms/account-overview/AccountOverview.tsx index 74cb173..c979341 100644 --- a/platforms/market/src/app/screens/(main)/account/organisms/account-overview/AccountOverview.tsx +++ b/platforms/market/src/app/screens/(main)/account/organisms/account-overview/AccountOverview.tsx @@ -4,11 +4,13 @@ import { Button } from '@lumina/island/atoms/button'; import { FlexBox } from '@lumina/island/atoms/flex-box'; import { Typography } from '@lumina/island/atoms/typography'; import { List, ListRow } from '@lumina/island/molecules/list-row'; +import { date, version } from '@lumina/tools/format'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useAccountOverview } from '../../../../../../features/account'; import { PAYOUT_ACCOUNT_ANCHOR } from '../../../../../../features/finance'; +import { useAgreementAcceptance } from '../../../../../../features/legal'; import { useIsStandalone } from '../../../../../navigation/hooks/use-is-standalone'; import { ROUTES } from '../../../../../navigation/navigation'; import { SignOutConfirm } from '../../../../organisms/sign-out-confirm'; @@ -21,7 +23,7 @@ import type { AccountOverviewProps } from './types'; * حساب کاربری (J12-1, J12-1b), the member's own page: whose account it is, then اطلاعات کاربری, * an analyst's اطلاعات تسویه‌حساب (their شبا on داشبورد › مالی, or its empty state), تنظیمات * اعلان‌ها and نصب اپلیکیشن (hidden in the installed app); then پشتیبانی, which opens the support - * sheet, and قوانین و مقررات; then «خروج از حساب», which asks first (J12-1d), and the version. + * sheet, قوانین و مقررات لومینا and an analyst's توافق‌نامه تحلیلگر; then «خروج از حساب», which asks first (J12-1d), and the version. */ export function AccountOverview({ layout }: AccountOverviewProps) { const { t } = useTranslation('account'); @@ -30,6 +32,7 @@ export function AccountOverview({ layout }: AccountOverviewProps) { const [isSupportOpen, setSupportOpen] = useState(false); const [isSigningOut, setSigningOut] = useState(false); const { creator } = model; + const acceptance = useAgreementAcceptance(); return ( + {creator && ( + + )} + + + ); +} diff --git a/platforms/market/src/app/screens/organisms/agreement-gate/components/GateBody.tsx b/platforms/market/src/app/screens/organisms/agreement-gate/components/GateBody.tsx new file mode 100644 index 0000000..2a82c32 --- /dev/null +++ b/platforms/market/src/app/screens/organisms/agreement-gate/components/GateBody.tsx @@ -0,0 +1,80 @@ +import { Checkbox } from '@lumina/island/atoms/checkbox'; +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { LinkButton } from '@lumina/island/atoms/link-button'; +import { Skeleton } from '@lumina/island/atoms/skeleton'; +import { Typography } from '@lumina/island/atoms/typography'; +import { ErrorState } from '@lumina/island/molecules/error-state'; +import { version } from '@lumina/tools/format'; +import { useTranslation } from 'react-i18next'; + +import { LegalDocumentBody } from '../../legal-document'; +import type { GateBodyProps } from '../types'; + +/** + * What the analyst reads and ticks: what changed in this version, the way to the whole text, which + * opens inside the dialog so the block never lifts, and the checkbox. + */ +export function GateBody({ model }: GateBodyProps) { + const { t } = useTranslation(['legal', 'errors']); + const { agreement } = model; + const { document } = agreement; + + if (agreement.isLoading) return ; + if (!document) { + return ( + void agreement.reload()} + retryLabel={t('errors:fallback.retry')} + retryingLabel={t('errors:fallback.retrying')} + retrying={agreement.isReloading} + /> + ); + } + + if (model.view === 'full') { + return ( + + + {t('agreement.gate.back')} + + + + + + ); + } + + return ( + + {t('agreement.gate.body')} + {document.changeSummary && ( + + + {t('agreement.gate.changes', { + version: version(document.version), + })} + + + {document.changeSummary} + + + )} + + {t('agreement.gate.read')} + + model.setTicked(event.target.checked)} + > + {t('agreement.gate.checkbox')} + + + ); +} diff --git a/platforms/market/src/app/screens/organisms/agreement-gate/index.ts b/platforms/market/src/app/screens/organisms/agreement-gate/index.ts new file mode 100644 index 0000000..b7a3971 --- /dev/null +++ b/platforms/market/src/app/screens/organisms/agreement-gate/index.ts @@ -0,0 +1,2 @@ +export { AgreementGate } from './AgreementGate'; +export type { AgreementGateProps } from './types'; diff --git a/platforms/market/src/app/screens/organisms/agreement-gate/types.ts b/platforms/market/src/app/screens/organisms/agreement-gate/types.ts new file mode 100644 index 0000000..f4dfb81 --- /dev/null +++ b/platforms/market/src/app/screens/organisms/agreement-gate/types.ts @@ -0,0 +1,11 @@ +import type { AgreementGateModel } from '../../../../features/legal'; + +export type AgreementGateProps = { layout: 'mobile' | 'desktop' }; + +export type GateBodyProps = { model: AgreementGateModel }; + +export type GateActionsProps = { + model: AgreementGateModel; + layout: AgreementGateProps['layout']; + onSignOut: () => void; +}; diff --git a/platforms/market/src/app/screens/organisms/general-rules/GeneralRules.tsx b/platforms/market/src/app/screens/organisms/general-rules/GeneralRules.tsx deleted file mode 100644 index d34fda8..0000000 --- a/platforms/market/src/app/screens/organisms/general-rules/GeneralRules.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { FlexBox } from '@lumina/island/atoms/flex-box'; -import { Typography } from '@lumina/island/atoms/typography'; - -import type { GeneralRulesProps } from './types'; - -/** - * «قوانین عمومی» of «قوانین لومینا» (G-2r): seven numbered sections, verbatim, then when they last - * changed. The same for every visitor, so it renders on the server: on its tab, and inside the - * registration form's rules sheet (G-2s), which gets it rendered. - */ -export function GeneralRules({ layout, labels }: GeneralRulesProps) { - return ( - - {/* Desktop's column title is the h1; the mobile bar's name is not a heading. */} - {layout === 'mobile' && ( - - {labels.title} - - )} - {labels.sections.map((section) => { - const titleId = `rules-${layout}-${section.id}`; - return ( - - - {section.title} - - {section.paragraphs.map((paragraph) => ( - {paragraph} - ))} - - ); - })} - - {labels.updated} - - - ); -} diff --git a/platforms/market/src/app/screens/organisms/general-rules/index.ts b/platforms/market/src/app/screens/organisms/general-rules/index.ts deleted file mode 100644 index 6791983..0000000 --- a/platforms/market/src/app/screens/organisms/general-rules/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export { GeneralRules } from './GeneralRules'; -export { generalRulesLabels } from './labels'; -export type { - GeneralRulesLabels, - GeneralRulesProps, - RulesSection, -} from './types'; diff --git a/platforms/market/src/app/screens/organisms/general-rules/labels.ts b/platforms/market/src/app/screens/organisms/general-rules/labels.ts deleted file mode 100644 index 335114c..0000000 --- a/platforms/market/src/app/screens/organisms/general-rules/labels.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { TFunction } from 'i18next'; - -import type { GeneralRulesLabels, RulesSection } from './types'; - -/** «قوانین عمومی»'s text, from the server's translations (0020), verbatim from G-2r. */ -export function generalRulesLabels(t: TFunction<'rules'>): GeneralRulesLabels { - const sections: RulesSection[] = [ - { id: 's1', title: t('s1.title'), paragraphs: [t('s1.p1'), t('s1.p2')] }, - { id: 's2', title: t('s2.title'), paragraphs: [t('s2.p1')] }, - { id: 's3', title: t('s3.title'), paragraphs: [t('s3.p1')] }, - { id: 's4', title: t('s4.title'), paragraphs: [t('s4.p1')] }, - { id: 's5', title: t('s5.title'), paragraphs: [t('s5.p1')] }, - { id: 's6', title: t('s6.title'), paragraphs: [t('s6.p1')] }, - { id: 's7', title: t('s7.title'), paragraphs: [t('s7.p1')] }, - ]; - return { title: t('title'), sections, updated: t('updated') }; -} diff --git a/platforms/market/src/app/screens/organisms/general-rules/types.ts b/platforms/market/src/app/screens/organisms/general-rules/types.ts deleted file mode 100644 index 0327458..0000000 --- a/platforms/market/src/app/screens/organisms/general-rules/types.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** One numbered section of the general rules: its title and paragraphs. */ -export type RulesSection = { - id: string; - title: string; - paragraphs: string[]; -}; - -export type GeneralRulesLabels = { - /** The page's name: «قوانین لومینا». */ - title: string; - sections: RulesSection[]; - /** «آخرین به‌روزرسانی: …», the caption last. */ - updated: string; -}; - -export type GeneralRulesProps = { - /** - * mobile: adds the page's h1 for screen readers, since its bar names the page in plain text. - * desktop: the column title is the h1. sheet: the sheet's title names it. - */ - layout: 'mobile' | 'desktop' | 'sheet'; - labels: GeneralRulesLabels; -}; diff --git a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/RulesSheet.tsx b/platforms/market/src/app/screens/organisms/legal-document/LegalDocumentDialog.tsx similarity index 63% rename from platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/RulesSheet.tsx rename to platforms/market/src/app/screens/organisms/legal-document/LegalDocumentDialog.tsx index 60faabf..5f19c31 100644 --- a/platforms/market/src/app/screens/(auth)/auth/register/details/organisms/register-details-step/components/RulesSheet.tsx +++ b/platforms/market/src/app/screens/organisms/legal-document/LegalDocumentDialog.tsx @@ -6,21 +6,25 @@ import { Modal } from '@lumina/island/molecules/modal'; import { Sheet } from '@lumina/island/molecules/sheet'; import { useTranslation } from 'react-i18next'; -import type { RulesSheetProps } from '../types'; +import { LegalDocumentView } from './LegalDocumentView'; +import type { LegalDocumentDialogProps } from './types'; /** - * «قوانین لومینا» over the registration form (G-2s): the general rules, rendered on the server and - * passed in, with one «متوجه شدم» that closes it. A bottom sheet on mobile, the 640 modal on - * desktop; Escape and the scrim close it too. + * A legal document over the page, so nothing typed under it is lost (G-2s, G-2u): one «متوجه شدم» + * closes it. A bottom sheet on mobile, the 640 modal on desktop; Escape and the scrim close it too. + * It reads the document only once it opens. */ -export function RulesSheet({ +export function LegalDocumentDialog({ + documentKey, + title, open, placement, onClose, - children, -}: RulesSheetProps) { - const { t } = useTranslation('auth'); - const title = t('register.rules-title'); +}: LegalDocumentDialogProps) { + const { t } = useTranslation('legal'); + const body = open && ( + + ); const close = ( ); if (placement === 'sheet') { return ( - {children} + {body} ); } @@ -46,7 +50,7 @@ export function RulesSheet({ direction="flex-col" className="min-h-0 flex-1 overflow-auto p-6" > - {children} + {body} ; + if (isError || !document) { + return ( + void reload()} + retryLabel={t('errors:fallback.retry')} + retryingLabel={t('errors:fallback.retrying')} + retrying={isReloading} + /> + ); + } + + return ( + + {layout === 'mobile' && ( + + {document.title} + + )} + + {children} + + {t('document.footer', { + version: version(document.version), + date: date(document.publishedAt, { time: false }), + })} + + + ); +} diff --git a/platforms/market/src/app/screens/organisms/legal-document/components/LegalDocumentBody.tsx b/platforms/market/src/app/screens/organisms/legal-document/components/LegalDocumentBody.tsx new file mode 100644 index 0000000..969a2b7 --- /dev/null +++ b/platforms/market/src/app/screens/organisms/legal-document/components/LegalDocumentBody.tsx @@ -0,0 +1,94 @@ +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { Typography } from '@lumina/island/atoms/typography'; +import { Element } from '@lumina/island/primitives/element'; +import { useMemo } from 'react'; + +import { parseLegalMarkdown } from '../../../../../features/legal'; +import type { LegalInline } from '../../../../../features/legal'; +import type { LegalDocumentBodyProps } from '../types'; + +function Inlines({ inlines }: { inlines: LegalInline[] }) { + return inlines.map((inline, index) => + inline.bold ? ( + // The text never changes while it is shown, so its place is its identity. + // oxlint-disable-next-line react/no-array-index-key + + {inline.text} + + ) : ( + inline.text + ), + ); +} + +/** A legal document's text, parsed rather than injected, so it can never carry markup. */ +export function LegalDocumentBody({ bodyMd }: LegalDocumentBodyProps) { + const blocks = useMemo(() => parseLegalMarkdown(bodyMd), [bodyMd]); + + return ( + + {blocks.map((block, index) => { + // Blocks of one version never reorder, and their text may repeat. + const key = `${block.kind}-${index}`; + switch (block.kind) { + case 'section': + return ( + + + + ); + case 'subsection': + return ( + + + + ); + case 'quote': + return ( + + + + ); + case 'list': + return ( + + {block.items.map((item, itemIndex) => ( + // oxlint-disable-next-line react/no-array-index-key + + + + + + ))} + + ); + default: + return ( + + + + ); + } + })} + + ); +} diff --git a/platforms/market/src/app/screens/organisms/legal-document/components/LegalDocumentSkeleton.tsx b/platforms/market/src/app/screens/organisms/legal-document/components/LegalDocumentSkeleton.tsx new file mode 100644 index 0000000..35b50ed --- /dev/null +++ b/platforms/market/src/app/screens/organisms/legal-document/components/LegalDocumentSkeleton.tsx @@ -0,0 +1,15 @@ +import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton'; + +/** A document's place while it loads: a few sections' worth of lines. */ +export function LegalDocumentSkeleton({ label }: { label: string }) { + return ( + + + + + + + + + ); +} diff --git a/platforms/market/src/app/screens/organisms/legal-document/index.ts b/platforms/market/src/app/screens/organisms/legal-document/index.ts new file mode 100644 index 0000000..7bffc45 --- /dev/null +++ b/platforms/market/src/app/screens/organisms/legal-document/index.ts @@ -0,0 +1,9 @@ +export { LegalDocumentBody } from './components/LegalDocumentBody'; +export { LegalDocumentSkeleton } from './components/LegalDocumentSkeleton'; +export { LegalDocumentDialog } from './LegalDocumentDialog'; +export { LegalDocumentView } from './LegalDocumentView'; +export type { + LegalDocumentBodyProps, + LegalDocumentDialogProps, + LegalDocumentViewProps, +} from './types'; diff --git a/platforms/market/src/app/screens/organisms/legal-document/types.ts b/platforms/market/src/app/screens/organisms/legal-document/types.ts new file mode 100644 index 0000000..4c8a09b --- /dev/null +++ b/platforms/market/src/app/screens/organisms/legal-document/types.ts @@ -0,0 +1,25 @@ +import type { ReactNode } from 'react'; + +import type { LegalDocumentKey } from '../../../../features/legal'; + +export type LegalDocumentBodyProps = { bodyMd: string }; + +export type LegalDocumentViewProps = { + documentKey: LegalDocumentKey; + /** + * mobile adds the document's title as an h1 for screen readers, since its bar names the page in + * plain text. desktop's column title and a dialog's title are the heading already. + */ + layout: 'mobile' | 'desktop' | 'dialog'; + /** Under the text, such as the analyst's own record or the support chats. */ + children?: ReactNode; +}; + +export type LegalDocumentDialogProps = { + documentKey: LegalDocumentKey; + title: string; + open: boolean; + /** A bottom sheet on mobile, the 640 modal on desktop. */ + placement: 'sheet' | 'modal'; + onClose: () => void; +}; diff --git a/platforms/market/src/features/auth/actions/agreement-required/actions.ts b/platforms/market/src/features/auth/actions/agreement-required/actions.ts new file mode 100644 index 0000000..5f54135 --- /dev/null +++ b/platforms/market/src/features/auth/actions/agreement-required/actions.ts @@ -0,0 +1,19 @@ +import { isHttpError } from '@lumina/libs/http'; + +import { useAuthStore } from '../../../../stores/auth'; + +const AGREEMENT_REQUIRED = 'agreement_required'; + +/** + * A 403 `agreement_required` on any call means a newer major agreement came out during the session: + * the shell's blocking modal opens. The 422 of the same code belongs to the sign-up form. + */ +export function noteAgreementRequired(error: unknown): void { + if ( + isHttpError(error) && + error.status === 403 && + error.code === AGREEMENT_REQUIRED + ) { + useAuthStore.getState().setAgreementRequired(true); + } +} diff --git a/platforms/market/src/features/auth/actions/agreement-required/index.ts b/platforms/market/src/features/auth/actions/agreement-required/index.ts new file mode 100644 index 0000000..6ab5aff --- /dev/null +++ b/platforms/market/src/features/auth/actions/agreement-required/index.ts @@ -0,0 +1 @@ +export { noteAgreementRequired } from './actions'; diff --git a/platforms/market/src/features/auth/actions/register-creator/actions.ts b/platforms/market/src/features/auth/actions/register-creator/actions.ts index 313d26d..47a2df8 100644 --- a/platforms/market/src/features/auth/actions/register-creator/actions.ts +++ b/platforms/market/src/features/auth/actions/register-creator/actions.ts @@ -37,6 +37,8 @@ export async function registerCreator( useAuthStore.getState().setSession({ account: registration.account, needsProfile: registration.profileSetupRequired, + // Registration itself accepted the latest agreement. + agreementRequired: false, }); if (emit) { eventEmitter.emit(AUTH_EVENTS.register, { diff --git a/platforms/market/src/features/auth/actions/restore-session/actions.ts b/platforms/market/src/features/auth/actions/restore-session/actions.ts index 5698e08..3f0b7dd 100644 --- a/platforms/market/src/features/auth/actions/restore-session/actions.ts +++ b/platforms/market/src/features/auth/actions/restore-session/actions.ts @@ -29,7 +29,8 @@ export async function restoreSession({ const { setSession, clearSession } = useAuthStore.getState(); let status: ViewerStatus; try { - const { account, needsProfile } = await authRepository.getSession(); + const { account, needsProfile, agreementRequired } = + await authRepository.getSession(); if (account?.status === 'suspended') { // An API that still answers the session of a suspended account: close it, then halt (J01-3d). void authRepository @@ -40,7 +41,7 @@ export async function restoreSession({ endSuspendedSession({ role: account.role, reason: null }); status = 'guest'; } else if (account) { - setSession({ account, needsProfile }); + setSession({ account, needsProfile, agreementRequired }); status = 'member'; } else { clearSession(); diff --git a/platforms/market/src/features/auth/index.ts b/platforms/market/src/features/auth/index.ts index 9a7760a..adf61f6 100644 --- a/platforms/market/src/features/auth/index.ts +++ b/platforms/market/src/features/auth/index.ts @@ -5,6 +5,7 @@ export { isSessionSuspended, suspendedSessionOf, } from './actions/end-suspended-session'; +export { noteAgreementRequired } from './actions/agreement-required'; export { login } from './actions/login'; export type { LoginOutcome } from './actions/login'; export { logout } from './actions/logout'; diff --git a/platforms/market/src/features/auth/models/register-details/types.ts b/platforms/market/src/features/auth/models/register-details/types.ts index 0af4cbe..490fc20 100644 --- a/platforms/market/src/features/auth/models/register-details/types.ts +++ b/platforms/market/src/features/auth/models/register-details/types.ts @@ -94,6 +94,17 @@ export type CreatorIdentityPartModel = { pickImage: (side: IdCardSide, file: File | null) => void; /** 0–100 while the images upload. */ progress: number | undefined; + /** The analyst agreement, ticked before anything is sent. */ + agreement: { + /** The version the tick accepts; null until it has been read. */ + version: string | null; + isLoading: boolean; + isError: boolean; + isReloading: boolean; + reload: () => void; + isTicked: boolean; + setTicked: (ticked: boolean) => void; + }; draft: () => RegistrationDraft; leave: RegisterLeaveModel; }; diff --git a/platforms/market/src/features/auth/models/register-details/use-creator-identity-part.ts b/platforms/market/src/features/auth/models/register-details/use-creator-identity-part.ts index fc91384..a330a55 100644 --- a/platforms/market/src/features/auth/models/register-details/use-creator-identity-part.ts +++ b/platforms/market/src/features/auth/models/register-details/use-creator-identity-part.ts @@ -1,5 +1,6 @@ import { valibotResolver } from '@hookform/resolvers/valibot'; import { showToast } from '@lumina/island/molecules/toast'; +import { isHttpError } from '@lumina/libs/http'; import { useRouter } from 'next/navigation'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; @@ -16,6 +17,7 @@ import type { CreatorIdentityFormValues, } from '../../../../shared/validations'; import { useAuthFlowStore } from '../../../../stores/auth-flow'; +import { LEGAL_ERROR_CODES, useLegalDocument } from '../../../legal'; import { registerCreator } from '../../actions/register-creator'; import { AUTH_ERROR_CODES, @@ -52,13 +54,14 @@ type Submission = * with progress; repeat taps are ignored while sending. Errors show on blur and on submit, the username's also as * it is typed. The username stands in for the display name the API wants now; the profile step * sets the real one. The text fields are saved as a draft on the server (never the images), and - * leaving asks first (J02-3f). + * leaving asks first (J02-3f). The analyst agreement is ticked first and travels with the version + * read, which the API checks is still the latest. */ export function useCreatorIdentityPart({ profileHref, onExpired, }: UseDetailsPartOptions): CreatorIdentityPartModel { - const { t } = useTranslation('auth'); + const { t } = useTranslation(['auth', 'legal']); const router = useRouter(); const [draft] = useState(() => useAuthFlowStore.getState().draft); const [submission, setSubmission] = useState({ phase: 'idle' }); @@ -80,6 +83,9 @@ export function useCreatorIdentityPart({ idCardBack: draft?.idCardBack ?? null, }, }); + const agreementDocument = useLegalDocument('analyst_agreement'); + const [agreementTicked, setAgreementTicked] = useState(false); + const agreementVersion = agreementDocument.document?.version; const username = useUsernameAvailability(form); const { errors, isSubmitting } = form.formState; const saveDraft = useRegistrationAutosave(form); @@ -104,6 +110,7 @@ export function useCreatorIdentityPart({ }; const submit = form.handleSubmit(async (values) => { + if (!agreementTicked || agreementVersion === undefined) return; const { phone, registration } = useAuthFlowStore.getState(); if (!phone || !registration) { onExpired(); @@ -131,6 +138,7 @@ export function useCreatorIdentityPart({ nationalIdNumber: values.nationalId, nationalIdFrontImage: values.idCardFront, nationalIdBackImage: values.idCardBack, + agreementVersion, }, { signal, @@ -149,6 +157,16 @@ export function useCreatorIdentityPart({ onExpired(); return; } + // A newer version came out while the form was open: it reads again and asks again. + if ( + isHttpError(error) && + error.code === LEGAL_ERROR_CODES.agreementRequired + ) { + setAgreementTicked(false); + void agreementDocument.reload(); + showToast({ tone: 'error', message: t('legal:agreement.kyc.changed') }); + return; + } applyServerErrors(form, renameFieldErrors(error, FORM_FIELDS), { t, failedMessage: t('register.identity.failed'), @@ -167,5 +185,14 @@ export function useCreatorIdentityPart({ submission.phase === 'uploading' ? submission.progress : undefined, draft: () => form.getValues(), leave, + agreement: { + version: agreementVersion ?? null, + isLoading: agreementDocument.isLoading, + isError: agreementDocument.isError, + isReloading: agreementDocument.isReloading, + reload: () => void agreementDocument.reload(), + isTicked: agreementTicked, + setTicked: setAgreementTicked, + }, }; } diff --git a/platforms/market/src/features/auth/repositories/auth/mappers.ts b/platforms/market/src/features/auth/repositories/auth/mappers.ts index 05a2a1d..1dbfd3e 100644 --- a/platforms/market/src/features/auth/repositories/auth/mappers.ts +++ b/platforms/market/src/features/auth/repositories/auth/mappers.ts @@ -58,6 +58,7 @@ export function toRegisterCreatorFormData(args: RegisterCreatorArgs): FormData { ...toRegisterInvestorDto(args), displayName: args.displayName.trim(), nationalIdNumber: args.nationalIdNumber.trim(), + agreementVersion: args.agreementVersion, }; for (const [name, value] of Object.entries(fields)) form.append(name, value); form.append('nationalIdFrontImage', args.nationalIdFrontImage); @@ -144,6 +145,7 @@ export function toSessionPayload(dto: SessionResponseDto): SessionPayload { return { account: toAccountPayload(dto.user), needsProfile: needsProfileOf(dto), + agreementRequired: dto.agreementRequired ?? false, }; } @@ -151,8 +153,12 @@ export function toSessionStatePayload( dto: SessionStateResponseDto, ): SessionStatePayload { return dto.user - ? { account: toAccountPayload(dto.user), needsProfile: needsProfileOf(dto) } - : { account: null, needsProfile: false }; + ? { + account: toAccountPayload(dto.user), + needsProfile: needsProfileOf(dto), + agreementRequired: dto.agreementRequired ?? false, + } + : { account: null, needsProfile: false, agreementRequired: false }; } export function toCreatorRegisteredPayload( diff --git a/platforms/market/src/features/auth/repositories/auth/types.ts b/platforms/market/src/features/auth/repositories/auth/types.ts index fb4595f..fb54963 100644 --- a/platforms/market/src/features/auth/repositories/auth/types.ts +++ b/platforms/market/src/features/auth/repositories/auth/types.ts @@ -108,6 +108,8 @@ export type RegisterCreatorArgs = RegisterInvestorArgs & { nationalIdNumber: string; nationalIdFrontImage: File; nationalIdBackImage: File; + /** The agreement version the creator ticked; the API refuses anything but the latest. */ + agreementVersion: string; }; /** Sign-in and registration set the HttpOnly session cookies; the body carries the account. */ @@ -116,18 +118,32 @@ export type SessionResponseDto = { userType: UserRole; /** Missing from an older gateway. */ needsProfile?: boolean; + agreementRequired?: boolean; +}; +/** + * `needsProfile`: a creator who has not finished registration step 5. `agreementRequired`: a + * creator who owes a newer major agreement. Both always false for an investor. + */ +export type SessionPayload = { + account: AccountPayload; + needsProfile: boolean; + agreementRequired: boolean; }; -/** `needsProfile`: a creator who has not finished registration step 5; always false for an investor. */ -export type SessionPayload = { account: AccountPayload; needsProfile: boolean }; /** A guest gets `{ user: null }`, never a 401, so a guest never starts a refresh. */ export type SessionStateResponseDto = - | { user: UserEntity; userType: UserRole; needsProfile?: boolean } + | { + user: UserEntity; + userType: UserRole; + needsProfile?: boolean; + agreementRequired?: boolean; + } | { user: null }; -/** A guest is `{ account: null, needsProfile: false }`. */ +/** A guest is `{ account: null, needsProfile: false, agreementRequired: false }`. */ export type SessionStatePayload = { account: AccountPayload | null; needsProfile: boolean; + agreementRequired: boolean; }; export type CreatorRegisteredResponseDto = { diff --git a/platforms/market/src/features/legal/actions/accept-agreement/actions.ts b/platforms/market/src/features/legal/actions/accept-agreement/actions.ts new file mode 100644 index 0000000..c473f90 --- /dev/null +++ b/platforms/market/src/features/legal/actions/accept-agreement/actions.ts @@ -0,0 +1,28 @@ +import { eventEmitter } from '@lumina/libs/event-emitter'; + +import { useAuthStore } from '../../../../stores/auth'; +import { LEGAL_EVENTS } from '../../constants'; +import { legalRepository } from '../../repositories/legal'; +import type { + AcceptDocumentArgs, + AcceptedDocumentPayload, +} from '../../repositories/legal'; + +/** + * Accepts a version of a document and, when nothing newer is owed, lifts the agreement's block on + * the session. Emits `legal.agreement-accepted`. + */ +export async function acceptAgreement( + args: AcceptDocumentArgs, + { emit = true }: { emit?: boolean } = {}, +): Promise { + const accepted = await legalRepository.accept(args); + useAuthStore.getState().setAgreementRequired(accepted.agreementRequired); + if (emit) { + eventEmitter.emit(LEGAL_EVENTS.agreementAccepted, { + document: accepted.document, + version: accepted.version, + }); + } + return accepted; +} diff --git a/platforms/market/src/features/legal/actions/accept-agreement/index.ts b/platforms/market/src/features/legal/actions/accept-agreement/index.ts new file mode 100644 index 0000000..ecf5f56 --- /dev/null +++ b/platforms/market/src/features/legal/actions/accept-agreement/index.ts @@ -0,0 +1 @@ +export { acceptAgreement } from './actions'; diff --git a/platforms/market/src/features/legal/constants.ts b/platforms/market/src/features/legal/constants.ts new file mode 100644 index 0000000..97bb1b9 --- /dev/null +++ b/platforms/market/src/features/legal/constants.ts @@ -0,0 +1,9 @@ +export const LEGAL_EVENTS = { + agreementAccepted: 'legal.agreement-accepted', +} as const; + +/** The API's refusal when the agreement version sent isn't the one that counts. */ +export const LEGAL_ERROR_CODES = { + agreementRequired: 'agreement_required', + versionOutdated: 'agreement_version_outdated', +} as const; diff --git a/platforms/market/src/features/legal/entities/legal-document/index.ts b/platforms/market/src/features/legal/entities/legal-document/index.ts new file mode 100644 index 0000000..6077617 --- /dev/null +++ b/platforms/market/src/features/legal/entities/legal-document/index.ts @@ -0,0 +1,5 @@ +export type { + LegalAcceptanceEntity, + LegalDocumentEntity, + LegalDocumentKey, +} from './types'; diff --git a/platforms/market/src/features/legal/entities/legal-document/types.ts b/platforms/market/src/features/legal/entities/legal-document/types.ts new file mode 100644 index 0000000..f7bc314 --- /dev/null +++ b/platforms/market/src/features/legal/entities/legal-document/types.ts @@ -0,0 +1,22 @@ +/** The back end's three versioned documents. */ +export type LegalDocumentKey = + | 'platform_rules' + | 'analyst_agreement' + | 'subscription_terms'; + +export type LegalDocumentEntity = { + key: LegalDocumentKey; + version: string; + title: string; + bodyMd: string; + isMajor: boolean; + changeSummary: string | null; + publishedAt: string; + effectiveAt: string; +}; + +export type LegalAcceptanceEntity = { + document: LegalDocumentKey; + version: string; + acceptedAt: string; +}; diff --git a/platforms/market/src/features/legal/http.ts b/platforms/market/src/features/legal/http.ts new file mode 100644 index 0000000..3b8eb8d --- /dev/null +++ b/platforms/market/src/features/legal/http.ts @@ -0,0 +1,3 @@ +import { http } from '@lumina/libs/http'; + +export const legalHttp = http.extend({}); diff --git a/platforms/market/src/features/legal/index.ts b/platforms/market/src/features/legal/index.ts new file mode 100644 index 0000000..9f22926 --- /dev/null +++ b/platforms/market/src/features/legal/index.ts @@ -0,0 +1,26 @@ +import './types'; + +export { acceptAgreement } from './actions/accept-agreement'; +export { LEGAL_ERROR_CODES, LEGAL_EVENTS } from './constants'; +export type { + LegalAcceptanceEntity, + LegalDocumentEntity, + LegalDocumentKey, +} from './entities/legal-document'; +export { useAgreementAcceptance } from './models/agreement-acceptance'; +export { useAgreementGate } from './models/agreement-gate'; +export type { + AgreementGateModel, + AgreementGateView, +} from './models/agreement-gate'; +export { useLegalDocument } from './models/legal-document'; +export type { LegalDocumentModel } from './models/legal-document'; +export { legalKeys, legalRepository } from './repositories/legal'; +export type { + AcceptDocumentArgs, + AcceptedDocumentPayload, + LegalAcceptancePayload, + LegalDocumentPayload, +} from './repositories/legal'; +export { parseLegalMarkdown } from './utils/parse-legal-markdown'; +export type { LegalBlock, LegalInline } from './utils/parse-legal-markdown'; diff --git a/platforms/market/src/features/legal/models/agreement-acceptance/index.ts b/platforms/market/src/features/legal/models/agreement-acceptance/index.ts new file mode 100644 index 0000000..2373fb8 --- /dev/null +++ b/platforms/market/src/features/legal/models/agreement-acceptance/index.ts @@ -0,0 +1 @@ +export { useAgreementAcceptance } from './use-agreement-acceptance'; diff --git a/platforms/market/src/features/legal/models/agreement-acceptance/use-agreement-acceptance.ts b/platforms/market/src/features/legal/models/agreement-acceptance/use-agreement-acceptance.ts new file mode 100644 index 0000000..44aa99c --- /dev/null +++ b/platforms/market/src/features/legal/models/agreement-acceptance/use-agreement-acceptance.ts @@ -0,0 +1,20 @@ +import { useQuery } from '@tanstack/react-query'; + +import { useViewerStatus } from '../../../../stores/auth'; +import { legalKeys, legalRepository } from '../../repositories/legal'; +import type { LegalAcceptancePayload } from '../../repositories/legal'; + +/** The newest analyst agreement this analyst accepted; null while unknown or when there is none. */ +export function useAgreementAcceptance(): LegalAcceptancePayload | null { + const status = useViewerStatus(); + const { data } = useQuery({ + queryKey: legalKeys.acceptances(), + queryFn: ({ signal }) => legalRepository.listAcceptances({ signal }), + enabled: status === 'member', + throwOnError: false, + }); + return ( + data?.find((acceptance) => acceptance.document === 'analyst_agreement') ?? + null + ); +} diff --git a/platforms/market/src/features/legal/models/agreement-gate/index.ts b/platforms/market/src/features/legal/models/agreement-gate/index.ts new file mode 100644 index 0000000..796c61c --- /dev/null +++ b/platforms/market/src/features/legal/models/agreement-gate/index.ts @@ -0,0 +1,2 @@ +export type { AgreementGateModel, AgreementGateView } from './types'; +export { useAgreementGate } from './use-agreement-gate'; diff --git a/platforms/market/src/features/legal/models/agreement-gate/types.ts b/platforms/market/src/features/legal/models/agreement-gate/types.ts new file mode 100644 index 0000000..37579d4 --- /dev/null +++ b/platforms/market/src/features/legal/models/agreement-gate/types.ts @@ -0,0 +1,17 @@ +import type { LegalDocumentModel } from '../legal-document'; + +/** summary: what changed and the checkbox. full: the whole text, with the way back. */ +export type AgreementGateView = 'summary' | 'full'; + +export type AgreementGateModel = { + isOpen: boolean; + agreement: LegalDocumentModel; + view: AgreementGateView; + showFullText: () => void; + showSummary: () => void; + isTicked: boolean; + setTicked: (ticked: boolean) => void; + canAccept: boolean; + isAccepting: boolean; + accept: () => void; +}; diff --git a/platforms/market/src/features/legal/models/agreement-gate/use-agreement-gate.ts b/platforms/market/src/features/legal/models/agreement-gate/use-agreement-gate.ts new file mode 100644 index 0000000..8ea7104 --- /dev/null +++ b/platforms/market/src/features/legal/models/agreement-gate/use-agreement-gate.ts @@ -0,0 +1,67 @@ +import { showToast } from '@lumina/island/molecules/toast'; +import { isHttpError } from '@lumina/libs/http'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { useState } from 'react'; +import { useTranslation } from 'react-i18next'; + +import { showActionError } from '../../../../shared/utils'; +import { useAgreementRequired } from '../../../../stores/auth'; +import { acceptAgreement } from '../../actions/accept-agreement'; +import { LEGAL_ERROR_CODES } from '../../constants'; +import { legalKeys } from '../../repositories/legal'; +import { useLegalDocument } from '../legal-document'; +import type { AgreementGateModel, AgreementGateView } from './types'; + +/** + * The blocking re-acceptance (J01-4): open while a newer major agreement is owed, learned from the + * session or from a 403 on any call. «پذیرش و ادامه» needs the box ticked. If a newer version came + * out while it was open, the text reads again and the box empties, so nobody accepts unread text. + */ +export function useAgreementGate(): AgreementGateModel { + const { t } = useTranslation('legal'); + const queryClient = useQueryClient(); + const isOpen = useAgreementRequired(); + const agreement = useLegalDocument('analyst_agreement', { enabled: isOpen }); + const [view, setView] = useState('summary'); + const [isTicked, setTicked] = useState(false); + + const accept = useMutation({ + mutationFn: (version: string) => + acceptAgreement({ document: 'analyst_agreement', version }), + onSuccess: () => { + void queryClient.invalidateQueries({ + queryKey: legalKeys.acceptances(), + }); + setTicked(false); + setView('summary'); + showToast({ tone: 'success', message: t('agreement.gate.accepted') }); + }, + onError: (error) => { + if ( + isHttpError(error) && + error.code === LEGAL_ERROR_CODES.versionOutdated + ) { + setTicked(false); + void agreement.reload(); + } + showActionError(error, { t, failedMessage: t('agreement.gate.failed') }); + }, + }); + + const version = agreement.document?.version; + + return { + isOpen, + agreement, + view, + showFullText: () => setView('full'), + showSummary: () => setView('summary'), + isTicked, + setTicked, + canAccept: isTicked && version !== undefined, + isAccepting: accept.isPending, + accept: () => { + if (isTicked && version !== undefined) accept.mutate(version); + }, + }; +} diff --git a/platforms/market/src/features/legal/models/legal-document/index.ts b/platforms/market/src/features/legal/models/legal-document/index.ts new file mode 100644 index 0000000..e459dfa --- /dev/null +++ b/platforms/market/src/features/legal/models/legal-document/index.ts @@ -0,0 +1,2 @@ +export type { LegalDocumentModel } from './types'; +export { useLegalDocument } from './use-legal-document'; diff --git a/platforms/market/src/features/legal/models/legal-document/types.ts b/platforms/market/src/features/legal/models/legal-document/types.ts new file mode 100644 index 0000000..d60cfa2 --- /dev/null +++ b/platforms/market/src/features/legal/models/legal-document/types.ts @@ -0,0 +1,10 @@ +import type { LegalDocumentPayload } from '../../repositories/legal'; + +export type LegalDocumentModel = { + document: LegalDocumentPayload | null; + isLoading: boolean; + isError: boolean; + isReloading: boolean; + /** Reads the document again; resolves with the newest version it got. */ + reload: () => Promise<{ data?: LegalDocumentPayload }>; +}; diff --git a/platforms/market/src/features/legal/models/legal-document/use-legal-document.ts b/platforms/market/src/features/legal/models/legal-document/use-legal-document.ts new file mode 100644 index 0000000..ca3a92e --- /dev/null +++ b/platforms/market/src/features/legal/models/legal-document/use-legal-document.ts @@ -0,0 +1,28 @@ +import { useQuery } from '@tanstack/react-query'; + +import type { LegalDocumentKey } from '../../entities/legal-document'; +import { legalKeys, legalRepository } from '../../repositories/legal'; +import type { LegalDocumentModel } from './types'; + +/** + * A legal document's latest version, read in the browser (0070). Its failure stays with the part + * that shows it, which offers `reload`, so a form around it keeps working. + */ +export function useLegalDocument( + key: LegalDocumentKey, + { enabled = true }: { enabled?: boolean } = {}, +): LegalDocumentModel { + const query = useQuery({ + queryKey: legalKeys.document(key), + queryFn: ({ signal }) => legalRepository.getDocument({ key }, { signal }), + enabled, + throwOnError: false, + }); + return { + document: query.data ?? null, + isLoading: query.isPending && enabled, + isError: query.isError, + isReloading: query.isRefetching, + reload: () => query.refetch(), + }; +} diff --git a/platforms/market/src/features/legal/repositories/legal/constants.ts b/platforms/market/src/features/legal/repositories/legal/constants.ts new file mode 100644 index 0000000..1860213 --- /dev/null +++ b/platforms/market/src/features/legal/repositories/legal/constants.ts @@ -0,0 +1,14 @@ +import type { LegalDocumentKey } from '../../entities/legal-document'; + +export const LEGAL_ENDPOINTS = { + document: (key: LegalDocumentKey) => `/legal/${key}`, + acceptances: '/me/legal-acceptances', + accept: '/me/agreements', +} as const; + +export const legalKeys = { + all: ['legal'] as const, + document: (key: LegalDocumentKey) => + [...legalKeys.all, 'document', key] as const, + acceptances: () => [...legalKeys.all, 'acceptances'] as const, +}; diff --git a/platforms/market/src/features/legal/repositories/legal/index.ts b/platforms/market/src/features/legal/repositories/legal/index.ts new file mode 100644 index 0000000..373940e --- /dev/null +++ b/platforms/market/src/features/legal/repositories/legal/index.ts @@ -0,0 +1,9 @@ +export { LEGAL_ENDPOINTS, legalKeys } from './constants'; +export { legalRepository } from './legal'; +export type { + AcceptDocumentArgs, + AcceptedDocumentPayload, + GetDocumentArgs, + LegalAcceptancePayload, + LegalDocumentPayload, +} from './types'; diff --git a/platforms/market/src/features/legal/repositories/legal/legal.ts b/platforms/market/src/features/legal/repositories/legal/legal.ts new file mode 100644 index 0000000..9b393f2 --- /dev/null +++ b/platforms/market/src/features/legal/repositories/legal/legal.ts @@ -0,0 +1,52 @@ +import { legalHttp } from '../../http'; +import { LEGAL_ENDPOINTS } from './constants'; +import { + toAcceptDocumentDto, + toAcceptedDocumentPayload, + toLegalAcceptancesPayload, + toLegalDocumentPayload, +} from './mappers'; +import type { + AcceptDocumentArgs, + AcceptDocumentResponseDto, + AcceptedDocumentPayload, + GetDocumentArgs, + LegalAcceptancePayload, + LegalAcceptancesResponseDto, + LegalDocumentPayload, + LegalDocumentResponseDto, +} from './types'; + +/** The versioned legal documents (public) and the signed-in user's acceptances. */ +export const legalRepository = { + /** The latest version; the text changes without a deploy. */ + async getDocument( + { key }: GetDocumentArgs, + { signal }: { signal?: AbortSignal } = {}, + ): Promise { + const response = await legalHttp.get( + LEGAL_ENDPOINTS.document(key), + { signal }, + ); + return toLegalDocumentPayload(response); + }, + + async listAcceptances({ signal }: { signal?: AbortSignal } = {}): Promise< + LegalAcceptancePayload[] + > { + const response = await legalHttp.get( + LEGAL_ENDPOINTS.acceptances, + { signal }, + ); + return toLegalAcceptancesPayload(response); + }, + + /** 422 `agreement_version_outdated` unless the version is still the latest. */ + async accept(args: AcceptDocumentArgs): Promise { + const response = await legalHttp.post( + LEGAL_ENDPOINTS.accept, + toAcceptDocumentDto(args), + ); + return toAcceptedDocumentPayload(response); + }, +}; diff --git a/platforms/market/src/features/legal/repositories/legal/mappers.ts b/platforms/market/src/features/legal/repositories/legal/mappers.ts new file mode 100644 index 0000000..2ebb973 --- /dev/null +++ b/platforms/market/src/features/legal/repositories/legal/mappers.ts @@ -0,0 +1,52 @@ +import type { + AcceptDocumentArgs, + AcceptDocumentDto, + AcceptDocumentResponseDto, + AcceptedDocumentPayload, + LegalAcceptancePayload, + LegalAcceptancesResponseDto, + LegalDocumentPayload, + LegalDocumentResponseDto, +} from './types'; + +export function toLegalDocumentPayload( + dto: LegalDocumentResponseDto, +): LegalDocumentPayload { + return { + key: dto.key, + version: dto.version, + title: dto.title, + bodyMd: dto.bodyMd, + isMajor: dto.isMajor, + changeSummary: dto.changeSummary, + publishedAt: dto.publishedAt, + effectiveAt: dto.effectiveAt, + }; +} + +export function toLegalAcceptancesPayload( + dto: LegalAcceptancesResponseDto, +): LegalAcceptancePayload[] { + return dto.items.map(({ document, version, acceptedAt }) => ({ + document, + version, + acceptedAt, + })); +} + +export function toAcceptDocumentDto( + args: AcceptDocumentArgs, +): AcceptDocumentDto { + return { document: args.document, version: args.version }; +} + +export function toAcceptedDocumentPayload( + dto: AcceptDocumentResponseDto, +): AcceptedDocumentPayload { + return { + document: dto.document, + version: dto.version, + acceptedAt: dto.acceptedAt, + agreementRequired: dto.agreementRequired, + }; +} diff --git a/platforms/market/src/features/legal/repositories/legal/types.ts b/platforms/market/src/features/legal/repositories/legal/types.ts new file mode 100644 index 0000000..3716223 --- /dev/null +++ b/platforms/market/src/features/legal/repositories/legal/types.ts @@ -0,0 +1,25 @@ +import type { + LegalAcceptanceEntity, + LegalDocumentEntity, + LegalDocumentKey, +} from '../../entities/legal-document'; + +export type GetDocumentArgs = { key: LegalDocumentKey }; +export type LegalDocumentResponseDto = LegalDocumentEntity; +export type LegalDocumentPayload = LegalDocumentEntity; + +export type LegalAcceptancesResponseDto = { items: LegalAcceptanceEntity[] }; +export type LegalAcceptancePayload = LegalAcceptanceEntity; + +export type AcceptDocumentArgs = { + document: LegalDocumentKey; + version: string; +}; +export type AcceptDocumentDto = AcceptDocumentArgs; +export type AcceptDocumentResponseDto = LegalAcceptanceEntity & { + agreementRequired: boolean; +}; +export type AcceptedDocumentPayload = LegalAcceptancePayload & { + /** True when an even newer major agreement is still owed. */ + agreementRequired: boolean; +}; diff --git a/platforms/market/src/features/legal/types.ts b/platforms/market/src/features/legal/types.ts new file mode 100644 index 0000000..5fb320a --- /dev/null +++ b/platforms/market/src/features/legal/types.ts @@ -0,0 +1,7 @@ +import type { LegalDocumentKey } from './entities/legal-document'; + +declare module '@lumina/libs/event-emitter' { + interface EventMap { + 'legal.agreement-accepted': { document: LegalDocumentKey; version: string }; + } +} diff --git a/platforms/market/src/features/legal/utils/parse-legal-markdown.test.ts b/platforms/market/src/features/legal/utils/parse-legal-markdown.test.ts new file mode 100644 index 0000000..861ac41 --- /dev/null +++ b/platforms/market/src/features/legal/utils/parse-legal-markdown.test.ts @@ -0,0 +1,74 @@ +import { describe, expect, it } from 'vitest'; + +import { parseLegalMarkdown } from './parse-legal-markdown'; + +const plain = (text: string) => [{ text, bold: false }]; + +describe('parseLegalMarkdown', () => { + it('reads ## and ### as a section and a subsection', () => { + expect(parseLegalMarkdown('## قوانین پلتفرم\n\n### حساب')).toEqual([ + { kind: 'section', inlines: plain('قوانین پلتفرم') }, + { kind: 'subsection', inlines: plain('حساب') }, + ]); + }); + + it('joins the lines of a paragraph and splits on a blank line', () => { + expect(parseLegalMarkdown('یک\nدو\n\nسه')).toEqual([ + { kind: 'paragraph', inlines: plain('یک دو') }, + { kind: 'paragraph', inlines: plain('سه') }, + ]); + }); + + it('reads an ordered list, whatever its numbers', () => { + expect(parseLegalMarkdown('1. یک\n2. دو')).toEqual([ + { kind: 'list', items: [plain('یک'), plain('دو')] }, + ]); + }); + + it('keeps a number in a paragraph as text unless every line is an item', () => { + expect(parseLegalMarkdown('1. یک\nادامه')).toEqual([ + { kind: 'paragraph', inlines: plain('1. یک ادامه') }, + ]); + }); + + it('reads a quote across lines', () => { + expect(parseLegalMarkdown('> پیش‌نویس\n> است')).toEqual([ + { kind: 'quote', inlines: plain('پیش‌نویس است') }, + ]); + }); + + it('marks **bold** inside any block', () => { + expect(parseLegalMarkdown('پیش **میان** پس')).toEqual([ + { + kind: 'paragraph', + inlines: [ + { text: 'پیش ', bold: false }, + { text: 'میان', bold: true }, + { text: ' پس', bold: false }, + ], + }, + ]); + expect(parseLegalMarkdown('1. **بازگشت** وجه')).toEqual([ + { + kind: 'list', + items: [ + [ + { text: 'بازگشت', bold: true }, + { text: ' وجه', bold: false }, + ], + ], + }, + ]); + }); + + it('leaves markup it does not know as plain text', () => { + expect(parseLegalMarkdown('')).toEqual([ + { kind: 'paragraph', inlines: plain('') }, + ]); + }); + + it('answers nothing for empty text and handles Windows line ends', () => { + expect(parseLegalMarkdown(' \n\n ')).toEqual([]); + expect(parseLegalMarkdown('## الف\r\n\r\nب')).toHaveLength(2); + }); +}); diff --git a/platforms/market/src/features/legal/utils/parse-legal-markdown.ts b/platforms/market/src/features/legal/utils/parse-legal-markdown.ts new file mode 100644 index 0000000..3a8105d --- /dev/null +++ b/platforms/market/src/features/legal/utils/parse-legal-markdown.ts @@ -0,0 +1,60 @@ +/** A stretch of text, bold or not. */ +export type LegalInline = { text: string; bold: boolean }; + +export type LegalBlock = + | { kind: 'section'; inlines: LegalInline[] } + | { kind: 'subsection'; inlines: LegalInline[] } + | { kind: 'paragraph'; inlines: LegalInline[] } + | { kind: 'quote'; inlines: LegalInline[] } + | { kind: 'list'; items: LegalInline[][] }; + +const ORDERED_ITEM = /^\d+\.\s+(.*)$/; + +function parseInlines(text: string): LegalInline[] { + return text + .split('**') + .map((part, index) => ({ text: part, bold: index % 2 === 1 })) + .filter((inline) => inline.text.length > 0); +} + +/** + * The little markdown legal text uses: `##`, `###`, paragraphs, ordered lists, `>` quotes and + * `**bold**`. Anything else stays plain text, so the text renders as data and never as markup. + * Blocks are separated by a blank line; lines of one paragraph join with a space. + */ +export function parseLegalMarkdown(source: string): LegalBlock[] { + const blocks: LegalBlock[] = []; + for (const chunk of source.replace(/\r\n/g, '\n').split(/\n\s*\n/)) { + const lines = chunk + .split('\n') + .map((line) => line.trim()) + .filter(Boolean); + const [first] = lines; + if (first === undefined) continue; + + if (first.startsWith('### ')) { + blocks.push({ + kind: 'subsection', + inlines: parseInlines(first.slice(4)), + }); + } else if (first.startsWith('## ')) { + blocks.push({ kind: 'section', inlines: parseInlines(first.slice(3)) }); + } else if (first.startsWith('>')) { + const text = lines.map((line) => line.replace(/^>\s?/, '')).join(' '); + blocks.push({ kind: 'quote', inlines: parseInlines(text) }); + } else if (lines.every((line) => ORDERED_ITEM.test(line))) { + blocks.push({ + kind: 'list', + items: lines.map((line) => + parseInlines(line.replace(ORDERED_ITEM, '$1')), + ), + }); + } else { + blocks.push({ + kind: 'paragraph', + inlines: parseInlines(lines.join(' ')), + }); + } + } + return blocks; +} diff --git a/platforms/market/src/features/notification/entities/notification/types.ts b/platforms/market/src/features/notification/entities/notification/types.ts index 90efa78..69e2615 100644 --- a/platforms/market/src/features/notification/entities/notification/types.ts +++ b/platforms/market/src/features/notification/entities/notification/types.ts @@ -16,6 +16,8 @@ * went, `invite_code_deactivated` that their invite code was turned off, and `prediction_corrected` * that an admin corrected one of their predictions (with the reason as its body). * + * `rules_updated` tells every user a major version of the rules is out (links to /terms). + * * From the admin panel (J11-7): `subscription_extended` tells an investor their subscription got * extra days (with the new expiry), `subscription_refunded` that money was paid back and the * subscription ended. @@ -29,6 +31,7 @@ export type NotificationType = | 'subscription_expired' | 'subscription_expired_suspended' | 'subscription_extended' + | 'rules_updated' | 'subscription_refunded' | 'payment_pending_review' | 'waitlist_capacity' diff --git a/platforms/market/src/features/notification/models/notification-centre/use-notification-centre.ts b/platforms/market/src/features/notification/models/notification-centre/use-notification-centre.ts index 0acc8de..2a41047 100644 --- a/platforms/market/src/features/notification/models/notification-centre/use-notification-centre.ts +++ b/platforms/market/src/features/notification/models/notification-centre/use-notification-centre.ts @@ -38,6 +38,7 @@ const IN_APP_PATHS: ReadonlySet = new Set([ ROUTES.dashboard.finance, ROUTES.account.profile, ROUTES.notifications, + ROUTES.rules.general, ]); const CHANNEL_PATH = ROUTES.channel(''); const CHECKOUT_PATH = ROUTES.checkout(''); diff --git a/platforms/market/src/index.ts b/platforms/market/src/index.ts index 81ab5d0..d968579 100644 --- a/platforms/market/src/index.ts +++ b/platforms/market/src/index.ts @@ -435,3 +435,28 @@ export { useViewerStatus, } from './stores/auth'; export type { AuthState, Session, ViewerStatus } from './stores/auth'; +export { + acceptAgreement, + LEGAL_ERROR_CODES, + LEGAL_EVENTS, + legalKeys, + legalRepository, + parseLegalMarkdown, + useAgreementAcceptance, + useAgreementGate, + useLegalDocument, +} from './features/legal'; +export type { + AcceptDocumentArgs, + AcceptedDocumentPayload, + AgreementGateModel, + AgreementGateView, + LegalAcceptanceEntity, + LegalAcceptancePayload, + LegalBlock, + LegalDocumentEntity, + LegalDocumentKey, + LegalDocumentModel, + LegalDocumentPayload, + LegalInline, +} from './features/legal'; diff --git a/platforms/market/src/shared/locales/fa/account.json b/platforms/market/src/shared/locales/fa/account.json index db5ac17..3f48e25 100644 --- a/platforms/market/src/shared/locales/fa/account.json +++ b/platforms/market/src/shared/locales/fa/account.json @@ -21,7 +21,9 @@ "install-mobile": "دسترسی سریع از صفحه اصلی گوشی", "install-desktop": "دسترسی سریع، بدون نوار مرورگر", "support": "پشتیبانی", - "terms": "قوانین لومینا" + "terms": "قوانین و مقررات لومینا", + "agreement": "توافق‌نامه تحلیلگر", + "agreement-record": "نسخه {{version}} · پذیرفته‌شده در {{date}}" }, "sign-out": "خروج از حساب", "version": "لومینا · نسخه 1٫0 بتا" diff --git a/platforms/market/src/shared/locales/fa/auth.json b/platforms/market/src/shared/locales/fa/auth.json index 85160ec..47aa0ba 100644 --- a/platforms/market/src/shared/locales/fa/auth.json +++ b/platforms/market/src/shared/locales/fa/auth.json @@ -1,4 +1,5 @@ { + "rules-caption": "ورود یا ثبت‌نام به معنی پذیرش قوانین و مقررات لومینا است.", "header": { "brand": "لومینا", "home": "صفحه اصلی لومینا", @@ -115,7 +116,6 @@ "title": "اطلاعات حساب", "description": "نام شما فقط در اطلاعات کاربری دیده می‌شود؛ دیگران شما را با نام کاربری می‌شناسند.", "submit": "ساخت حساب", - "terms-before": "با ساخت حساب، ", "failed": "حساب ساخته نشد", "network-title": "خطا در ثبت اطلاعات.", "success": "حساب شما ساخته شد." @@ -129,15 +129,10 @@ "private-title": "اطلاعات هویتی", "private-description": "محرمانه است و فقط برای تأیید هویت بررسی می‌شود.", "submit": "ثبت و ادامه", - "terms-before": "با ثبت اطلاعات، ", "failed": "اطلاعات ثبت نشد", "success": "اطلاعات شما دریافت شد. پس از تأیید، حساب شما فعال می‌شود.", "username-placeholder": "ali_trader" }, - "terms-link": "قوانین لومینا", - "terms-after": " را می‌پذیرید.", - "rules-title": "قوانین لومینا", - "rules-close": "متوجه شدم", "fields": { "first-name": "نام", "first-name-placeholder": "مثال: علی", diff --git a/platforms/market/src/shared/locales/fa/legal.json b/platforms/market/src/shared/locales/fa/legal.json new file mode 100644 index 0000000..223be07 --- /dev/null +++ b/platforms/market/src/shared/locales/fa/legal.json @@ -0,0 +1,40 @@ +{ + "document": { + "loading": "در حال بارگذاری متن…", + "footer": "نسخه {{version}} · آخرین به‌روزرسانی: {{date}}", + "failed": "متن بارگذاری نشد" + }, + "dialog": { + "close": "متوجه شدم", + "rules-title": "قوانین و مقررات لومینا", + "agreement-title": "توافق‌نامه تحلیلگر" + }, + "subscription": { + "hours": "زمان پاسخگویی: {{hours}}" + }, + "agreement": { + "record": "نسخه {{version}} · پذیرفته‌شده در {{date}}، ساعت {{time}}", + "kyc": { + "title": "توافق‌نامه تحلیلگر", + "text": "پیش از وارد کردن اطلاعات هویتی، توافق‌نامه تحلیلگر را بخوانید و بپذیرید.", + "read": "خواندن متن", + "checkbox": "توافق‌نامه تحلیلگر را خوانده‌ام و می‌پذیرم.", + "frozen": "برای ادامه، توافق‌نامه تحلیلگر را بپذیرید.", + "changed": "توافق‌نامه تحلیلگر به‌روزرسانی شد. نسخهٔ جدید را بخوانید و بپذیرید.", + "failed": "متن توافق‌نامه بارگذاری نشد." + }, + "gate": { + "title": "توافق‌نامه تحلیلگر به‌روزرسانی شد", + "body": "برای ادامه کار با لومینا، نسخهٔ جدید توافق‌نامه را بخوانید و بپذیرید. تا پیش از پذیرش، انتشار و دسترسی به داشبورد ممکن نیست.", + "changes": "تغییرات مهم نسخه {{version}}", + "read": "خواندن متن کامل", + "back": "بازگشت به خلاصه تغییرات", + "checkbox": "نسخهٔ جدید توافق‌نامه تحلیلگر را خوانده‌ام و می‌پذیرم.", + "accept": "پذیرش و ادامه", + "frozen": "ابتدا توافق‌نامه را بپذیرید.", + "sign-out": "خروج از حساب", + "accepted": "توافق‌نامه پذیرفته شد.", + "failed": "پذیرش ثبت نشد" + } + } +} diff --git a/platforms/market/src/shared/locales/fa/rules.json b/platforms/market/src/shared/locales/fa/rules.json index 28661a8..7676a08 100644 --- a/platforms/market/src/shared/locales/fa/rules.json +++ b/platforms/market/src/shared/locales/fa/rules.json @@ -1,40 +1,14 @@ { - "meta-title": "قوانین لومینا", - "meta-description": "قوانین عمومی استفاده از لومینا: حساب کاربری، محتوای تحلیلگران، محتوای ممنوع، پیش‌بینی‌ها، تعلیق حساب، حریم خصوصی و تغییر قوانین.", - "title": "قوانین لومینا", + "meta-title": "قوانین و مقررات لومینا", + "meta-description": "قوانین و مقررات استفاده از لومینا: قوانین پلتفرم و حریم خصوصی.", + "title": "قوانین و مقررات لومینا", "tabs": { - "label": "قوانین لومینا", - "general": "قوانین عمومی", + "label": "قوانین و مقررات لومینا", + "general": "قوانین و مقررات", "subscription": "شرایط اشتراک" }, - "s1": { - "title": "1. حساب کاربری", - "p1": "هر شماره موبایل فقط یک حساب دارد و ورود همیشه با کد پیامکی انجام می‌شود. اطلاعاتی که هنگام ثبت‌نام وارد می‌کنید باید واقعی و متعلق به خودتان باشد.", - "p2": "کد ورود را به هیچ‌کس، حتی پشتیبانی لومینا، ندهید." - }, - "s2": { - "title": "2. محتوای تحلیلگران", - "p1": "تحلیل‌ها و پیش‌بینی‌ها نظر شخصی تحلیلگر است و توصیه قطعی خرید یا فروش نیست. تصمیم سرمایه‌گذاری و مسئولیت آن با خود شماست و لومینا سود یا درستی هیچ تحلیلی را تضمین نمی‌کند." - }, - "s3": { - "title": "3. محتوای ممنوع", - "p1": "وعده سود تضمینی یا بدون ریسک؛ درخواست پرداخت یا اطلاعات بانکی بیرون از لومینا؛ تبلیغ کانال‌ها و خدمات پولی دیگر؛ انتشار محتوای دیگران بدون اجازه؛ توهین، تهدید یا انتشار اطلاعات شخصی افراد؛ هر محتوای خلاف قوانین جمهوری اسلامی ایران." - }, - "s4": { - "title": "4. پیش‌بینی‌ها و کارنامه", - "p1": "پیش‌بینی پس از انتشار ویرایش نمی‌شود و فقط پیش از رسیدن به هدف یا حد ضرر می‌توان آن را زودتر بست. نتیجه با قیمت منبع اعلام‌شده ثبت می‌شود و اگر قیمت نادرست ثبت شده باشد، ادمین نتیجه را با ذکر دلیل اصلاح می‌کند." - }, - "s5": { - "title": "5. تعلیق حساب", - "p1": "اگر قوانین رعایت نشود، حساب تعلیق می‌شود و دلیل آن با پیامک و اعلان به شما گفته می‌شود. برای اعتراض با پشتیبانی تماس بگیرید. در دوره تعلیق، اشتراک‌های فعال طبق «شرایط اشتراک» بررسی می‌شوند." - }, - "s6": { - "title": "6. حریم خصوصی", - "p1": "دیگران شما را فقط با نام کاربری می‌بینند. شماره موبایل و نام شما فقط برای خودتان و پشتیبانی نمایش داده می‌شود. تصویر کارت ملی تحلیلگر فقط برای احراز هویت استفاده می‌شود و در هیچ صفحه‌ای نمایش داده نمی‌شود." - }, - "s7": { - "title": "7. تغییر قوانین", - "p1": "هر تغییر در این قوانین پیش از اجرا با اعلان به شما اطلاع داده می‌شود. ادامه استفاده از لومینا به معنی پذیرش قوانین تازه است." - }, - "updated": "آخرین به‌روزرسانی: 1 مهر 1405" + "agreement": { + "meta-title": "توافق‌نامه تحلیلگر", + "title": "توافق‌نامه تحلیلگر" + } } diff --git a/platforms/market/src/shared/locales/fa/terms.json b/platforms/market/src/shared/locales/fa/terms.json index 7dccc23..e7c5687 100644 --- a/platforms/market/src/shared/locales/fa/terms.json +++ b/platforms/market/src/shared/locales/fa/terms.json @@ -1,54 +1,4 @@ { "meta-title": "شرایط اشتراک", - "meta-description": "شرایط خرید، تمدید و بازگشت وجه اشتراک کانال تحلیلگران در لومینا.", - "title": "شرایط اشتراک", - "s1": { - "title": "1. اشتراک چیست؟", - "p1": "با خرید اشتراک، به محتوای ویژه (پریمیوم) کانال یک تحلیلگر برای مدت انتخاب‌شده دسترسی پیدا می‌کنید. دسترسی شما بلافاصله پس از تأیید پرداخت فعال می‌شود و تا پایان دوره ادامه دارد.", - "p2": "اشتراک به‌صورت خودکار تمدید نمی‌شود. پیش از پایان دوره به شما اطلاع داده می‌شود تا در صورت تمایل، اشتراک خود را تمدید کنید." - }, - "s2": { - "title": "2. بازگشت وجه", - "p1": "اشتراک‌ها به‌دلیل ماهیت دیجیتال و دسترسی فوری به محتوا، به‌طور کلی قابل بازگشت نیستند.", - "p2": "در موارد استثنایی می‌توانید از طریق پشتیبانی لومینا درخواست بررسی دهید. هر درخواست به‌صورت جداگانه بررسی می‌شود.", - "p3": "در صورت تأیید بازگشت وجه، مبلغ از طریق انتقال بانکی به شماره شبایی که به پشتیبانی اعلام می‌کنید واریز می‌شود. مسئولیت صحت شماره شبای اعلام‌شده بر عهده شماست. بازگشت وجه به‌صورت اعتبار داخل پلتفرم انجام نمی‌شود." - }, - "s3": { - "title": "3. در صورت غیرفعال شدن کانال تحلیلگر", - "p1": "اگر دسترسی به کانال یک تحلیلگر در طول دوره اشتراک شما متوقف شود، بلافاصله از طریق پیامک و اعلان در پلتفرم به شما اطلاع داده می‌شود و دو گزینه خواهید داشت:", - "refund-lead": "درخواست بازگشت وجه:", - "refund": "با پیام به پشتیبانی لومینا، مبلغ دوره استفاده‌نشده به‌صورت نسبی محاسبه و به حساب شما واریز می‌شود.", - "wait-lead": "انتظار برای بازگشت کانال:", - "wait": "اگر کانال پیش از پایان اشتراک شما دوباره فعال شود، مدت‌زمان توقف به اشتراک شما اضافه می‌شود و تاریخ انقضای جدید به شما اعلام خواهد شد.", - "p2": "اگر هیچ اقدامی نکنید، گزینه دوم به‌طور خودکار اعمال می‌شود.", - "p3": "با دریافت بازگشت وجه، اشتراک شما پایان می‌یابد و مدت توقف به آن اضافه نمی‌شود.", - "p4": "اگر اشتراک شما در دوره توقف به پایان برسد، حق درخواست بازگشت وجه مدت استفاده‌نشده برای شما محفوظ می‌ماند." - }, - "s4": { - "title": "4. تغییر قیمت", - "p1": "قیمتی که هنگام خرید پرداخت کرده‌اید تا پایان دوره اشتراک شما ثابت می‌ماند. تغییر قیمت توسط تحلیلگر روی اشتراک فعلی شما تأثیری ندارد.", - "p2": "در زمان تمدید، قیمت جاری آن کانال اعمال می‌شود و پیش از پرداخت به شما نمایش داده خواهد شد." - }, - "s5": { - "title": "5. تخفیف‌ها", - "p1": "تخفیف‌های دوره‌ای هنگام خرید اشتراک جدید، تمدید اشتراک فعلی، و خرید مجدد پس از پایان دوره قابل استفاده هستند.", - "p2": "تخفیف روی اشتراکی که پیش‌تر خریداری کرده‌اید اعمال نمی‌شود، اما می‌توانید در زمان تمدید یا خرید مجدد از آن بهره‌مند شوید.", - "p3": "پایان یافتن یک تخفیف روی اشتراکی که با قیمت تخفیف‌خورده خریداری شده تأثیری ندارد؛ شما تا پایان دوره از همان قیمت بهره‌مند می‌شوید." - }, - "s6": { - "title": "6. محتوا و مسئولیت", - "p1": "محتوای منتشرشده در کانال‌ها، شامل تحلیل‌ها، پیش‌بینی‌ها و دیدگاه‌ها، توسط تحلیلگران تولید می‌شود و مسئولیت آن به‌عهده خود آن‌هاست.", - "p2": "لومینا بستری برای انتشار و اعتبارسنجی عملکرد تحلیلگران فراهم می‌کند و هیچ‌یک از محتوای منتشرشده را تأیید، تضمین یا به‌عنوان توصیه سرمایه‌گذاری ارائه نمی‌دهد.", - "p3": "تصمیمات سرمایه‌گذاری شما بر عهده خودتان است." - }, - "s7": { - "title": "7. مشکلات پرداخت", - "p1": "اگر مبلغی از حساب شما کسر شده اما پرداخت ناموفق اعلام شده است، این مبلغ حداکثر ظرف 72 ساعت به‌طور خودکار توسط بانک به حساب شما بازمی‌گردد.", - "p2": "اگر پرداخت موفق بوده اما اشتراک شما فعال نشده است، شماره پیگیری را از بخش تراکنش‌ها برای پشتیبانی ارسال کنید تا دسترسی شما فعال شود." - }, - "s8": { - "title": "8. ارتباط با پشتیبانی", - "p1": "برای هرگونه پرسش یا مشکل، از طریق پیام‌رسان بله یا تلگرام با پشتیبانی لومینا در ارتباط باشید.", - "hours": "زمان پاسخگویی: {{hours}}" - } + "meta-description": "شرایط خرید، تمدید و بازگشت وجه اشتراک کانال تحلیلگران در لومینا." } diff --git a/platforms/market/src/shared/locales/resources.ts b/platforms/market/src/shared/locales/resources.ts index d3b3b55..d093a62 100644 --- a/platforms/market/src/shared/locales/resources.ts +++ b/platforms/market/src/shared/locales/resources.ts @@ -7,6 +7,7 @@ import faDashboard from './fa/dashboard.json'; import faErrors from './fa/errors.json'; import faFinance from './fa/finance.json'; import faHome from './fa/home.json'; +import faLegal from './fa/legal.json'; import faNotifications from './fa/notifications.json'; import faPayment from './fa/payment.json'; import faPredictions from './fa/predictions.json'; @@ -35,6 +36,7 @@ export const resources = { finance: faFinance, account: faAccount, predictions: faPredictions, + legal: faLegal, }, } as const; diff --git a/platforms/market/src/shared/locales/server-resources.ts b/platforms/market/src/shared/locales/server-resources.ts index 6f85dc2..72d639b 100644 --- a/platforms/market/src/shared/locales/server-resources.ts +++ b/platforms/market/src/shared/locales/server-resources.ts @@ -5,9 +5,9 @@ import faRules from './fa/rules.json'; import faTerms from './fa/terms.json'; /** - * Namespaces that only server components read: the prerendered landing, the subscription terms - * and «قوانین لومینا» (the registration sheet gets those rules rendered on the server). They stay - * out of every client bundle; each app's server bootstrap adds them to its i18n instance. + * Namespaces that only server components read: the prerendered landing, and the metadata, title and + * tabs of the rules pages (their text comes from the API). They stay out of every client bundle; + * each app's server bootstrap adds them to its i18n instance. */ export const SERVER_RESOURCES = { fa: { diff --git a/platforms/market/src/stores/auth/auth-store.ts b/platforms/market/src/stores/auth/auth-store.ts index e6f4c29..a5f278c 100644 --- a/platforms/market/src/stores/auth/auth-store.ts +++ b/platforms/market/src/stores/auth/auth-store.ts @@ -25,6 +25,10 @@ export const useAuthStore = create()( set((state) => { if (state.session) state.session.needsProfile = false; }), + setAgreementRequired: (required) => + set((state) => { + if (state.session) state.session.agreementRequired = required; + }), clearSession: () => set((state) => { state.status = 'guest'; @@ -38,3 +42,5 @@ export const useCurrentAccount = () => useAuthStore((state) => state.session?.account ?? null); export const useNeedsProfile = () => useAuthStore((state) => state.session?.needsProfile ?? false); +export const useAgreementRequired = () => + useAuthStore((state) => state.session?.agreementRequired ?? false); diff --git a/platforms/market/src/stores/auth/index.ts b/platforms/market/src/stores/auth/index.ts index 8f30ff0..e1f8824 100644 --- a/platforms/market/src/stores/auth/index.ts +++ b/platforms/market/src/stores/auth/index.ts @@ -1,4 +1,5 @@ export { + useAgreementRequired, useAuthStore, useCurrentAccount, useNeedsProfile, diff --git a/platforms/market/src/stores/auth/types.ts b/platforms/market/src/stores/auth/types.ts index e3cd174..569457e 100644 --- a/platforms/market/src/stores/auth/types.ts +++ b/platforms/market/src/stores/auth/types.ts @@ -10,6 +10,11 @@ export type Session = { * step 5 sends them back to it. Always `false` for an investor. */ needsProfile: boolean; + /** + * An analyst who owes a newer major agreement: a blocking modal stays open until they accept it. + * Always `false` for an investor. + */ + agreementRequired: boolean; }; export type AuthState = { @@ -20,5 +25,7 @@ export type AuthState = { updateAccount: (account: AccountPayload) => void; /** Step 5 is done: the creator may use the rest of the app. */ profileCompleted: () => void; + /** Set by the session's answer or a 403 `agreement_required`; cleared by accepting. */ + setAgreementRequired: (required: boolean) => void; clearSession: () => void; }; diff --git a/tools/vitest-setup.ts b/tools/vitest-setup.ts index e01cebc..cbf7c53 100644 --- a/tools/vitest-setup.ts +++ b/tools/vitest-setup.ts @@ -2,3 +2,17 @@ import { cleanup } from '@testing-library/react'; import { afterEach } from 'vitest'; afterEach(cleanup); + +// jsdom has `` without its modal methods. +if (typeof HTMLDialogElement !== 'undefined') { + HTMLDialogElement.prototype.showModal ??= function showModal( + this: HTMLDialogElement, + ) { + this.open = true; + }; + HTMLDialogElement.prototype.close ??= function close( + this: HTMLDialogElement, + ) { + this.open = false; + }; +}