feat(dashboard): list subscribers and clean the plans tab
The plans tab loses «مخاطبان», whose figures now live on the overview, and shows the soonest-ending subscribers instead. /dashboard/subscribers lists them all with «همه» and «در حال انقضا»; notifications may now open it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
935d59dab8
commit
d56064fa2e
|
|
@ -1,7 +1,7 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { AudienceStatsSkeleton } from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/audience-stats';
|
||||
import { InviteCodeCardSkeleton } from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/invite-code-card';
|
||||
import { PricingCardSkeleton } from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/pricing-card';
|
||||
import { SubscribersPreviewSkeleton } from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/subscribers-preview';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ export default function Loading() {
|
|||
label={i18n.t('dashboard:invite.loading')}
|
||||
delayed
|
||||
/>
|
||||
<AudienceStatsSkeleton
|
||||
label={i18n.t('dashboard:audience.loading')}
|
||||
<SubscribersPreviewSkeleton
|
||||
label={i18n.t('dashboard:subscribers.loading')}
|
||||
delayed
|
||||
/>
|
||||
</FlexBox>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import {
|
||||
AudienceStats,
|
||||
AudienceStatsSkeleton,
|
||||
} from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/audience-stats';
|
||||
import {
|
||||
InviteCodeCard,
|
||||
InviteCodeCardSkeleton,
|
||||
|
|
@ -13,6 +9,10 @@ import {
|
|||
PricingCard,
|
||||
PricingCardSkeleton,
|
||||
} from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/pricing-card';
|
||||
import {
|
||||
SubscribersPreview,
|
||||
SubscribersPreviewSkeleton,
|
||||
} from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/subscribers-preview';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ export const metadata: Metadata = {
|
|||
};
|
||||
|
||||
/**
|
||||
* داشبورد › طرحهای اشتراک (J10-1): «قیمت طرحها», «کد دعوت» (only once approved) and «مخاطبان»,
|
||||
* داشبورد › طرحهای اشتراک (J10-1): «قیمت طرحها», «کد دعوت» (only once approved) and «مشترکان»,
|
||||
* the creator's own, in the browser only. Each block loads and fails on its own; the tabs stay.
|
||||
*/
|
||||
export default function PlansPage() {
|
||||
|
|
@ -41,8 +41,10 @@ export default function PlansPage() {
|
|||
label={i18n.t('dashboard:invite.loading')}
|
||||
/>
|
||||
);
|
||||
const audienceSkeleton = (
|
||||
<AudienceStatsSkeleton label={i18n.t('dashboard:audience.loading')} />
|
||||
const subscribersSkeleton = (
|
||||
<SubscribersPreviewSkeleton
|
||||
label={i18n.t('dashboard:subscribers.loading')}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
@ -52,7 +54,7 @@ export default function PlansPage() {
|
|||
<FlexBox direction="flex-col" gap="gap-4">
|
||||
{pricingSkeleton}
|
||||
{inviteSkeleton}
|
||||
{audienceSkeleton}
|
||||
{subscribersSkeleton}
|
||||
</FlexBox>
|
||||
}
|
||||
>
|
||||
|
|
@ -79,12 +81,12 @@ export default function PlansPage() {
|
|||
</Suspense>
|
||||
</PartBoundary>
|
||||
<PartBoundary
|
||||
name="audience-stats"
|
||||
description={i18n.t('dashboard:audience.error')}
|
||||
name="subscribers-preview"
|
||||
description={i18n.t('dashboard:subscribers.error')}
|
||||
framed
|
||||
>
|
||||
<Suspense fallback={audienceSkeleton}>
|
||||
<AudienceStats />
|
||||
<Suspense fallback={subscribersSkeleton}>
|
||||
<SubscribersPreview />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</FlexBox>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
// Locked until a creator finishes registration step 5 (0016), as the tab is; the guard renders
|
||||
// the page as is.
|
||||
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { DesktopPageTitle, ROUTES } from '@lumina/market/app/navigation';
|
||||
import { SubscriberListSkeleton } from '@lumina/market/app/screens/(main)/dashboard/subscribers/organisms/subscriber-list';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
/** «مشترکان» before it arrives, under its real title. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
className="w-full max-w-content"
|
||||
>
|
||||
<DesktopPageTitle
|
||||
title={i18n.t('dashboard:subscribers.title')}
|
||||
parentHref={ROUTES.dashboard.overview}
|
||||
/>
|
||||
<SubscriberListSkeleton
|
||||
label={i18n.t('dashboard:subscribers.loading')}
|
||||
delayed
|
||||
/>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { DesktopPageTitle, ROUTES } from '@lumina/market/app/navigation';
|
||||
import {
|
||||
SubscriberList,
|
||||
SubscriberListSkeleton,
|
||||
} from '@lumina/market/app/screens/(main)/dashboard/subscribers/organisms/subscriber-list';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: i18n.t('dashboard:subscribers.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
|
||||
/**
|
||||
* «مشترکان» on desktop (J10-1f, J10-1g): the same list in the 640 column, «بازگشت» over its title
|
||||
* back to نمای کلی. The creator's own, in the browser only.
|
||||
*/
|
||||
export default function SubscribersPage() {
|
||||
const skeleton = (
|
||||
<SubscriberListSkeleton label={i18n.t('dashboard:subscribers.loading')} />
|
||||
);
|
||||
|
||||
return (
|
||||
<FlexBox tag="main" justifyContent="justify-center" className="px-8 py-10">
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
className="w-full max-w-content"
|
||||
>
|
||||
<DesktopPageTitle
|
||||
title={i18n.t('dashboard:subscribers.title')}
|
||||
parentHref={ROUTES.dashboard.overview}
|
||||
/>
|
||||
<PartBoundary
|
||||
name="subscriber-list"
|
||||
description={i18n.t('dashboard:subscribers.error')}
|
||||
framed
|
||||
>
|
||||
<AuthGuard role="creator" fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<SubscriberList />
|
||||
</Suspense>
|
||||
</AuthGuard>
|
||||
</PartBoundary>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { AudienceStatsSkeleton } from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/audience-stats';
|
||||
import { InviteCodeCardSkeleton } from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/invite-code-card';
|
||||
import { PricingCardSkeleton } from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/pricing-card';
|
||||
import { SubscribersPreviewSkeleton } from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/subscribers-preview';
|
||||
|
||||
import { i18n } from '../../../../../i18n';
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ export default function Loading() {
|
|||
label={i18n.t('dashboard:invite.loading')}
|
||||
delayed
|
||||
/>
|
||||
<AudienceStatsSkeleton
|
||||
label={i18n.t('dashboard:audience.loading')}
|
||||
<SubscribersPreviewSkeleton
|
||||
label={i18n.t('dashboard:subscribers.loading')}
|
||||
delayed
|
||||
/>
|
||||
</FlexBox>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import {
|
||||
AudienceStats,
|
||||
AudienceStatsSkeleton,
|
||||
} from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/audience-stats';
|
||||
import {
|
||||
InviteCodeCard,
|
||||
InviteCodeCardSkeleton,
|
||||
|
|
@ -13,6 +9,10 @@ import {
|
|||
PricingCard,
|
||||
PricingCardSkeleton,
|
||||
} from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/pricing-card';
|
||||
import {
|
||||
SubscribersPreview,
|
||||
SubscribersPreviewSkeleton,
|
||||
} from '@lumina/market/app/screens/(main)/dashboard/plans/organisms/subscribers-preview';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ export const metadata: Metadata = {
|
|||
};
|
||||
|
||||
/**
|
||||
* داشبورد › طرحهای اشتراک (J10-1): «قیمت طرحها», «کد دعوت» (only once approved) and «مخاطبان»,
|
||||
* داشبورد › طرحهای اشتراک (J10-1): «قیمت طرحها», «کد دعوت» (only once approved) and «مشترکان»,
|
||||
* the creator's own, in the browser only. Each block loads and fails on its own; the tabs stay.
|
||||
*/
|
||||
export default function PlansPage() {
|
||||
|
|
@ -41,8 +41,10 @@ export default function PlansPage() {
|
|||
label={i18n.t('dashboard:invite.loading')}
|
||||
/>
|
||||
);
|
||||
const audienceSkeleton = (
|
||||
<AudienceStatsSkeleton label={i18n.t('dashboard:audience.loading')} />
|
||||
const subscribersSkeleton = (
|
||||
<SubscribersPreviewSkeleton
|
||||
label={i18n.t('dashboard:subscribers.loading')}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
@ -52,7 +54,7 @@ export default function PlansPage() {
|
|||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
{pricingSkeleton}
|
||||
{inviteSkeleton}
|
||||
{audienceSkeleton}
|
||||
{subscribersSkeleton}
|
||||
</FlexBox>
|
||||
}
|
||||
>
|
||||
|
|
@ -79,12 +81,12 @@ export default function PlansPage() {
|
|||
</Suspense>
|
||||
</PartBoundary>
|
||||
<PartBoundary
|
||||
name="audience-stats"
|
||||
description={i18n.t('dashboard:audience.error')}
|
||||
name="subscribers-preview"
|
||||
description={i18n.t('dashboard:subscribers.error')}
|
||||
framed
|
||||
>
|
||||
<Suspense fallback={audienceSkeleton}>
|
||||
<AudienceStats />
|
||||
<Suspense fallback={subscribersSkeleton}>
|
||||
<SubscribersPreview />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</FlexBox>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
// Locked until a creator finishes registration step 5 (0016), as the tab is; the guard renders
|
||||
// the page as is.
|
||||
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { MobileTopBar, ROUTES } from '@lumina/market/app/navigation';
|
||||
import { SubscriberListSkeleton } from '@lumina/market/app/screens/(main)/dashboard/subscribers/organisms/subscriber-list';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
/** «مشترکان» before it arrives, under its real bar. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar
|
||||
title={i18n.t('dashboard:subscribers.title')}
|
||||
parentHref={ROUTES.dashboard.overview}
|
||||
backToPrevious
|
||||
/>
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1 p-4">
|
||||
<SubscriberListSkeleton
|
||||
label={i18n.t('dashboard:subscribers.loading')}
|
||||
delayed
|
||||
/>
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { PartBoundary } from '@lumina/market/app/error-boundaries';
|
||||
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
|
||||
import { MobileTopBar, ROUTES } from '@lumina/market/app/navigation';
|
||||
import {
|
||||
SubscriberList,
|
||||
SubscriberListSkeleton,
|
||||
} from '@lumina/market/app/screens/(main)/dashboard/subscribers/organisms/subscriber-list';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: i18n.t('dashboard:subscribers.meta-title'),
|
||||
robots: { index: false },
|
||||
};
|
||||
|
||||
/**
|
||||
* «مشترکان» on mobile (J10-1f, J10-1g): a page pushed from نمای کلی or طرحهای اشتراک, back ·
|
||||
* «مشترکان» · support, with the nav kept on داشبورد. The creator's own, in the browser only;
|
||||
* opened on its own, back goes to نمای کلی.
|
||||
*/
|
||||
export default function SubscribersPage() {
|
||||
const skeleton = (
|
||||
<SubscriberListSkeleton label={i18n.t('dashboard:subscribers.loading')} />
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<MobileTopBar
|
||||
title={i18n.t('dashboard:subscribers.title')}
|
||||
parentHref={ROUTES.dashboard.overview}
|
||||
backToPrevious
|
||||
/>
|
||||
<FlexBox tag="main" direction="flex-col" className="flex-1 p-4">
|
||||
<PartBoundary
|
||||
name="subscriber-list"
|
||||
description={i18n.t('dashboard:subscribers.error')}
|
||||
>
|
||||
<AuthGuard role="creator" fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<SubscriberList />
|
||||
</Suspense>
|
||||
</AuthGuard>
|
||||
</PartBoundary>
|
||||
</FlexBox>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
'use client';
|
||||
|
||||
import { Avatar } from '@lumina/island/atoms/avatar';
|
||||
import { StatusBadge } from '@lumina/island/atoms/status-badge';
|
||||
import { ListRow } from '@lumina/island/molecules/list-row';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { date, number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { subscriberDaysLeft } from '../../../../../../features/overview';
|
||||
import type { SubscriberRowProps } from './types';
|
||||
|
||||
/**
|
||||
* One subscriber: the @username, plan and end date, with how long is left in its last week. Only
|
||||
* the @username ever shows, never a phone or a name.
|
||||
*/
|
||||
export function SubscriberRow({ subscriber }: SubscriberRowProps) {
|
||||
const { t } = useTranslation(['dashboard', 'common']);
|
||||
const daysLeft = subscriberDaysLeft(subscriber.endsAt);
|
||||
const until = date(subscriber.endsAt, { time: false });
|
||||
|
||||
return (
|
||||
<ListRow
|
||||
leading={
|
||||
<Avatar name={subscriber.username ?? '?'} src={subscriber.avatarUrl} />
|
||||
}
|
||||
title={
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{subscriber.username ?? '—'}
|
||||
</Element>
|
||||
}
|
||||
subtitle={
|
||||
subscriber.tier
|
||||
? t('subscribers.until-plan', {
|
||||
plan: t(`common:billing-periods.${subscriber.tier}`),
|
||||
date: until,
|
||||
})
|
||||
: t('subscribers.until', { date: until })
|
||||
}
|
||||
end={
|
||||
daysLeft !== null && (
|
||||
<StatusBadge tone="warning" icon={null}>
|
||||
{t('subscribers.days-left', { n: number(daysLeft) })}
|
||||
</StatusBadge>
|
||||
)
|
||||
}
|
||||
chevron={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { SubscriberRow } from './SubscriberRow';
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import type { OwnSubscriberPayload } from '../../../../../../features/overview';
|
||||
|
||||
export type SubscriberRowProps = { subscriber: OwnSubscriberPayload };
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { StatTile } from '@lumina/island/molecules/stat-tile';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useId } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useAudiencePart } from '../../../../../../../features/overview';
|
||||
|
||||
/**
|
||||
* طرحهای اشتراک › «مخاطبان» (J10-1): two tiles, «دنبالکنندگان» and «مشترکان فعال», then who can
|
||||
* see which. Counts only, never a list of people. A section on the page, not a card.
|
||||
*/
|
||||
export function AudienceStats() {
|
||||
const { t } = useTranslation('dashboard');
|
||||
const model = useAudiencePart();
|
||||
const headingId = useId();
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag="section"
|
||||
aria-labelledby={headingId}
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
>
|
||||
<Typography tag="h2" id={headingId} variant="heading-sm">
|
||||
{t('audience.title')}
|
||||
</Typography>
|
||||
<GridBox cols="grid-cols-2" gap="gap-2">
|
||||
<StatTile
|
||||
label={t('audience.followers')}
|
||||
icon="users"
|
||||
value={number(model.followers)}
|
||||
/>
|
||||
<StatTile
|
||||
label={t('audience.subscribers')}
|
||||
icon="star"
|
||||
value={number(model.activeSubscribers)}
|
||||
/>
|
||||
</GridBox>
|
||||
<Typography variant="caption" color="secondary">
|
||||
{t('audience.note')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
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 { AudienceStatsSkeletonProps } from './types';
|
||||
|
||||
/** «مخاطبان» before it arrives: its title, the two tiles and the line under them. */
|
||||
export function AudienceStatsSkeleton({
|
||||
label,
|
||||
delayed,
|
||||
}: AudienceStatsSkeletonProps) {
|
||||
return (
|
||||
<SkeletonRegion label={label} delayed={delayed}>
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Skeleton width="25%" />
|
||||
<GridBox cols="grid-cols-2" gap="gap-2">
|
||||
{[0, 1].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>
|
||||
<Skeleton width="80%" />
|
||||
</FlexBox>
|
||||
</SkeletonRegion>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
export { AudienceStats } from './AudienceStats';
|
||||
export { AudienceStatsSkeleton } from './AudienceStatsSkeleton';
|
||||
export type { AudienceStatsSkeletonProps } from './types';
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
export type AudienceStatsSkeletonProps = {
|
||||
/** Hidden status text: «در حال بارگذاری مخاطبان…». */
|
||||
label: string;
|
||||
/** Fades in after 300ms, so a fast route never flashes grey. loading.tsx only. */
|
||||
delayed?: boolean;
|
||||
};
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { List } from '@lumina/island/molecules/list-row';
|
||||
import { SectionTitle } from '@lumina/island/molecules/section-title';
|
||||
import { useId } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useSubscribersPreviewPart } from '../../../../../../../features/overview';
|
||||
import { ROUTES } from '../../../../../../navigation/navigation';
|
||||
import { SubscriberRow } from '../../../organisms/subscriber-row';
|
||||
|
||||
/** طرحهای اشتراک › «مشترکان» (J10-1): the soonest-ending few, then the whole list a tap away. */
|
||||
export function SubscribersPreview() {
|
||||
const { t } = useTranslation('dashboard');
|
||||
const { total, items } = useSubscribersPreviewPart();
|
||||
const titleId = useId();
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag="section"
|
||||
aria-labelledby={titleId}
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
>
|
||||
<SectionTitle
|
||||
title={t('subscribers.title')}
|
||||
titleId={titleId}
|
||||
count={total}
|
||||
actionLabel={total > 0 ? t('subscribers.view-all') : undefined}
|
||||
actionHref={total > 0 ? ROUTES.dashboard.subscribers : undefined}
|
||||
/>
|
||||
{total > 0 ? (
|
||||
<>
|
||||
<List>
|
||||
{items.map((subscriber) => (
|
||||
<SubscriberRow
|
||||
key={`${subscriber.username}:${subscriber.endsAt}`}
|
||||
subscriber={subscriber}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
<Typography variant="caption" color="secondary">
|
||||
{t('subscribers.privacy-short')}
|
||||
</Typography>
|
||||
</>
|
||||
) : (
|
||||
<Typography variant="body-sm" color="secondary">
|
||||
{t('subscribers.empty.all')}
|
||||
</Typography>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import type { SubscribersPreviewSkeletonProps } from './types';
|
||||
|
||||
/** «مشترکان» before it arrives: its title over the rows. */
|
||||
export function SubscribersPreviewSkeleton({
|
||||
label,
|
||||
delayed,
|
||||
}: SubscribersPreviewSkeletonProps) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Skeleton width="25%" />
|
||||
<SkeletonPreset preset="list" count={3} label={label} delayed={delayed} />
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { SubscribersPreview } from './SubscribersPreview';
|
||||
export { SubscribersPreviewSkeleton } from './SubscribersPreviewSkeleton';
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
export type SubscribersPreviewSkeletonProps = {
|
||||
/** Hidden status text: «در حال بارگذاری مشترکان…». */
|
||||
label: string;
|
||||
/** Fades in after 300 ms, so a fast route never flashes it (`loading.tsx` only, G-3d). */
|
||||
delayed?: boolean;
|
||||
};
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { EmptyState } from '@lumina/island/molecules/empty-state';
|
||||
import { ErrorState } from '@lumina/island/molecules/error-state';
|
||||
import { FilterChips } from '@lumina/island/molecules/filter-chips';
|
||||
import { List } from '@lumina/island/molecules/list-row';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useSubscribersPage } from '../../../../../../../features/overview';
|
||||
import { SubscriberRow } from '../../../organisms/subscriber-row';
|
||||
|
||||
/**
|
||||
* «مشترکان» (J10-1f, J10-1g): «همه» · «در حال انقضا», soonest-ending first, «نمایش بیشتر» for the
|
||||
* next page. The rows stay while another chip's list loads; a failed page says so in its place.
|
||||
*/
|
||||
export function SubscriberList() {
|
||||
const { t } = useTranslation(['dashboard', 'errors']);
|
||||
const model = useSubscribersPage();
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-4" aria-busy={model.isFiltering}>
|
||||
<FilterChips
|
||||
label={t('subscribers.filter')}
|
||||
size="sm"
|
||||
options={[
|
||||
{
|
||||
value: 'all' as const,
|
||||
label: t('subscribers.filters.all', {
|
||||
n: number(model.counts.all),
|
||||
}),
|
||||
},
|
||||
{
|
||||
value: 'expiring' as const,
|
||||
label: t('subscribers.filters.expiring', {
|
||||
n: number(model.counts.expiring),
|
||||
}),
|
||||
},
|
||||
]}
|
||||
value={model.filter}
|
||||
onChange={model.setFilter}
|
||||
/>
|
||||
{model.items.length === 0 ? (
|
||||
<EmptyState
|
||||
tone="neutral"
|
||||
size="section"
|
||||
icon="users"
|
||||
title={t(`subscribers.empty.${model.filter}`)}
|
||||
/>
|
||||
) : (
|
||||
<List>
|
||||
{model.items.map((subscriber) => (
|
||||
<SubscriberRow
|
||||
key={`${subscriber.username}:${subscriber.endsAt}`}
|
||||
subscriber={subscriber}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
)}
|
||||
{model.loadMoreError ? (
|
||||
<ErrorState
|
||||
kind={model.loadMoreError}
|
||||
size="inline"
|
||||
title={t(`errors:fallback.${model.loadMoreError}.title`)}
|
||||
description={t('subscribers.more-failed')}
|
||||
onRetry={model.loadMore}
|
||||
retryLabel={t('errors:fallback.retry')}
|
||||
retryingLabel={t('errors:fallback.retrying')}
|
||||
retrying={model.isLoadingMore}
|
||||
/>
|
||||
) : (
|
||||
model.hasMore && (
|
||||
<Button
|
||||
variant="secondary"
|
||||
block
|
||||
onClick={model.loadMore}
|
||||
isLoading={model.isLoadingMore}
|
||||
>
|
||||
{t('subscribers.more')}
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
{model.filter === 'expiring' && (
|
||||
<Typography variant="caption" color="secondary">
|
||||
{t('subscribers.expiring-note')}
|
||||
</Typography>
|
||||
)}
|
||||
<Typography variant="caption" color="secondary">
|
||||
{t('subscribers.privacy')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import type { SubscriberListSkeletonProps } from './types';
|
||||
|
||||
/** «مشترکان» before it arrives: the chips' row, then the rows. */
|
||||
export function SubscriberListSkeleton({
|
||||
label,
|
||||
delayed,
|
||||
}: SubscriberListSkeletonProps) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-4">
|
||||
<FlexBox gap="gap-2" aria-hidden>
|
||||
<Skeleton shape="pill" width={88} height={36} />
|
||||
<Skeleton shape="pill" width={128} height={36} />
|
||||
</FlexBox>
|
||||
<SkeletonPreset preset="list" count={4} label={label} delayed={delayed} />
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { SubscriberList } from './SubscriberList';
|
||||
export { SubscriberListSkeleton } from './SubscriberListSkeleton';
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
export type SubscriberListSkeletonProps = {
|
||||
/** Hidden status text: «در حال بارگذاری مشترکان…». */
|
||||
label: string;
|
||||
/** Fades in after 300 ms, so a fast route never flashes it (`loading.tsx` only, G-3d). */
|
||||
delayed?: boolean;
|
||||
};
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
export { useAudiencePart } from './models/audience';
|
||||
export type { AudiencePartModel } from './models/audience';
|
||||
export {
|
||||
planBreakdownRows,
|
||||
useDashboardOverviewPart,
|
||||
|
|
@ -9,6 +7,15 @@ export type {
|
|||
PlanBreakdownMetric,
|
||||
PlanBreakdownRow,
|
||||
} from './models/dashboard-overview';
|
||||
export {
|
||||
subscriberDaysLeft,
|
||||
useSubscribersPage,
|
||||
useSubscribersPreviewPart,
|
||||
} from './models/subscribers';
|
||||
export type {
|
||||
SubscribersPageModel,
|
||||
SubscribersPreviewPartModel,
|
||||
} from './models/subscribers';
|
||||
export { useOwnSubscriberCount } from './models/own-subscriber-count';
|
||||
export type { UseOwnSubscriberCountOptions } from './models/own-subscriber-count';
|
||||
export {
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
export { useAudiencePart } from './use-audience-part';
|
||||
export type { AudiencePartModel } from './types';
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
/** طرحهای اشتراک › «مخاطبان» (J10-1): counts only, never a list of people. */
|
||||
export type AudiencePartModel = {
|
||||
/** «دنبالکنندگان»: public, the same figure the channel shows everyone. */
|
||||
followers: number;
|
||||
/** «مشترکان فعال»: subscriptions running now; only the creator sees it. */
|
||||
activeSubscribers: number;
|
||||
};
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
import { useSuspenseQueries } from '@tanstack/react-query';
|
||||
|
||||
import { useCurrentAccount } from '../../../../stores/auth';
|
||||
import { channelKeys, channelRepository } from '../../../channel';
|
||||
import {
|
||||
creatorDashboardRepository,
|
||||
overviewKeys,
|
||||
} from '../../repositories/creator-dashboard';
|
||||
import type { AudiencePartModel } from './types';
|
||||
|
||||
/**
|
||||
* طرحهای اشتراک › «مخاطبان» (J10-1): how many follow the creator (the channel's public count, so
|
||||
* a follow anywhere moves it) and how many subscriptions run now (from the creator's dashboard
|
||||
* figures). Counts only: the design shows no list of people. Read in the browser for the signed-in
|
||||
* creator; either read failing fails the part.
|
||||
*/
|
||||
export function useAudiencePart(): AudiencePartModel {
|
||||
const creatorId = useCurrentAccount()?.id ?? '';
|
||||
const [followers, dashboard] = useSuspenseQueries({
|
||||
queries: [
|
||||
{
|
||||
queryKey: channelKeys.followerCount(creatorId),
|
||||
queryFn: ({ signal }: { signal: AbortSignal }) =>
|
||||
channelRepository.getFollowerCount({ creatorId }, { signal }),
|
||||
},
|
||||
{
|
||||
queryKey: overviewKeys.dashboard(),
|
||||
queryFn: ({ signal }: { signal: AbortSignal }) =>
|
||||
creatorDashboardRepository.get({ signal }),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return {
|
||||
followers: followers.data,
|
||||
activeSubscribers: dashboard.data.activeSubscribers,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
/** The filter's place in the URL, so back and a reload keep it, and نمای کلی can link to it. */
|
||||
export const SUBSCRIBERS_FILTER_PARAM = 'filter';
|
||||
|
||||
/** Rows طرحهای اشتراک shows before «مشاهده همه» (J10-1). */
|
||||
export const SUBSCRIBERS_PREVIEW_COUNT = 3;
|
||||
|
||||
/** From here a row says how long it has left, as «در حال انقضا» counts them. */
|
||||
export const SUBSCRIBER_EXPIRING_DAYS = 7;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
export { subscriberDaysLeft } from './subscriber-days';
|
||||
export { useSubscribersPage } from './use-subscribers-page';
|
||||
export { useSubscribersPreviewPart } from './use-subscribers-preview-part';
|
||||
export type {
|
||||
SubscribersPageModel,
|
||||
SubscribersPreviewPartModel,
|
||||
} from './types';
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { subscriberDaysLeft } from './subscriber-days';
|
||||
|
||||
const now = Date.parse('2026-11-05T12:00:00Z');
|
||||
const inDays = (days: number) => new Date(now + days * 86400000).toISOString();
|
||||
|
||||
describe('subscriberDaysLeft', () => {
|
||||
it('counts a started day', () => {
|
||||
expect(subscriberDaysLeft(inDays(3.5), now)).toBe(4);
|
||||
});
|
||||
|
||||
it('stays quiet beyond a week', () => {
|
||||
expect(subscriberDaysLeft(inDays(7), now)).toBe(7);
|
||||
expect(subscriberDaysLeft(inDays(7.5), now)).toBeNull();
|
||||
});
|
||||
|
||||
it('never says less than a day', () => {
|
||||
expect(subscriberDaysLeft(inDays(0.1), now)).toBe(1);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import { SUBSCRIBER_EXPIRING_DAYS } from './constants';
|
||||
|
||||
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
/** Whole days left, a started day counted, for a subscription ending soon; `null` otherwise. */
|
||||
export function subscriberDaysLeft(
|
||||
endsAt: string,
|
||||
now = Date.now(),
|
||||
): number | null {
|
||||
const days = Math.ceil((new Date(endsAt).getTime() - now) / DAY_MS);
|
||||
return days > SUBSCRIBER_EXPIRING_DAYS ? null : Math.max(days, 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import type { LoadMoreErrorKind } from '../../../../shared/utils';
|
||||
import type {
|
||||
OwnSubscriberPayload,
|
||||
OwnSubscribersFilter,
|
||||
} from '../../repositories/creator-dashboard';
|
||||
|
||||
export type SubscribersPageModel = {
|
||||
filter: OwnSubscribersFilter;
|
||||
setFilter: (filter: OwnSubscribersFilter) => void;
|
||||
isFiltering: boolean;
|
||||
counts: Record<OwnSubscribersFilter, number>;
|
||||
items: OwnSubscriberPayload[];
|
||||
hasMore: boolean;
|
||||
loadMore: () => void;
|
||||
isLoadingMore: boolean;
|
||||
/** The next page failed: which message says so in place of «more». */
|
||||
loadMoreError: LoadMoreErrorKind | null;
|
||||
};
|
||||
|
||||
export type SubscribersPreviewPartModel = {
|
||||
/** Who subscribes now, in all. */
|
||||
total: number;
|
||||
/** The soonest-ending few. */
|
||||
items: OwnSubscriberPayload[];
|
||||
};
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useTransition } from 'react';
|
||||
|
||||
import { firstOfEach, loadMoreErrorKind } from '../../../../shared/utils';
|
||||
import {
|
||||
creatorDashboardRepository,
|
||||
overviewKeys,
|
||||
} from '../../repositories/creator-dashboard';
|
||||
import { SUBSCRIBERS_FILTER_PARAM } from './constants';
|
||||
import type { SubscribersPageModel } from './types';
|
||||
|
||||
/**
|
||||
* «مشترکان» (J10-1f, J10-1g): «همه» · «در حال انقضا» with the API's totals, the chip in the URL so
|
||||
* back and a reload keep it, soonest-ending first, 20 a page by cursor.
|
||||
*/
|
||||
export function useSubscribersPage(): SubscribersPageModel {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const [isFiltering, startFiltering] = useTransition();
|
||||
const filter =
|
||||
searchParams.get(SUBSCRIBERS_FILTER_PARAM) === 'expiring'
|
||||
? 'expiring'
|
||||
: 'all';
|
||||
|
||||
const list = useSuspenseInfiniteQuery({
|
||||
queryKey: overviewKeys.subscribers(filter),
|
||||
queryFn: ({ pageParam, signal }) =>
|
||||
creatorDashboardRepository.listSubscribers(
|
||||
{ filter, cursor: pageParam },
|
||||
{ signal },
|
||||
),
|
||||
initialPageParam: undefined as string | undefined,
|
||||
getNextPageParam: (last) => last.nextCursor ?? undefined,
|
||||
});
|
||||
|
||||
return {
|
||||
filter,
|
||||
setFilter: (next) => {
|
||||
if (next === filter) return;
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
if (next === 'all') params.delete(SUBSCRIBERS_FILTER_PARAM);
|
||||
else params.set(SUBSCRIBERS_FILTER_PARAM, next);
|
||||
const query = params.toString();
|
||||
// In place: the page keeps its scroll, and the chip replaces the entry.
|
||||
startFiltering(() => {
|
||||
router.replace(query ? `${pathname}?${query}` : pathname, {
|
||||
scroll: false,
|
||||
});
|
||||
});
|
||||
},
|
||||
isFiltering,
|
||||
counts: list.data.pages[0].counts,
|
||||
items: firstOfEach(
|
||||
list.data.pages.flatMap((page) => page.items),
|
||||
(item) => `${item.username}:${item.endsAt}`,
|
||||
),
|
||||
hasMore: list.hasNextPage,
|
||||
loadMore: () => {
|
||||
// fetchNextPage would cancel a read of every page on its way and skip or repeat rows.
|
||||
if (!list.isFetching) void list.fetchNextPage();
|
||||
},
|
||||
isLoadingMore: list.isFetchingNextPage,
|
||||
loadMoreError: list.isFetchNextPageError
|
||||
? loadMoreErrorKind(list.error)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { useSuspenseQuery } from '@tanstack/react-query';
|
||||
|
||||
import {
|
||||
creatorDashboardRepository,
|
||||
overviewKeys,
|
||||
} from '../../repositories/creator-dashboard';
|
||||
import { SUBSCRIBERS_PREVIEW_COUNT } from './constants';
|
||||
import type { SubscribersPreviewPartModel } from './types';
|
||||
|
||||
/** طرحهای اشتراک › «مشترکان» (J10-1): how many, and the few who end soonest. */
|
||||
export function useSubscribersPreviewPart(): SubscribersPreviewPartModel {
|
||||
const { data } = useSuspenseQuery({
|
||||
queryKey: [...overviewKeys.subscribers('all'), 'preview'],
|
||||
queryFn: ({ signal }) =>
|
||||
creatorDashboardRepository.listSubscribers({ filter: 'all' }, { signal }),
|
||||
});
|
||||
return {
|
||||
total: data.counts.all,
|
||||
items: data.items.slice(0, SUBSCRIBERS_PREVIEW_COUNT),
|
||||
};
|
||||
}
|
||||
|
|
@ -343,11 +343,9 @@ export type {
|
|||
export {
|
||||
creatorDashboardRepository,
|
||||
overviewKeys,
|
||||
useAudiencePart,
|
||||
useOwnSubscriberCount,
|
||||
} from './features/overview';
|
||||
export type {
|
||||
AudiencePartModel,
|
||||
CreatorDashboardPayload,
|
||||
CreatorTierPayload,
|
||||
RecentPaymentPayload,
|
||||
|
|
|
|||
|
|
@ -146,14 +146,6 @@
|
|||
"finance": {
|
||||
"meta-title": "مالی"
|
||||
},
|
||||
"audience": {
|
||||
"title": "مخاطبان",
|
||||
"followers": "دنبالکنندگان",
|
||||
"subscribers": "مشترکان فعال",
|
||||
"note": "تعداد دنبالکنندگان برای همه دیده میشود؛ تعداد مشترکان فقط برای شما.",
|
||||
"loading": "در حال بارگذاری مخاطبان…",
|
||||
"error": "آمار مخاطبان بارگذاری نشد. دوباره تلاش کنید."
|
||||
},
|
||||
"invite": {
|
||||
"title": "کد دعوت",
|
||||
"loading": "در حال بارگذاری کد دعوت…",
|
||||
|
|
@ -269,5 +261,29 @@
|
|||
"text": "لینک کانال را در تلگرام، اینستاگرام یا هر جای دیگری که مخاطب دارید بگذارید. هر دنبالکننده و مشترک تازه اینجا شمرده میشود.",
|
||||
"action": "اشتراکگذاری لینک کانال"
|
||||
}
|
||||
},
|
||||
"subscribers": {
|
||||
"meta-title": "مشترکان",
|
||||
"title": "مشترکان",
|
||||
"view-all": "مشاهده همه",
|
||||
"loading": "در حال بارگذاری مشترکان…",
|
||||
"error": "مشترکان بارگذاری نشدند. دوباره تلاش کنید.",
|
||||
"filter": "فیلتر مشترکان",
|
||||
"filters": {
|
||||
"all": "همه ({{n}})",
|
||||
"expiring": "در حال انقضا ({{n}})"
|
||||
},
|
||||
"until-plan": "{{plan}} · تا {{date}}",
|
||||
"until": "تا {{date}}",
|
||||
"days-left": "{{n}} روز مانده",
|
||||
"expiring-note": "مشترکانی که اشتراکشان در 7 روز آینده تمام میشود.",
|
||||
"privacy-short": "فقط نام کاربری مشترکان نمایش داده میشود.",
|
||||
"privacy": "فقط نام کاربری مشترکان نمایش داده میشود؛ شماره موبایل و نام آنها هرگز.",
|
||||
"empty": {
|
||||
"all": "هنوز مشترکی ندارید.",
|
||||
"expiring": "در 7 روز آینده اشتراکی تمام نمیشود."
|
||||
},
|
||||
"more": "نمایش مشترکان بیشتر",
|
||||
"more-failed": "مشترکان بیشتر بارگذاری نشدند."
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue