From 163005429d59407e8ce11bda2e6d8046f90f7ee9 Mon Sep 17 00:00:00 2001 From: Amiram_se Date: Fri, 9 Oct 2026 16:11:12 +0400 Subject: [PATCH] feat(market): creator dashboard plans and finance, pricing form with promotions, payout account and ledger Co-Authored-By: Claude Opus 5.5 --- .../onboarding-guard/OnboardingGuard.tsx | 3 +- .../components/bottom-nav/BottomNav.tsx | 4 +- .../desktop-header/DesktopHeader.tsx | 2 +- .../market/src/app/navigation/navigation.ts | 6 +- .../organisms/pricing-form/PricingForm.tsx | 140 +++++++ .../pricing-form/PricingFormSkeleton.tsx | 36 ++ .../pricing-form/components/ConfirmDialog.tsx | 155 ++++++++ .../pricing-form/components/DateField.tsx | 59 +++ .../components/DateTimeDialog.tsx | 202 ++++++++++ .../components/PromotionBlock.tsx | 106 ++++++ .../pricing-form/components/TierCard.tsx | 127 +++++++ .../pricing-form/components/WarnNote.tsx | 20 + .../pricing-form/components/types.ts | 7 + .../components/use-field-message.ts | 38 ++ .../pricing/organisms/pricing-form/index.ts | 3 + .../pricing/organisms/pricing-form/types.ts | 46 +++ .../balance-summary/BalanceSummary.tsx | 134 +++++++ .../BalanceSummarySkeleton.tsx | 31 ++ .../organisms/balance-summary/index.ts | 3 + .../organisms/balance-summary/types.ts | 10 + .../finance/organisms/ledger/Ledger.tsx | 141 +++++++ .../organisms/ledger/LedgerSkeleton.tsx | 37 ++ .../ledger/components/LedgerDetail.tsx | 263 +++++++++++++ .../organisms/ledger/components/LedgerRow.tsx | 109 ++++++ .../ledger/components/use-ledger-row-text.ts | 47 +++ .../finance/organisms/ledger/index.ts | 3 + .../finance/organisms/ledger/types.ts | 28 ++ .../payout-account/PayoutAccount.tsx | 138 +++++++ .../payout-account/PayoutAccountSkeleton.tsx | 27 ++ .../payout-account/components/AccountForm.tsx | 118 ++++++ .../components/ReadBackDialog.tsx | 112 ++++++ .../components/SavedAccount.tsx | 47 +++ .../payout-account/components/WarnLine.tsx | 24 ++ .../finance/organisms/payout-account/index.ts | 3 + .../finance/organisms/payout-account/types.ts | 29 ++ .../PayoutScheduleNotice.tsx | 25 ++ .../organisms/payout-schedule-notice/index.ts | 5 + .../organisms/payout-schedule-notice/types.ts | 13 + .../dashboard-tabs/DashboardTabs.tsx | 27 +- .../organisms/dashboard-tabs/constants.ts | 6 + .../organisms/dashboard-tabs/types.ts | 2 + .../organisms/pricing-card/PricingCard.tsx | 101 +++++ .../pricing-card/PricingCardSkeleton.tsx | 37 ++ .../pricing-card/components/PlanRow.tsx | 78 ++++ .../plans/organisms/pricing-card/index.ts | 3 + .../plans/organisms/pricing-card/types.ts | 19 + .../subscriber-list/SubscriberList.tsx | 140 +++++++ .../SubscriberListSkeleton.tsx | 39 ++ .../plans/organisms/subscriber-list/index.ts | 3 + .../plans/organisms/subscriber-list/types.ts | 10 + .../notification-centre/constants.ts | 10 + .../src/features/finance/actions/.gitkeep | 0 .../actions/save-payout-account/actions.ts | 21 ++ .../actions/save-payout-account/index.ts | 1 + .../market/src/features/finance/constants.ts | 8 + .../src/features/finance/entities/.gitkeep | 0 .../finance/entities/earnings/index.ts | 7 + .../finance/entities/earnings/types.ts | 65 ++++ .../market/src/features/finance/index.ts | 50 ++- .../src/features/finance/models/.gitkeep | 0 .../features/finance/models/balance/index.ts | 2 + .../features/finance/models/balance/types.ts | 5 + .../models/balance/use-balance-part.ts | 16 + .../features/finance/models/ledger/index.ts | 2 + .../features/finance/models/ledger/types.ts | 33 ++ .../finance/models/ledger/use-ledger-part.ts | 113 ++++++ .../finance/models/payout-account/index.ts | 2 + .../finance/models/payout-account/types.ts | 50 +++ .../payout-account/use-payout-account-part.ts | 212 +++++++++++ .../repositories/creator-payment/constants.ts | 6 - .../creator-payment/creator-payment.ts | 23 -- .../repositories/creator-payment/index.ts | 3 - .../repositories/creator-payment/mappers.ts | 20 - .../repositories/creator-payment/types.ts | 30 -- .../repositories/earnings/constants.ts | 26 ++ .../finance/repositories/earnings/earnings.ts | 43 +++ .../finance/repositories/earnings/index.ts | 19 + .../finance/repositories/earnings/mappers.ts | 82 ++++ .../finance/repositories/earnings/types.ts | 115 ++++++ .../repositories/payout-account/constants.ts | 15 + .../repositories/payout-account/index.ts | 8 + .../repositories/payout-account/mappers.ts | 36 ++ .../payout-account/payout-account.ts | 54 +++ .../repositories/payout-account/types.ts | 35 ++ .../market/src/features/finance/types.ts | 7 + .../entities/notification/types.ts | 11 +- .../market/src/features/overview/index.ts | 11 + .../overview/models/subscribers/index.ts | 2 + .../overview/models/subscribers/types.ts | 11 + .../subscribers/use-subscribers-part.ts | 38 ++ .../creator-subscribers/constants.ts | 6 + .../creator-subscribers.ts | 25 ++ .../repositories/creator-subscribers/index.ts | 7 + .../creator-subscribers/mappers.ts | 29 ++ .../repositories/creator-subscribers/types.ts | 38 ++ .../src/features/pricing/actions/.gitkeep | 0 .../pricing/actions/save-pricing/actions.ts | 22 ++ .../pricing/actions/save-pricing/index.ts | 1 + .../market/src/features/pricing/constants.ts | 23 ++ .../market/src/features/pricing/index.ts | 22 ++ .../src/features/pricing/models/.gitkeep | 0 .../pricing/models/pricing-card/index.ts | 2 + .../pricing/models/pricing-card/types.ts | 29 ++ .../pricing-card/use-pricing-card-part.ts | 49 +++ .../features/pricing/models/pricing/index.ts | 19 + .../pricing/models/pricing/pricing-rules.ts | 147 ++++++++ .../features/pricing/models/pricing/types.ts | 115 ++++++ .../models/pricing/use-pricing-page.ts | 351 ++++++++++++++++++ .../pricing/repositories/pricing/mappers.ts | 2 + .../pricing/repositories/pricing/types.ts | 2 + .../market/src/features/pricing/types.ts | 7 + platforms/market/src/index.ts | 71 +++- .../market/src/shared/constants/index.ts | 6 + .../src/shared/locales/fa/dashboard.json | 21 ++ .../market/src/shared/locales/fa/finance.json | 193 ++++++++++ .../src/shared/locales/fa/notifications.json | 7 +- .../market/src/shared/locales/fa/pricing.json | 104 ++++++ .../market/src/shared/locales/resources.ts | 4 + platforms/market/src/shared/utils/iban.ts | 60 +++ platforms/market/src/shared/utils/index.ts | 9 + .../shared/validations/finance-validations.ts | 25 ++ .../market/src/shared/validations/index.ts | 3 + .../market/src/shared/validations/types.ts | 4 + 123 files changed, 5250 insertions(+), 111 deletions(-) create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/PricingForm.tsx create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/PricingFormSkeleton.tsx create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/ConfirmDialog.tsx create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/DateField.tsx create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/DateTimeDialog.tsx create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/PromotionBlock.tsx create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/TierCard.tsx create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/WarnNote.tsx create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/types.ts create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/use-field-message.ts create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/index.ts create mode 100644 platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/types.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/balance-summary/BalanceSummary.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/balance-summary/BalanceSummarySkeleton.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/balance-summary/index.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/balance-summary/types.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/ledger/Ledger.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/ledger/LedgerSkeleton.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/ledger/components/LedgerDetail.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/ledger/components/LedgerRow.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/ledger/components/use-ledger-row-text.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/ledger/index.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/ledger/types.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-account/PayoutAccount.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-account/PayoutAccountSkeleton.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-account/components/AccountForm.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-account/components/ReadBackDialog.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-account/components/SavedAccount.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-account/components/WarnLine.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-account/index.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-account/types.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-schedule-notice/PayoutScheduleNotice.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-schedule-notice/index.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/finance/organisms/payout-schedule-notice/types.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/pricing-card/PricingCard.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/pricing-card/PricingCardSkeleton.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/pricing-card/components/PlanRow.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/pricing-card/index.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/pricing-card/types.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/subscriber-list/SubscriberList.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/subscriber-list/SubscriberListSkeleton.tsx create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/subscriber-list/index.ts create mode 100644 platforms/market/src/app/screens/(main)/dashboard/plans/organisms/subscriber-list/types.ts delete mode 100644 platforms/market/src/features/finance/actions/.gitkeep create mode 100644 platforms/market/src/features/finance/actions/save-payout-account/actions.ts create mode 100644 platforms/market/src/features/finance/actions/save-payout-account/index.ts create mode 100644 platforms/market/src/features/finance/constants.ts delete mode 100644 platforms/market/src/features/finance/entities/.gitkeep create mode 100644 platforms/market/src/features/finance/entities/earnings/index.ts create mode 100644 platforms/market/src/features/finance/entities/earnings/types.ts delete mode 100644 platforms/market/src/features/finance/models/.gitkeep create mode 100644 platforms/market/src/features/finance/models/balance/index.ts create mode 100644 platforms/market/src/features/finance/models/balance/types.ts create mode 100644 platforms/market/src/features/finance/models/balance/use-balance-part.ts create mode 100644 platforms/market/src/features/finance/models/ledger/index.ts create mode 100644 platforms/market/src/features/finance/models/ledger/types.ts create mode 100644 platforms/market/src/features/finance/models/ledger/use-ledger-part.ts create mode 100644 platforms/market/src/features/finance/models/payout-account/index.ts create mode 100644 platforms/market/src/features/finance/models/payout-account/types.ts create mode 100644 platforms/market/src/features/finance/models/payout-account/use-payout-account-part.ts delete mode 100644 platforms/market/src/features/finance/repositories/creator-payment/constants.ts delete mode 100644 platforms/market/src/features/finance/repositories/creator-payment/creator-payment.ts delete mode 100644 platforms/market/src/features/finance/repositories/creator-payment/index.ts delete mode 100644 platforms/market/src/features/finance/repositories/creator-payment/mappers.ts delete mode 100644 platforms/market/src/features/finance/repositories/creator-payment/types.ts create mode 100644 platforms/market/src/features/finance/repositories/earnings/constants.ts create mode 100644 platforms/market/src/features/finance/repositories/earnings/earnings.ts create mode 100644 platforms/market/src/features/finance/repositories/earnings/index.ts create mode 100644 platforms/market/src/features/finance/repositories/earnings/mappers.ts create mode 100644 platforms/market/src/features/finance/repositories/earnings/types.ts create mode 100644 platforms/market/src/features/finance/repositories/payout-account/constants.ts create mode 100644 platforms/market/src/features/finance/repositories/payout-account/index.ts create mode 100644 platforms/market/src/features/finance/repositories/payout-account/mappers.ts create mode 100644 platforms/market/src/features/finance/repositories/payout-account/payout-account.ts create mode 100644 platforms/market/src/features/finance/repositories/payout-account/types.ts create mode 100644 platforms/market/src/features/finance/types.ts create mode 100644 platforms/market/src/features/overview/models/subscribers/index.ts create mode 100644 platforms/market/src/features/overview/models/subscribers/types.ts create mode 100644 platforms/market/src/features/overview/models/subscribers/use-subscribers-part.ts create mode 100644 platforms/market/src/features/overview/repositories/creator-subscribers/constants.ts create mode 100644 platforms/market/src/features/overview/repositories/creator-subscribers/creator-subscribers.ts create mode 100644 platforms/market/src/features/overview/repositories/creator-subscribers/index.ts create mode 100644 platforms/market/src/features/overview/repositories/creator-subscribers/mappers.ts create mode 100644 platforms/market/src/features/overview/repositories/creator-subscribers/types.ts delete mode 100644 platforms/market/src/features/pricing/actions/.gitkeep create mode 100644 platforms/market/src/features/pricing/actions/save-pricing/actions.ts create mode 100644 platforms/market/src/features/pricing/actions/save-pricing/index.ts create mode 100644 platforms/market/src/features/pricing/constants.ts delete mode 100644 platforms/market/src/features/pricing/models/.gitkeep create mode 100644 platforms/market/src/features/pricing/models/pricing-card/index.ts create mode 100644 platforms/market/src/features/pricing/models/pricing-card/types.ts create mode 100644 platforms/market/src/features/pricing/models/pricing-card/use-pricing-card-part.ts create mode 100644 platforms/market/src/features/pricing/models/pricing/index.ts create mode 100644 platforms/market/src/features/pricing/models/pricing/pricing-rules.ts create mode 100644 platforms/market/src/features/pricing/models/pricing/types.ts create mode 100644 platforms/market/src/features/pricing/models/pricing/use-pricing-page.ts create mode 100644 platforms/market/src/features/pricing/types.ts create mode 100644 platforms/market/src/shared/locales/fa/finance.json create mode 100644 platforms/market/src/shared/locales/fa/pricing.json create mode 100644 platforms/market/src/shared/utils/iban.ts create mode 100644 platforms/market/src/shared/validations/finance-validations.ts diff --git a/platforms/market/src/app/guards/onboarding-guard/OnboardingGuard.tsx b/platforms/market/src/app/guards/onboarding-guard/OnboardingGuard.tsx index 6118fb3..4af9259 100644 --- a/platforms/market/src/app/guards/onboarding-guard/OnboardingGuard.tsx +++ b/platforms/market/src/app/guards/onboarding-guard/OnboardingGuard.tsx @@ -12,7 +12,8 @@ import type { OnboardingGuardProps } from './types'; * then: publishing and prices (R2-CompleteProfile 4.2). It changes nothing in the render, so the * server HTML stays the same for every visitor; once the browser knows the viewer, such a creator * goes to step 5, which returns here when done. The layouts of those routes render it - * (`compose`, `dashboard/pricing`); everything else, such as the terms, stays open. + * (`compose`, `dashboard/pricing`, the creator's داشبورد); everything else, such as the terms, stays + * open. */ export function OnboardingGuard({ children }: OnboardingGuardProps) { const status = useViewerStatus(); diff --git a/platforms/market/src/app/navigation/components/bottom-nav/BottomNav.tsx b/platforms/market/src/app/navigation/components/bottom-nav/BottomNav.tsx index beec0e5..7e1fc3c 100644 --- a/platforms/market/src/app/navigation/components/bottom-nav/BottomNav.tsx +++ b/platforms/market/src/app/navigation/components/bottom-nav/BottomNav.tsx @@ -61,9 +61,7 @@ export function BottomNav() { )} (null); + const picked = pick + ? model.tiers.find((tier) => tier.billingPeriod === pick.period)?.promotion + : null; + + return ( + { + event.preventDefault(); + model.save(); + }} + > + {model.saveFailed && ( + + {t('form.retry')} + + } + > + {t('form.network')} + + )} + {model.verification !== 'approved' && ( + + {t('form.pending-note')} + + )} + {model.lockedUntil ? ( + + {t('form.locked-note', { + date: date(model.lockedUntil, { time: false }), + })} + + ) : ( + model.prePurchase && ( + + + + {t('form.pre-purchase-note')} + + + ) + )} + {model.tiers.map((tier) => ( + setPick({ period, edge })} + /> + ))} + {model.lockedUntil && ( + + {t('promotion.locked-live')} + + )} + + {t('form.existing-note')} + + + {model.isBlocked && {t('form.blocked')}} + + + + setPick(null)} + onConfirm={(iso, indefinite) => { + if (!pick) return; + if (pick.edge === 'start' && iso) + model.setPromotionStart(pick.period, iso); + if (pick.edge === 'end') + model.setPromotionEnd(pick.period, iso, indefinite); + setPick(null); + }} + /> + + ); +} diff --git a/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/PricingFormSkeleton.tsx b/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/PricingFormSkeleton.tsx new file mode 100644 index 0000000..2463efe --- /dev/null +++ b/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/PricingFormSkeleton.tsx @@ -0,0 +1,36 @@ +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton'; +import { Card } from '@lumina/island/molecules/card'; + +import type { PricingFormSkeletonProps } from './types'; + +/** C7 before it arrives: four period cards, each a title row, the total field and the promotion row. */ +export function PricingFormSkeleton({ + layout, + label, + delayed, +}: PricingFormSkeletonProps) { + return ( + + + {[0, 1, 2, 3].map((card) => ( + + + + + + + + + + + + ))} + + + + ); +} diff --git a/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/ConfirmDialog.tsx b/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/ConfirmDialog.tsx new file mode 100644 index 0000000..5b94a20 --- /dev/null +++ b/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/ConfirmDialog.tsx @@ -0,0 +1,155 @@ +import { Button } from '@lumina/island/atoms/button'; +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { Tag } from '@lumina/island/atoms/tag'; +import { Typography } from '@lumina/island/atoms/typography'; +import { Modal } from '@lumina/island/molecules/modal'; +import { Sheet } from '@lumina/island/molecules/sheet'; +import { cn } from '@lumina/island/tools/cn'; +import { date, percent, price } from '@lumina/tools/format'; +import { useTranslation } from 'react-i18next'; + +import { BILLING_PERIOD_MONTHS } from '../../../../../../../../shared/constants'; +import type { ConfirmDialogProps } from '../types'; + +/** + * The confirmation on every save (C7 §۵): each offered period, total and per month, in the order + * investors see them; a promoted one adds its discount, end and promotional price (۵.۲). Then the + * lock warning and the safety valve. «تأیید و ذخیره» saves; «انصراف» or the scrim go back with + * everything kept. A bottom sheet on mobile, a modal of 420 on desktop (۸.۲); no ✕. + */ +export function ConfirmDialog({ model, layout }: ConfirmDialogProps) { + const { t } = useTranslation(['pricing', 'common']); + const confirmation = model.confirmation; + const open = confirmation !== null; + const saving = model.phase === 'saving'; + + const buttons = ( + <> + + + + ); + + const body = confirmation && ( + + + {confirmation.tiers.map((tier, index) => { + const months = BILLING_PERIOD_MONTHS[tier.billingPeriod]; + const view = model.tiers.find( + (item) => item.billingPeriod === tier.billingPeriod, + ); + const promo = + tier.promotion && view?.promotion.enabled ? view.promotion : null; + return ( + 0 && 'border-t border-border-subtle', + )} + > + + + {t(`common:billing-periods.${tier.billingPeriod}`)} + + + {t('confirm.row', { + total: price(tier.priceToman), + perMonth: price(Math.round(tier.priceToman / months)), + })} + + + {promo && promo.percentValue !== null && ( + + + + {promo.indefinite || !promo.endsAt + ? t('confirm.promotion-open', { + percent: percent(promo.percentValue, 0), + }) + : t('confirm.promotion', { + percent: percent(promo.percentValue, 0), + date: date(promo.endsAt, { time: false }), + })} + + + {promo.priceToman !== null && + promo.perMonthToman !== null && ( + + {t('confirm.promotion-price', { + total: price(promo.priceToman), + perMonth: price(promo.perMonthToman), + })} + + )} + + )} + + ); + })} + + + {t('confirm.cooldown')} + + + {t('confirm.safety')} + + + ); + + const onClose = saving ? undefined : model.closeConfirmation; + + return layout === 'mobile' ? ( + + {body} + + ) : ( + + {body} + + ); +} diff --git a/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/DateField.tsx b/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/DateField.tsx new file mode 100644 index 0000000..fa26049 --- /dev/null +++ b/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/DateField.tsx @@ -0,0 +1,59 @@ +import { DateTime } from '@lumina/island/atoms/date-time'; +import { FieldError } from '@lumina/island/atoms/field-error'; +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { Icon } from '@lumina/island/atoms/icon'; +import { Typography } from '@lumina/island/atoms/typography'; +import { cn } from '@lumina/island/tools/cn'; +import { useId } from 'react'; +import { useTranslation } from 'react-i18next'; + +import type { DateFieldProps } from './types'; + +/** + * A promotion's start or end (C7 ۴.۲): a button that shows the Shamsi date and time and opens the + * picker. Its error sits under it, as a text field's does. + */ +export function DateField({ id, label, value, error, onOpen }: DateFieldProps) { + const { t } = useTranslation('pricing'); + const errorId = useId(); + const labelId = useId(); + + return ( + + + {label} + + + + {value ? : t('promotion.not-set')} + + + + {error && {error}} + + ); +} diff --git a/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/DateTimeDialog.tsx b/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/DateTimeDialog.tsx new file mode 100644 index 0000000..cde1255 --- /dev/null +++ b/platforms/market/src/app/screens/(flow)/dashboard/pricing/organisms/pricing-form/components/DateTimeDialog.tsx @@ -0,0 +1,202 @@ +import { Button } from '@lumina/island/atoms/button'; +import { Checkbox } from '@lumina/island/atoms/checkbox'; +import { FlexBox } from '@lumina/island/atoms/flex-box'; +import { GridBox } from '@lumina/island/atoms/grid-box'; +import { Select } from '@lumina/island/atoms/select'; +import { Modal } from '@lumina/island/molecules/modal'; +import { Sheet } from '@lumina/island/molecules/sheet'; +import { number } from '@lumina/tools/format'; +import { fromJalali, jalaliMonthLength, toJalali } from '@lumina/tools/jalali'; +import type { JalaliDateTime } from '@lumina/tools/jalali'; +import { useState } from 'react'; +import { useTranslation } from 'react-i18next'; + +import type { DateTimeDialogProps } from '../types'; + +const MONTHS = Array.from({ length: 12 }, (_, index) => index + 1); +const HOURS = Array.from({ length: 24 }, (_, index) => index); +const MINUTES = Array.from({ length: 12 }, (_, index) => index * 5).concat(59); +/** This year and the next two: a promotion is never set further out. */ +const YEARS_AHEAD = 2; + +const pad = (value: number) => number(value).padStart(2, '0'); + +function nearestMinute(minute: number): number { + return MINUTES.reduce((best, option) => + Math.abs(option - minute) < Math.abs(best - minute) ? option : best, + ); +} + +/** + * The Shamsi date and time picker (C7 ۴.۳): day, month, year, hour and minute, each a native select + * (a wheel on phones), and for an end «بدون تاریخ پایان», so ending is one decision in one place. + * A bottom sheet on mobile, a centred modal on desktop (۸.۱). «تأیید» sets the field. + */ +export function DateTimeDialog({ + layout, + pick, + value, + indefinite, + onConfirm, + onClose, +}: DateTimeDialogProps) { + const { t } = useTranslation('pricing'); + const title = + pick?.edge === 'end' ? t('promotion.end') : t('promotion.start'); + + return layout === 'mobile' ? ( + + {pick && ( + + )} + + ) : ( + + {pick && ( + + )} + + ); +} + +type PickerBodyProps = { + isEnd: boolean; + value: string | null; + indefinite: boolean; + onConfirm: (iso: string | null, indefinite: boolean) => void; + size?: 'lg'; +}; + +function PickerBody({ + isEnd, + value, + indefinite, + onConfirm, + size, +}: PickerBodyProps) { + const { t } = useTranslation('pricing'); + const [parts, setParts] = useState(() => { + const start = toJalali(value ?? new Date()); + return { ...start, minute: nearestMinute(start.minute) }; + }); + const [open, setOpen] = useState(indefinite); + const [thisYear] = useState(() => toJalali(new Date()).year); + const years = Array.from( + { length: YEARS_AHEAD + 1 }, + (_, index) => thisYear + index, + ); + if (!years.includes(parts.year)) years.unshift(parts.year); + const days = Array.from( + { length: jalaliMonthLength(parts.year, parts.month) }, + (_, index) => index + 1, + ); + + const set = (key: keyof JalaliDateTime, next: number) => + setParts((current) => { + const updated = { ...current, [key]: next }; + // 31 اردیبهشت → مهر has 30 days: keep the last one. + updated.day = Math.min( + updated.day, + jalaliMonthLength(updated.year, updated.month), + ); + return updated; + }); + + return ( + + + set('month', Number(event.target.value))} + options={MONTHS.map((month) => ({ + value: String(month), + label: t(`picker.months.${month}` as 'picker.months.1'), + }))} + /> + set('hour', Number(event.target.value))} + options={HOURS.map((hour) => ({ + value: String(hour), + label: pad(hour), + }))} + /> +