feat(dashboard): show audience and income on the overview tab
Followers, active subscribers and those ending within a week, then total, this Shamsi month's and payable income, with their links. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
33321c2e65
commit
c6da027450
|
|
@ -31,6 +31,11 @@ const dateFormatter = new Intl.DateTimeFormat(LOCALE, {
|
||||||
month: 'long',
|
month: 'long',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
});
|
});
|
||||||
|
const monthFormatter = new Intl.DateTimeFormat(LOCALE, {
|
||||||
|
timeZone: TIME_ZONE,
|
||||||
|
month: 'long',
|
||||||
|
year: 'numeric',
|
||||||
|
});
|
||||||
const timeFormatter = new Intl.DateTimeFormat(LOCALE, {
|
const timeFormatter = new Intl.DateTimeFormat(LOCALE, {
|
||||||
timeZone: TIME_ZONE,
|
timeZone: TIME_ZONE,
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
|
|
@ -171,6 +176,15 @@ export function date(
|
||||||
return time ? `${day}${DATE_TIME_JOINER}${timeFormatter.format(at)}` : day;
|
return time ? `${day}${DATE_TIME_JOINER}${timeFormatter.format(at)}` : day;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The Shamsi month and year in Tehran: `مهر 1405`. */
|
||||||
|
export function month(value: DateInput): string {
|
||||||
|
// Intl writes the year first in Persian.
|
||||||
|
const parts = monthFormatter.formatToParts(toDate(value));
|
||||||
|
const part = (type: Intl.DateTimeFormatPartTypes) =>
|
||||||
|
parts.find((item) => item.type === type)?.value ?? '';
|
||||||
|
return `${part('month')} ${part('year')}`;
|
||||||
|
}
|
||||||
|
|
||||||
/** Time of day in Tehran: `14:05`, such as when a draft was last saved. */
|
/** Time of day in Tehran: `14:05`, such as when a draft was last saved. */
|
||||||
export function time(value: DateInput): string {
|
export function time(value: DateInput): string {
|
||||||
return timeFormatter.format(toDate(value));
|
return timeFormatter.format(toDate(value));
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export {
|
||||||
iso,
|
iso,
|
||||||
latinDigits,
|
latinDigits,
|
||||||
list,
|
list,
|
||||||
|
month,
|
||||||
number,
|
number,
|
||||||
percent,
|
percent,
|
||||||
price,
|
price,
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,19 @@
|
||||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||||
|
|
||||||
import { useDashboardOverviewPart } from '../../../../../../../features/overview';
|
import { useDashboardOverviewPart } from '../../../../../../../features/overview';
|
||||||
|
import { AudienceSection } from './components/AudienceSection';
|
||||||
|
import { IncomeSection } from './components/IncomeSection';
|
||||||
import type { DashboardOverviewProps } from './types';
|
import type { DashboardOverviewProps } from './types';
|
||||||
|
|
||||||
/** داشبورد › نمای کلی (J10-0), the creator's default tab. Loads and fails as one. */
|
/** داشبورد › نمای کلی (J10-0), the creator's default tab. Loads and fails as one. */
|
||||||
export function DashboardOverview({ layout }: DashboardOverviewProps) {
|
export function DashboardOverview({ layout }: DashboardOverviewProps) {
|
||||||
useDashboardOverviewPart();
|
const overview = useDashboardOverviewPart();
|
||||||
|
const cols = layout === 'desktop' ? 'grid-cols-3' : 'grid-cols-2';
|
||||||
|
|
||||||
return <FlexBox direction="flex-col" gap="gap-6" data-layout={layout} />;
|
return (
|
||||||
|
<FlexBox direction="flex-col" gap="gap-6">
|
||||||
|
<AudienceSection overview={overview} cols={cols} />
|
||||||
|
<IncomeSection overview={overview} cols={cols} />
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||||
|
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||||
|
import { Link } from '@lumina/island/atoms/link';
|
||||||
|
import { InfoTip } from '@lumina/island/molecules/info-tip';
|
||||||
|
import { SectionTitle } from '@lumina/island/molecules/section-title';
|
||||||
|
import { StatTile } from '@lumina/island/molecules/stat-tile';
|
||||||
|
import { number } from '@lumina/tools/format';
|
||||||
|
import { useId } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { SUBSCRIBERS_EXPIRING_HREF } from '../constants';
|
||||||
|
import type { OverviewSectionProps } from '../types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* «مخاطبان»: followers (the creator's own figure, subscribers included), who subscribes now and
|
||||||
|
* who ends within a week, with the way to see them. Counts only, never a list of people here.
|
||||||
|
*/
|
||||||
|
export function AudienceSection({ overview, cols }: OverviewSectionProps) {
|
||||||
|
const { t } = useTranslation('dashboard');
|
||||||
|
const titleId = useId();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
tag="section"
|
||||||
|
aria-labelledby={titleId}
|
||||||
|
direction="flex-col"
|
||||||
|
gap="gap-3"
|
||||||
|
>
|
||||||
|
<SectionTitle title={t('overview.audience.title')} titleId={titleId} />
|
||||||
|
<GridBox cols={cols} gap="gap-2">
|
||||||
|
<StatTile
|
||||||
|
icon="users"
|
||||||
|
label={
|
||||||
|
<>
|
||||||
|
{t('overview.audience.followers')}
|
||||||
|
<InfoTip label={t('overview.audience.followers-tip-label')}>
|
||||||
|
{t('overview.audience.followers-tip')}
|
||||||
|
</InfoTip>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
value={number(overview.followers)}
|
||||||
|
/>
|
||||||
|
<StatTile
|
||||||
|
icon="star"
|
||||||
|
label={t('overview.audience.subscribers')}
|
||||||
|
value={number(overview.activeSubscribers)}
|
||||||
|
hint={
|
||||||
|
overview.activeSubscribers === 0
|
||||||
|
? t('overview.audience.subscribers-none')
|
||||||
|
: t('overview.audience.subscribers-plans', {
|
||||||
|
n: number(overview.plansWithSubscribers),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatTile
|
||||||
|
icon="clock"
|
||||||
|
label={t('overview.audience.expiring')}
|
||||||
|
value={number(overview.expiringIn7d)}
|
||||||
|
hint={t('overview.audience.expiring-hint')}
|
||||||
|
footer={
|
||||||
|
overview.expiringIn7d > 0 && (
|
||||||
|
<FlexBox>
|
||||||
|
<Link
|
||||||
|
href={SUBSCRIBERS_EXPIRING_HREF}
|
||||||
|
icon="chevron-left"
|
||||||
|
standalone
|
||||||
|
>
|
||||||
|
{t('overview.audience.expiring-link')}
|
||||||
|
</Link>
|
||||||
|
</FlexBox>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</GridBox>
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
import { Amount } from '@lumina/island/atoms/amount';
|
||||||
|
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||||
|
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||||
|
import { Link } from '@lumina/island/atoms/link';
|
||||||
|
import { InfoTip } from '@lumina/island/molecules/info-tip';
|
||||||
|
import { SectionTitle } from '@lumina/island/molecules/section-title';
|
||||||
|
import { StatTile } from '@lumina/island/molecules/stat-tile';
|
||||||
|
import { month } from '@lumina/tools/format';
|
||||||
|
import { useId } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { ROUTES } from '../../../../../../../navigation/navigation';
|
||||||
|
import type { OverviewSectionProps } from '../types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* «درآمد»: everything earned, net of commission and refunds, this Shamsi month's part of it, and
|
||||||
|
* what can be paid out, with the way to مالی.
|
||||||
|
*/
|
||||||
|
export function IncomeSection({ overview, cols }: OverviewSectionProps) {
|
||||||
|
const { t } = useTranslation(['dashboard', 'common']);
|
||||||
|
const titleId = useId();
|
||||||
|
const currency = t('common:currency');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
tag="section"
|
||||||
|
aria-labelledby={titleId}
|
||||||
|
direction="flex-col"
|
||||||
|
gap="gap-3"
|
||||||
|
>
|
||||||
|
<SectionTitle title={t('overview.income.title')} titleId={titleId} />
|
||||||
|
<GridBox cols={cols} gap="gap-2">
|
||||||
|
<StatTile
|
||||||
|
icon="wallet"
|
||||||
|
label={
|
||||||
|
<>
|
||||||
|
{t('overview.income.total')}
|
||||||
|
<InfoTip label={t('overview.income.total-tip-label')}>
|
||||||
|
{t('overview.income.total-tip')}
|
||||||
|
</InfoTip>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
value={
|
||||||
|
<Amount
|
||||||
|
value={overview.income.total}
|
||||||
|
size="title"
|
||||||
|
currency={currency}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatTile
|
||||||
|
icon="calendar"
|
||||||
|
label={t('overview.income.month')}
|
||||||
|
value={
|
||||||
|
<Amount
|
||||||
|
value={overview.income.thisMonth}
|
||||||
|
size="title"
|
||||||
|
currency={currency}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
hint={month(new Date())}
|
||||||
|
/>
|
||||||
|
<StatTile
|
||||||
|
icon="receipt"
|
||||||
|
label={t('overview.income.payable')}
|
||||||
|
value={
|
||||||
|
<Amount
|
||||||
|
value={overview.income.payable}
|
||||||
|
size="title"
|
||||||
|
currency={currency}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
footer={
|
||||||
|
<FlexBox>
|
||||||
|
<Link
|
||||||
|
href={ROUTES.dashboard.finance}
|
||||||
|
icon="chevron-left"
|
||||||
|
standalone
|
||||||
|
>
|
||||||
|
{t('overview.income.payable-link')}
|
||||||
|
</Link>
|
||||||
|
</FlexBox>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</GridBox>
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
import { ROUTES } from '../../../../../../navigation/navigation';
|
||||||
|
|
||||||
|
/** «مشترکان» opened on who ends within a week (J10-1g). */
|
||||||
|
export const SUBSCRIBERS_EXPIRING_HREF = `${ROUTES.dashboard.subscribers}?filter=expiring`;
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
|
import type { DashboardOverviewPartModel } from '../../../../../../../features/overview';
|
||||||
|
|
||||||
export type DashboardOverviewLayout = 'mobile' | 'desktop';
|
export type DashboardOverviewLayout = 'mobile' | 'desktop';
|
||||||
|
|
||||||
export type DashboardOverviewProps = { layout: DashboardOverviewLayout };
|
export type DashboardOverviewProps = { layout: DashboardOverviewLayout };
|
||||||
|
|
||||||
|
export type OverviewSectionProps = {
|
||||||
|
overview: DashboardOverviewPartModel;
|
||||||
|
/** Three tiles in a row on desktop, two on mobile. */
|
||||||
|
cols: 'grid-cols-2' | 'grid-cols-3';
|
||||||
|
};
|
||||||
|
|
||||||
export type DashboardOverviewSkeletonProps = {
|
export type DashboardOverviewSkeletonProps = {
|
||||||
layout: DashboardOverviewLayout;
|
layout: DashboardOverviewLayout;
|
||||||
/** Hidden status text: «در حال بارگذاری نمای کلی…». */
|
/** Hidden status text: «در حال بارگذاری نمای کلی…». */
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,27 @@
|
||||||
"overview": {
|
"overview": {
|
||||||
"meta-title": "نمای کلی",
|
"meta-title": "نمای کلی",
|
||||||
"loading": "در حال بارگذاری نمای کلی…",
|
"loading": "در حال بارگذاری نمای کلی…",
|
||||||
"error": "نمای کلی بارگذاری نشد. دوباره تلاش کنید."
|
"error": "نمای کلی بارگذاری نشد. دوباره تلاش کنید.",
|
||||||
|
"audience": {
|
||||||
|
"title": "مخاطبان",
|
||||||
|
"followers": "دنبالکنندگان",
|
||||||
|
"followers-tip": "شامل مشترکان هم میشود.",
|
||||||
|
"followers-tip-label": "توضیح دنبالکنندگان",
|
||||||
|
"subscribers": "مشترکان فعال",
|
||||||
|
"subscribers-plans": "در {{n}} طرح",
|
||||||
|
"subscribers-none": "هنوز مشترکی ندارید",
|
||||||
|
"expiring": "در حال انقضا",
|
||||||
|
"expiring-hint": "7 روز آینده",
|
||||||
|
"expiring-link": "مشاهده مشترکان"
|
||||||
|
},
|
||||||
|
"income": {
|
||||||
|
"title": "درآمد",
|
||||||
|
"total": "درآمد کل",
|
||||||
|
"total-tip": "از ابتدا، خالص بعد از کمیسیون لومینا و بازگشت وجهها.",
|
||||||
|
"total-tip-label": "توضیح درآمد کل",
|
||||||
|
"month": "درآمد این ماه",
|
||||||
|
"payable": "قابل واریز",
|
||||||
|
"payable-link": "رفتن به مالی"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue