feat(dashboard): add the overview tab as the analyst's default

Adds /dashboard/overview to both apps, with its read of the API's overview
and subscriber list routes. The tab row is now «نمای کلی» · «طرح‌های اشتراک» ·
«سیگنال‌ها» · «مالی», and the nav's داشبورد opens it for a creator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amiram_se 2026-11-05 19:05:24 +04:00
parent 96fb709505
commit 33321c2e65
27 changed files with 371 additions and 13 deletions

View File

@ -8,7 +8,7 @@ import { i18n } from '../../../../i18n';
/**
* The creator's داشبورد on desktop (Creator Dashboard ۵.۱): the 640 column under the header, with
* the «داشبورد» heading, the three tabs «طرح‌های اشتراک» · «سیگنال‌ها» · «مالی», then the tab. Each tab is its own
* the «داشبورد» heading, the four tabs «نمای کلی» · «طرح‌های اشتراک» · «سیگنال‌ها» · «مالی», then the tab. Each tab is its own
* route with its own loading, so the heading and the tabs stay while one loads. Locked until
* registration step 5 is done (0016).
*/

View File

@ -0,0 +1,14 @@
import { DashboardOverviewSkeleton } from '@lumina/market/app/screens/(main)/dashboard/overview/organisms/dashboard-overview';
import { i18n } from '../../../../../i18n';
/** نمای کلی before it arrives; the layout keeps the bar and the tabs. */
export default function Loading() {
return (
<DashboardOverviewSkeleton
layout="desktop"
label={i18n.t('dashboard:overview.loading')}
delayed
/>
);
}

View File

@ -0,0 +1,42 @@
import { PartBoundary } from '@lumina/market/app/error-boundaries';
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
import {
DashboardOverview,
DashboardOverviewSkeleton,
} from '@lumina/market/app/screens/(main)/dashboard/overview/organisms/dashboard-overview';
import type { Metadata } from 'next';
import { Suspense } from 'react';
import { i18n } from '../../../../../i18n';
export const metadata: Metadata = {
title: i18n.t('dashboard:overview.meta-title'),
robots: { index: false },
};
/**
* داشبورد › نمای کلی (J10-0), the creator's default tab: audience, income, the split by plan and
* the signals' summary, the creator's own, in the browser only. The tabs stay while it loads.
*/
export default function OverviewPage() {
const skeleton = (
<DashboardOverviewSkeleton
layout="desktop"
label={i18n.t('dashboard:overview.loading')}
/>
);
return (
<AuthGuard role="creator" fallback={skeleton}>
<PartBoundary
name="dashboard-overview"
description={i18n.t('dashboard:overview.error')}
framed
>
<Suspense fallback={skeleton}>
<DashboardOverview layout="desktop" />
</Suspense>
</PartBoundary>
</AuthGuard>
);
}

View File

@ -7,8 +7,8 @@ import type { ReactNode } from 'react';
import { i18n } from '../../../../i18n';
/**
* The creator's داشبورد on mobile (Creator Dashboard ۱.۱, 0034): the tab bar «داشبورد», the three
* tabs «طرح‌های اشتراک» · «سیگنال‌ها» · «مالی», then the tab. Each tab is its own route with its own loading, so the
* The creator's داشبورد on mobile (Creator Dashboard ۱.۱, 0034): the tab bar «داشبورد», the four
* tabs «نمای کلی» · «طرح‌های اشتراک» · «سیگنال‌ها» · «مالی», then the tab. Each tab is its own route with its own loading, so the
* bar and the tabs stay while one loads. Locked until registration step 5 is done (0016).
*/
export default function CreatorDashboardLayout({

View File

@ -0,0 +1,14 @@
import { DashboardOverviewSkeleton } from '@lumina/market/app/screens/(main)/dashboard/overview/organisms/dashboard-overview';
import { i18n } from '../../../../../i18n';
/** نمای کلی before it arrives; the layout keeps the bar and the tabs. */
export default function Loading() {
return (
<DashboardOverviewSkeleton
layout="mobile"
label={i18n.t('dashboard:overview.loading')}
delayed
/>
);
}

View File

@ -0,0 +1,42 @@
import { PartBoundary } from '@lumina/market/app/error-boundaries';
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
import {
DashboardOverview,
DashboardOverviewSkeleton,
} from '@lumina/market/app/screens/(main)/dashboard/overview/organisms/dashboard-overview';
import type { Metadata } from 'next';
import { Suspense } from 'react';
import { i18n } from '../../../../../i18n';
export const metadata: Metadata = {
title: i18n.t('dashboard:overview.meta-title'),
robots: { index: false },
};
/**
* داشبورد › نمای کلی (J10-0), the creator's default tab: audience, income, the split by plan and
* the signals' summary, the creator's own, in the browser only. The tabs stay while it loads.
*/
export default function OverviewPage() {
const skeleton = (
<DashboardOverviewSkeleton
layout="mobile"
label={i18n.t('dashboard:overview.loading')}
/>
);
return (
<AuthGuard role="creator" fallback={skeleton}>
<PartBoundary
name="dashboard-overview"
description={i18n.t('dashboard:overview.error')}
framed
>
<Suspense fallback={skeleton}>
<DashboardOverview layout="mobile" />
</Suspense>
</PartBoundary>
</AuthGuard>
);
}

View File

@ -74,7 +74,9 @@ export function BottomNav() {
)}
<NavTab
href={
isCreator ? ROUTES.dashboard.plans : ROUTES.dashboard.subscriptions
isCreator
? ROUTES.dashboard.overview
: ROUTES.dashboard.subscriptions
}
icon="dashboard"
label={t('nav.dashboard')}

View File

@ -92,7 +92,7 @@ export function DesktopHeader() {
<HeaderNavLink
href={
isCreator
? ROUTES.dashboard.plans
? ROUTES.dashboard.overview
: ROUTES.dashboard.subscriptions
}
label={t('nav.dashboard')}

View File

@ -57,8 +57,11 @@ export const ROUTES = {
subscriptions: '/dashboard/subscriptions',
transactions: '/dashboard/transactions',
following: '/dashboard/following',
/** The creator's داشبورد: «طرح‌های اشتراک» (the default tab), «سیگنال‌ها» and «مالی». */
/** The creator's داشبورد: «نمای کلی» (the default tab), «طرح‌های اشتراک», «سیگنال‌ها» and «مالی». */
overview: '/dashboard/overview',
plans: '/dashboard/plans',
/** «مشترکان», pushed from نمای کلی and طرح‌های اشتراک; `?filter=expiring`. */
subscribers: '/dashboard/subscribers',
predictions: '/dashboard/predictions',
/** «همه سیگنال‌ها», pushed from the «سیگنال‌ها» tab; `?status=closed|all`. */
predictionsAll: '/dashboard/predictions/all',

View File

@ -9,8 +9,8 @@ import type { DashboardTabsProps } from './types';
/**
* The داشبورد's section row, full width, the current one underlined: the investor's «اشتراک‌ها» ·
* «تراکنش‌ها» · «دنبال‌شده‌ها» (U8 ۴.۱, ۶.۱; U8 ۵.۲), or the creator's «طرح‌های اشتراک» ·
* «سیگنال‌ها» · «مالی» (Creator Dashboard ۱.۱, J10-0, 0034). The dashboard layout renders it once, so it stays put while a section
* «تراکنش‌ها» · «دنبال‌شده‌ها» (U8 ۴.۱, ۶.۱; U8 ۵.۲), or the creator's «نمای کلی» ·
* «طرح‌های اشتراک» · «سیگنال‌ها» · «مالی» (J10-0, 0034, 0072). The dashboard layout renders it once, so it stays put while a section
* loads; the current one comes from the URL, which the server render already knows.
*/
export function DashboardTabs({

View File

@ -7,8 +7,9 @@ export const INVESTOR_TABS = [
{ href: ROUTES.dashboard.following, label: 'tabs.following' },
] as const;
/** The creator's three tabs, «طرح‌های اشتراک» first (Creator Dashboard ۱.۱, J10-0). */
/** The creator's four tabs, «نمای کلی» first (J10-0). */
export const CREATOR_TABS = [
{ href: ROUTES.dashboard.overview, label: 'creator-tabs.overview' },
{ href: ROUTES.dashboard.plans, label: 'creator-tabs.plans' },
{ href: ROUTES.dashboard.predictions, label: 'creator-tabs.predictions' },
{ href: ROUTES.dashboard.finance, label: 'creator-tabs.finance' },

View File

@ -0,0 +1,13 @@
'use client';
import { FlexBox } from '@lumina/island/atoms/flex-box';
import { useDashboardOverviewPart } from '../../../../../../../features/overview';
import type { DashboardOverviewProps } from './types';
/** داشبورد › نمای کلی (J10-0), the creator's default tab. Loads and fails as one. */
export function DashboardOverview({ layout }: DashboardOverviewProps) {
useDashboardOverviewPart();
return <FlexBox direction="flex-col" gap="gap-6" data-layout={layout} />;
}

View File

@ -0,0 +1,43 @@
import { FlexBox } from '@lumina/island/atoms/flex-box';
import { GridBox } from '@lumina/island/atoms/grid-box';
import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton';
import type { DashboardOverviewSkeletonProps } from './types';
/** «نمای کلی» before it arrives: each section's title over its tiles, the plans' card under them. */
export function DashboardOverviewSkeleton({
layout,
label,
delayed,
}: DashboardOverviewSkeletonProps) {
const cols = layout === 'desktop' ? 'grid-cols-3' : 'grid-cols-2';
return (
<SkeletonRegion label={label} delayed={delayed}>
<FlexBox direction="flex-col" gap="gap-6">
{[0, 1].map((section) => (
<FlexBox key={section} direction="flex-col" gap="gap-3">
<Skeleton width="25%" />
<GridBox cols={cols} gap="gap-2">
{[0, 1, 2].map((tile) => (
<FlexBox
key={tile}
direction="flex-col"
gap="gap-2"
className="rounded-lg border border-border-subtle p-4"
>
<Skeleton width="60%" />
<Skeleton width="35%" height={36} />
</FlexBox>
))}
</GridBox>
</FlexBox>
))}
<FlexBox direction="flex-col" gap="gap-3">
<Skeleton width="25%" />
<Skeleton height={160} />
</FlexBox>
</FlexBox>
</SkeletonRegion>
);
}

View File

@ -0,0 +1,3 @@
export { DashboardOverview } from './DashboardOverview';
export { DashboardOverviewSkeleton } from './DashboardOverviewSkeleton';
export type { DashboardOverviewSkeletonProps } from './types';

View File

@ -0,0 +1,11 @@
export type DashboardOverviewLayout = 'mobile' | 'desktop';
export type DashboardOverviewProps = { layout: DashboardOverviewLayout };
export type DashboardOverviewSkeletonProps = {
layout: DashboardOverviewLayout;
/** Hidden status text: «در حال بارگذاری نمای کلی…». */
label: string;
/** Fades in after 300 ms, so a fast route never flashes it (`loading.tsx` only, G-3d). */
delayed?: boolean;
};

View File

@ -8,6 +8,7 @@ export const TAB_BARS: Record<string, PageBar> = {
[ROUTES.dashboard.subscriptions]: { kind: 'tab', title: 'nav.dashboard' },
[ROUTES.dashboard.transactions]: { kind: 'tab', title: 'nav.dashboard' },
[ROUTES.dashboard.following]: { kind: 'tab', title: 'nav.dashboard' },
[ROUTES.dashboard.overview]: { kind: 'tab', title: 'nav.dashboard' },
[ROUTES.dashboard.plans]: { kind: 'tab', title: 'nav.dashboard' },
[ROUTES.dashboard.finance]: { kind: 'tab', title: 'nav.dashboard' },
};

View File

@ -29,12 +29,13 @@ const CREATOR_LINK = /^\/traders\/([^/?#]+)/;
// The app pages a notification may open; a channel and its posts (a closed prediction) and a
// channel's checkout (a payment the bank never confirmed, capacity opened with the code) open too.
// Any other link, such as a page not built yet (the creator's /dashboard/subscribers) or another
// site, leaves the item plain rather than leading to not-found.
// Any other link, such as another site, leaves the item plain rather than leading to not-found.
const IN_APP_PATHS: ReadonlySet<string> = new Set([
ROUTES.dashboard.subscriptions,
ROUTES.dashboard.transactions,
ROUTES.dashboard.overview,
ROUTES.dashboard.plans,
ROUTES.dashboard.subscribers,
ROUTES.dashboard.finance,
ROUTES.account.profile,
ROUTES.notifications,

View File

@ -1,5 +1,7 @@
export { useAudiencePart } from './models/audience';
export type { AudiencePartModel } from './models/audience';
export { useDashboardOverviewPart } from './models/dashboard-overview';
export type { DashboardOverviewPartModel } from './models/dashboard-overview';
export { useOwnSubscriberCount } from './models/own-subscriber-count';
export type { UseOwnSubscriberCountOptions } from './models/own-subscriber-count';
export {
@ -9,5 +11,10 @@ export {
export type {
CreatorDashboardPayload,
CreatorTierPayload,
DashboardOverviewPayload,
DashboardOverviewPlan,
OwnSubscriberPayload,
OwnSubscribersFilter,
OwnSubscribersPagePayload,
RecentPaymentPayload,
} from './repositories/creator-dashboard';

View File

@ -0,0 +1,2 @@
export { useDashboardOverviewPart } from './use-dashboard-overview-part';
export type { DashboardOverviewPartModel } from './types';

View File

@ -0,0 +1,9 @@
import type { DashboardOverviewPayload } from '../../repositories/creator-dashboard';
/** «نمای کلی» (J10-0): the API's figures, read once for the whole tab. */
export type DashboardOverviewPartModel = DashboardOverviewPayload & {
/** Plans with someone on them now, for «در {n} طرح». */
plansWithSubscribers: number;
/** No audience and no income yet: the page says how to start (J10-0b). */
isNewcomer: boolean;
};

View File

@ -0,0 +1,38 @@
import { useSuspenseQuery } from '@tanstack/react-query';
import { BILLING_PERIODS } from '../../../../shared/constants';
import {
creatorDashboardRepository,
overviewKeys,
} from '../../repositories/creator-dashboard';
import type { DashboardOverviewPartModel } from './types';
/**
* داشبورد › نمای کلی (J10-0): audience, income and the split by plan, in the browser only. A creator
* with no plan yet still sees the four periods at zero (J10-0b).
*/
export function useDashboardOverviewPart(): DashboardOverviewPartModel {
const { data } = useSuspenseQuery({
queryKey: overviewKeys.overview(),
queryFn: ({ signal }) => creatorDashboardRepository.getOverview({ signal }),
});
return {
...data,
plans:
data.plans.length > 0
? data.plans
: BILLING_PERIODS.map((tier) => ({
tier,
activeSubscribers: 0,
totalPurchases: 0,
income: 0,
})),
plansWithSubscribers: data.plans.filter(
(plan) => plan.activeSubscribers > 0,
).length,
isNewcomer:
data.followers === 0 &&
data.activeSubscribers === 0 &&
data.income.total === 0,
};
}

View File

@ -1,6 +1,13 @@
import type { OwnSubscribersFilter } from './types';
export const CREATOR_DASHBOARD_ENDPOINT = '/subscriptions/me/dashboard';
export const DASHBOARD_OVERVIEW_ENDPOINT = '/me/dashboard/overview';
export const OWN_SUBSCRIBERS_ENDPOINT = '/me/subscribers';
export const overviewKeys = {
all: ['overview'] as const,
dashboard: () => [...overviewKeys.all, 'dashboard'] as const,
overview: () => [...overviewKeys.all, 'overview'] as const,
subscribers: (filter: OwnSubscribersFilter) =>
[...overviewKeys.all, 'subscribers', filter] as const,
};

View File

@ -1,9 +1,20 @@
import { overviewHttp } from '../../http';
import { CREATOR_DASHBOARD_ENDPOINT } from './constants';
import { toCreatorDashboardPayload } from './mappers';
import {
CREATOR_DASHBOARD_ENDPOINT,
DASHBOARD_OVERVIEW_ENDPOINT,
OWN_SUBSCRIBERS_ENDPOINT,
} from './constants';
import {
toCreatorDashboardPayload,
toOwnSubscribersPagePayload,
} from './mappers';
import type {
CreatorDashboardPayload,
CreatorDashboardResponseDto,
DashboardOverviewPayload,
OwnSubscribersFilter,
OwnSubscribersPagePayload,
OwnSubscribersPageResponseDto,
} from './types';
/** The signed-in creator's subscription figures. Creator session only: an investor gets 403. */
@ -17,4 +28,26 @@ export const creatorDashboardRepository = {
);
return toCreatorDashboardPayload(response);
},
/** «نمای کلی»: audience, income and the split by plan. */
getOverview({
signal,
}: { signal?: AbortSignal } = {}): Promise<DashboardOverviewPayload> {
return overviewHttp.get<DashboardOverviewPayload>(
DASHBOARD_OVERVIEW_ENDPOINT,
{ signal },
);
},
/** A page of who subscribes now, soonest-ending first. */
async listSubscribers(
{ filter, cursor }: { filter: OwnSubscribersFilter; cursor?: string },
{ signal }: { signal?: AbortSignal } = {},
): Promise<OwnSubscribersPagePayload> {
const response = await overviewHttp.get<OwnSubscribersPageResponseDto>(
OWN_SUBSCRIBERS_ENDPOINT,
{ params: { filter, cursor }, signal },
);
return toOwnSubscribersPagePayload(response);
},
};

View File

@ -3,5 +3,10 @@ export { creatorDashboardRepository } from './creator-dashboard';
export type {
CreatorDashboardPayload,
CreatorTierPayload,
DashboardOverviewPayload,
DashboardOverviewPlan,
OwnSubscriberPayload,
OwnSubscribersFilter,
OwnSubscribersPagePayload,
RecentPaymentPayload,
} from './types';

View File

@ -1,6 +1,9 @@
import { toApiUrl } from '../../../../shared/utils';
import type {
CreatorDashboardPayload,
CreatorDashboardResponseDto,
OwnSubscribersPagePayload,
OwnSubscribersPageResponseDto,
} from './types';
export function toCreatorDashboardPayload(
@ -26,3 +29,15 @@ export function toCreatorDashboardPayload(
})),
};
}
export function toOwnSubscribersPagePayload(
dto: OwnSubscribersPageResponseDto,
): OwnSubscribersPagePayload {
return {
...dto,
items: dto.items.map((item) => ({
...item,
avatarUrl: toApiUrl(item.avatarUrl),
})),
};
}

View File

@ -46,3 +46,49 @@ export type CreatorDashboardResponseDto = {
tiers: CreatorTierEntity[];
recentTransactions: PaymentEntity[];
};
/** One plan in «تفکیک طرح‌ها». */
export type DashboardOverviewPlan = {
tier: BillingPeriod;
/** Running now on this plan. */
activeSubscribers: number;
/** Every purchase since the start, renewals included, minus refunded ones. */
totalPurchases: number;
/** Whole Toman, net of commission and refunds. */
income: number;
};
/** `GET /me/dashboard/overview`, «نمای کلی» (J10-0). Income is whole Toman, net. */
export type DashboardOverviewPayload = {
/** Subscribers included; only the creator sees it. */
followers: number;
activeSubscribers: number;
/** Ending within the next 7 days. */
expiringIn7d: number;
income: {
total: number;
/** The current Shamsi month, in Tehran. */
thisMonth: number;
payable: number;
};
plans: DashboardOverviewPlan[];
};
export type OwnSubscribersFilter = 'all' | 'expiring';
/** One running subscription. Only the @username and avatar ever leave the API, never a phone. */
export type OwnSubscriberPayload = {
username: string | null;
avatarUrl: string | null;
tier: BillingPeriod | null;
endsAt: string;
};
/** `GET /me/subscribers`: soonest-ending first, 20 a page. */
export type OwnSubscribersPagePayload = {
items: OwnSubscriberPayload[];
counts: Record<OwnSubscribersFilter, number>;
nextCursor: string | null;
};
export type OwnSubscribersPageResponseDto = OwnSubscribersPagePayload;

View File

@ -135,6 +135,7 @@
"subscription-value": "{{period}} — {{name}}"
},
"creator-tabs": {
"overview": "نمای کلی",
"plans": "طرح‌های اشتراک",
"predictions": "سیگنال‌ها",
"finance": "مالی"
@ -216,5 +217,10 @@
"sent": "درخواست شما ثبت شد.",
"failed": "درخواست افزایش ظرفیت ثبت نشد"
}
},
"overview": {
"meta-title": "نمای کلی",
"loading": "در حال بارگذاری نمای کلی…",
"error": "نمای کلی بارگذاری نشد. دوباره تلاش کنید."
}
}