diff --git a/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/DashboardOverview.tsx b/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/DashboardOverview.tsx
index 08bb545..c500172 100644
--- a/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/DashboardOverview.tsx
+++ b/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/DashboardOverview.tsx
@@ -5,6 +5,7 @@ import { FlexBox } from '@lumina/island/atoms/flex-box';
import { useDashboardOverviewPart } from '../../../../../../../features/overview';
import { AudienceSection } from './components/AudienceSection';
import { IncomeSection } from './components/IncomeSection';
+import { PlanBreakdown } from './components/PlanBreakdown';
import type { DashboardOverviewProps } from './types';
/** داشبورد › نمای کلی (J10-0), the creator's default tab. Loads and fails as one. */
@@ -16,6 +17,7 @@ export function DashboardOverview({ layout }: DashboardOverviewProps) {
+
);
}
diff --git a/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/components/PlanBreakdown.tsx b/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/components/PlanBreakdown.tsx
new file mode 100644
index 0000000..1277326
--- /dev/null
+++ b/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/components/PlanBreakdown.tsx
@@ -0,0 +1,68 @@
+'use client';
+
+import { FlexBox } from '@lumina/island/atoms/flex-box';
+import { Typography } from '@lumina/island/atoms/typography';
+import { Card } from '@lumina/island/molecules/card';
+import { FilterChips } from '@lumina/island/molecules/filter-chips';
+import { Meter } from '@lumina/island/molecules/meter';
+import { SectionTitle } from '@lumina/island/molecules/section-title';
+import { number, percent } from '@lumina/tools/format';
+import { useId, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { planBreakdownRows } from '../../../../../../../../features/overview';
+import type { PlanBreakdownMetric } from '../../../../../../../../features/overview';
+import { PLAN_BREAKDOWN_METRICS } from '../constants';
+import type { PlanBreakdownProps } from '../types';
+
+/**
+ * «تفکیک طرحها»: one bar per plan, by active subscribers, every purchase or income, the chips
+ * choosing which. The note says what «کل خریدها» counts.
+ */
+export function PlanBreakdown({ plans }: PlanBreakdownProps) {
+ const { t } = useTranslation(['dashboard', 'common']);
+ const [metric, setMetric] = useState('active');
+ const titleId = useId();
+
+ return (
+
+
+ ({
+ value,
+ label: t(`overview.plans.metrics.${value}`),
+ }))}
+ value={metric}
+ onChange={setMetric}
+ />
+
+
+ {planBreakdownRows(plans, metric).map((row) => (
+
+ ))}
+
+
+
+ {t('overview.plans.note')}
+
+
+ );
+}
diff --git a/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/constants.ts b/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/constants.ts
index 1bb4674..35eccf7 100644
--- a/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/constants.ts
+++ b/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/constants.ts
@@ -1,4 +1,11 @@
+import type { PlanBreakdownMetric } from '../../../../../../../features/overview';
import { ROUTES } from '../../../../../../navigation/navigation';
/** «مشترکان» opened on who ends within a week (J10-1g). */
export const SUBSCRIBERS_EXPIRING_HREF = `${ROUTES.dashboard.subscribers}?filter=expiring`;
+
+export const PLAN_BREAKDOWN_METRICS: readonly PlanBreakdownMetric[] = [
+ 'active',
+ 'purchases',
+ 'income',
+];
diff --git a/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/types.ts b/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/types.ts
index 1f169d3..63010bb 100644
--- a/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/types.ts
+++ b/platforms/market/src/app/screens/(main)/dashboard/overview/organisms/dashboard-overview/types.ts
@@ -17,3 +17,7 @@ export type DashboardOverviewSkeletonProps = {
/** Fades in after 300 ms, so a fast route never flashes it (`loading.tsx` only, G-3d). */
delayed?: boolean;
};
+
+export type PlanBreakdownProps = {
+ plans: DashboardOverviewPartModel['plans'];
+};
diff --git a/platforms/market/src/features/overview/index.ts b/platforms/market/src/features/overview/index.ts
index 32a6433..058db1a 100644
--- a/platforms/market/src/features/overview/index.ts
+++ b/platforms/market/src/features/overview/index.ts
@@ -1,7 +1,14 @@
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 {
+ planBreakdownRows,
+ useDashboardOverviewPart,
+} from './models/dashboard-overview';
+export type {
+ DashboardOverviewPartModel,
+ PlanBreakdownMetric,
+ PlanBreakdownRow,
+} from './models/dashboard-overview';
export { useOwnSubscriberCount } from './models/own-subscriber-count';
export type { UseOwnSubscriberCountOptions } from './models/own-subscriber-count';
export {
diff --git a/platforms/market/src/features/overview/models/dashboard-overview/index.ts b/platforms/market/src/features/overview/models/dashboard-overview/index.ts
index feb20a6..f94d40a 100644
--- a/platforms/market/src/features/overview/models/dashboard-overview/index.ts
+++ b/platforms/market/src/features/overview/models/dashboard-overview/index.ts
@@ -1,2 +1,7 @@
+export { planBreakdownRows } from './plan-breakdown';
export { useDashboardOverviewPart } from './use-dashboard-overview-part';
-export type { DashboardOverviewPartModel } from './types';
+export type {
+ DashboardOverviewPartModel,
+ PlanBreakdownMetric,
+ PlanBreakdownRow,
+} from './types';
diff --git a/platforms/market/src/features/overview/models/dashboard-overview/plan-breakdown.test.ts b/platforms/market/src/features/overview/models/dashboard-overview/plan-breakdown.test.ts
new file mode 100644
index 0000000..717fe4d
--- /dev/null
+++ b/platforms/market/src/features/overview/models/dashboard-overview/plan-breakdown.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, it } from 'vitest';
+
+import { planBreakdownRows } from './plan-breakdown';
+
+const plan = (
+ tier: 'monthly' | 'quarterly',
+ activeSubscribers: number,
+ income = 0,
+) => ({ tier, activeSubscribers, totalPurchases: 0, income });
+
+describe('planBreakdownRows', () => {
+ it('gives each plan its share of the chosen figure', () => {
+ const rows = planBreakdownRows(
+ [plan('monthly', 3), plan('quarterly', 1)],
+ 'active',
+ );
+ expect(rows.map((row) => row.sharePercent)).toEqual([75, 25]);
+ expect(rows[0].total).toBe(4);
+ });
+
+ it('shows zero shares when nothing has happened yet', () => {
+ const rows = planBreakdownRows([plan('monthly', 0)], 'purchases');
+ expect(rows[0]).toMatchObject({ value: 0, total: 0, sharePercent: 0 });
+ });
+
+ it('keeps a refunded plan out of the others’ shares', () => {
+ const rows = planBreakdownRows(
+ [plan('monthly', 0, 1000), plan('quarterly', 0, -500)],
+ 'income',
+ );
+ expect(rows[0].sharePercent).toBe(100);
+ expect(rows[1]).toMatchObject({ value: -500, sharePercent: 0 });
+ });
+});
diff --git a/platforms/market/src/features/overview/models/dashboard-overview/plan-breakdown.ts b/platforms/market/src/features/overview/models/dashboard-overview/plan-breakdown.ts
new file mode 100644
index 0000000..c4922f5
--- /dev/null
+++ b/platforms/market/src/features/overview/models/dashboard-overview/plan-breakdown.ts
@@ -0,0 +1,35 @@
+import type { DashboardOverviewPlan } from '../../repositories/creator-dashboard';
+import type { PlanBreakdownMetric, PlanBreakdownRow } from './types';
+
+const VALUE_OF: Record<
+ PlanBreakdownMetric,
+ (plan: DashboardOverviewPlan) => number
+> = {
+ active: (plan) => plan.activeSubscribers,
+ purchases: (plan) => plan.totalPurchases,
+ income: (plan) => plan.income,
+};
+
+/**
+ * Each plan's part of the chosen figure, as «تفکیک طرحها» draws it. A refund can leave a plan's
+ * income below zero: that plan's bar is empty and it takes no share from the others.
+ */
+export function planBreakdownRows(
+ plans: DashboardOverviewPlan[],
+ metric: PlanBreakdownMetric,
+): PlanBreakdownRow[] {
+ const valueOf = VALUE_OF[metric];
+ const total = plans.reduce(
+ (sum, plan) => sum + Math.max(valueOf(plan), 0),
+ 0,
+ );
+ return plans.map((plan) => {
+ const value = valueOf(plan);
+ return {
+ tier: plan.tier,
+ value,
+ total,
+ sharePercent: total > 0 ? (Math.max(value, 0) / total) * 100 : 0,
+ };
+ });
+}
diff --git a/platforms/market/src/features/overview/models/dashboard-overview/types.ts b/platforms/market/src/features/overview/models/dashboard-overview/types.ts
index 6fcd32d..8142278 100644
--- a/platforms/market/src/features/overview/models/dashboard-overview/types.ts
+++ b/platforms/market/src/features/overview/models/dashboard-overview/types.ts
@@ -1,3 +1,4 @@
+import type { BillingPeriod } from '../../../../shared/constants';
import type { DashboardOverviewPayload } from '../../repositories/creator-dashboard';
/** «نمای کلی» (J10-0): the API's figures, read once for the whole tab. */
@@ -7,3 +8,15 @@ export type DashboardOverviewPartModel = DashboardOverviewPayload & {
/** No audience and no income yet: the page says how to start (J10-0b). */
isNewcomer: boolean;
};
+
+/** What «تفکیک طرحها» splits by: «مشترکان فعال» · «کل خریدها» · «درآمد». */
+export type PlanBreakdownMetric = 'active' | 'purchases' | 'income';
+
+export type PlanBreakdownRow = {
+ tier: BillingPeriod;
+ value: number;
+ /** Every plan's figure together, a refunded plan's negative income left out. */
+ total: number;
+ /** 0 to 100. */
+ sharePercent: number;
+};
diff --git a/platforms/market/src/shared/locales/fa/dashboard.json b/platforms/market/src/shared/locales/fa/dashboard.json
index ab23c51..bc1ecce 100644
--- a/platforms/market/src/shared/locales/fa/dashboard.json
+++ b/platforms/market/src/shared/locales/fa/dashboard.json
@@ -242,6 +242,21 @@
"month": "درآمد این ماه",
"payable": "قابل واریز",
"payable-link": "رفتن به مالی"
+ },
+ "plans": {
+ "title": "تفکیک طرحها",
+ "metric": "معیار تفکیک",
+ "metrics": {
+ "active": "مشترکان فعال",
+ "purchases": "کل خریدها",
+ "income": "درآمد"
+ },
+ "caption": {
+ "active": "{{n}} نفر · {{share}}",
+ "purchases": "{{n}} خرید · {{share}}",
+ "income": "{{n}} {{currency}} · {{share}}"
+ },
+ "note": "«کل خریدها» همه خریدها از ابتدا است، با تمدید و فعالسازی مجدد و منهای بازگشت وجهها."
}
}
}