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), + }))} + /> +