feat(admin): wall-street-plaza admin panel on garden-roof, bound to admin-api
- New admin app apps/wall-street-plaza (port 7002) and platform platforms/garden-roof (scope:admin), talking only to admin-api through the /api rewrite (decision 0061; 0062 and 0063 proposed). - All J11 sections: beta health, verifications, analysts, invite codes, subscriptions, predictions, payouts, featured; audit log, cross-section refresh, Persian-only errors. - Admin login matches the uniform admin-api contract (one OTP_INVALID message, 429 wait, local code check); reason hints say who reads each reason. - island: DataTable, Pager, PersonSummary, TabLinks count, StatTile footer; tools: exactDuration; market: subscription_extended/refunded notification icons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6319052cc1
commit
8c300edf68
|
|
@ -0,0 +1,11 @@
|
|||
# Copy to .env.local. Public variables are inlined into the browser bundle: never put a secret in one.
|
||||
NEXT_PUBLIC_SITE_URL=http://localhost:7002
|
||||
|
||||
# Server only: the admin API's origin from inside the deployment network (0061). The browser's
|
||||
# /api proxy goes there (next.config rewrite, fixed at build time). The admin app never calls the
|
||||
# public gateway.
|
||||
ADMIN_API_INTERNAL_ORIGIN=http://localhost:9010
|
||||
|
||||
# Only for steps that run without the real env (lint, type-check). A build still needs
|
||||
# ADMIN_API_INTERNAL_ORIGIN: the /api rewrite keeps the value it was built with.
|
||||
SKIP_ENV_VALIDATION=false
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"jsc": {
|
||||
"target": "es2017",
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true,
|
||||
"dynamicImport": true
|
||||
},
|
||||
"transform": {
|
||||
"decoratorMetadata": true,
|
||||
"legacyDecorator": true
|
||||
},
|
||||
"keepClassNames": true,
|
||||
"externalHelpers": true,
|
||||
"loose": true
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
},
|
||||
"sourceMaps": true,
|
||||
"exclude": [
|
||||
"jest.config.[ct]s",
|
||||
".*\\.spec.tsx?$",
|
||||
".*\\.test.tsx?$",
|
||||
"./src/jest-setup.ts$",
|
||||
"./**/jest-setup.ts$",
|
||||
".*.js$",
|
||||
".*.d.ts$"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<!-- BEGIN:nextjs-agent-rules -->
|
||||
|
||||
# This is NOT the Next.js you know
|
||||
|
||||
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.
|
||||
|
||||
This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
|
||||
|
||||
<!-- END:nextjs-agent-rules -->
|
||||
|
|
@ -0,0 +1 @@
|
|||
@AGENTS.md
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import baseConfig from '../../eslint.config.mjs';
|
||||
|
||||
export default baseConfig;
|
||||
|
|
@ -0,0 +1 @@
|
|||
/// <reference types="@nx/next/typings/style.d.ts" />
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
import { withFontCopy } from '@lumina/island/tools/font-copy-plugin';
|
||||
import { withIconSprite } from '@lumina/island/tools/icon-sprite-plugin';
|
||||
import type { NextConfig } from 'next';
|
||||
|
||||
import {
|
||||
API_PROXY_MAX_BODY,
|
||||
API_PROXY_PATH,
|
||||
API_PROXY_TIMEOUT_MS,
|
||||
} from './src/constants';
|
||||
import { adminApiInternalUrl } from './src/env/env.config';
|
||||
|
||||
// Fonts and the icon sprite keep fixed names (0011, 0012); Next serves public/ with max-age=0.
|
||||
const immutable = [
|
||||
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
|
||||
];
|
||||
|
||||
// The panel is never framed, never indexed, and never sends full URLs to other sites.
|
||||
const security = [
|
||||
{ key: 'Content-Security-Policy', value: "frame-ancestors 'none'" },
|
||||
{ key: 'X-Frame-Options', value: 'DENY' },
|
||||
{ key: 'X-Content-Type-Options', value: 'nosniff' },
|
||||
{ key: 'Referrer-Policy', value: 'same-origin' },
|
||||
{ key: 'X-Robots-Tag', value: 'noindex, nofollow' },
|
||||
];
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
// Metadata always in <head> (0054).
|
||||
htmlLimitedBots: /.*/,
|
||||
experimental: {
|
||||
proxyTimeout: API_PROXY_TIMEOUT_MS,
|
||||
proxyClientMaxBodySize: API_PROXY_MAX_BODY,
|
||||
},
|
||||
// Workspace packages export TypeScript source, so Next.js compiles them.
|
||||
transpilePackages: [
|
||||
'@lumina/garden-roof',
|
||||
'@lumina/integrations',
|
||||
'@lumina/island',
|
||||
'@lumina/libs',
|
||||
'@lumina/tools',
|
||||
],
|
||||
// The browser calls the admin API on this site's origin (`/api/v1/admin/…`), proxied to
|
||||
// admin-api, so there is no CORS and the session cookies are this site's (0061). No service
|
||||
// worker or manifest: the panel isn't installable (0062).
|
||||
async rewrites() {
|
||||
return [
|
||||
{
|
||||
source: `${API_PROXY_PATH}/:path*`,
|
||||
destination: `${adminApiInternalUrl()}/:path*`,
|
||||
},
|
||||
];
|
||||
},
|
||||
async headers() {
|
||||
return [
|
||||
{ source: '/:path*', headers: security },
|
||||
{ source: '/fonts/:path*', headers: immutable },
|
||||
{ source: '/icons/:path*', headers: immutable },
|
||||
];
|
||||
},
|
||||
async redirects() {
|
||||
return [{ source: '/', destination: '/health', permanent: false }];
|
||||
},
|
||||
};
|
||||
|
||||
// On next dev and next build, island's plugins write the fonts and icon sprite into public/
|
||||
// under their fixed names, with no hash (0012).
|
||||
export default withIconSprite(withFontCopy(nextConfig));
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"name": "@lumina/wall-street-plaza",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"nx": {
|
||||
"name": "wall-street-plaza",
|
||||
"sourceRoot": "apps/wall-street-plaza/src",
|
||||
"tags": [
|
||||
"type:app",
|
||||
"scope:admin"
|
||||
],
|
||||
"targets": {
|
||||
"build": {
|
||||
"outputs": [
|
||||
"{projectRoot}/.next/!(cache)/**/*",
|
||||
"{projectRoot}/.next/!(cache)",
|
||||
"{projectRoot}/public/icons",
|
||||
"{projectRoot}/public/fonts"
|
||||
]
|
||||
},
|
||||
"dev": {
|
||||
"options": {
|
||||
"command": "next dev --port 7002"
|
||||
}
|
||||
},
|
||||
"start": {
|
||||
"options": {
|
||||
"command": "next start --port 7002"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@lumina/garden-roof": "workspace:*",
|
||||
"@lumina/integrations": "workspace:*",
|
||||
"@lumina/island": "workspace:*",
|
||||
"@lumina/libs": "workspace:*",
|
||||
"@lumina/tools": "workspace:*",
|
||||
"next": "~16.3.8",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
export default {
|
||||
plugins: {
|
||||
'@tailwindcss/postcss': {},
|
||||
},
|
||||
};
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -0,0 +1,24 @@
|
|||
'use client';
|
||||
|
||||
import { ErrorFallback } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
|
||||
type GroupErrorProps = {
|
||||
error: Error & { digest?: string };
|
||||
retry: () => void;
|
||||
};
|
||||
|
||||
/** A failed login page: the state in the form column. */
|
||||
export default function GroupError({ error, retry }: GroupErrorProps) {
|
||||
return (
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
className="min-h-dvh bg-bg-page px-4 py-10"
|
||||
>
|
||||
<FlexBox direction="flex-col" className="w-full max-w-form">
|
||||
<ErrorFallback error={error} size="page" name="login" onRetry={retry} />
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
// Every request renders fresh: nothing in this group is prerendered or cached on the server.
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
/** Adds nothing to the page; it holds the group's rendering mode. */
|
||||
export default function AuthLayout({ children }: { children: ReactNode }) {
|
||||
return children;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
|
||||
/** The login frame before it arrives: the card in the form column. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
alignItems="items-center"
|
||||
className="min-h-dvh bg-bg-page px-4 py-10"
|
||||
>
|
||||
<Card padding="lg" className="w-full max-w-form">
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
label={i18n.t('auth:login.title')}
|
||||
delayed
|
||||
/>
|
||||
</Card>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
import { GuestGuard } from '@lumina/garden-roof/app/guards';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import { LoginTemplate } from './templates/login-template';
|
||||
|
||||
export const metadata: Metadata = { title: i18n.t('auth:login.title') };
|
||||
|
||||
/**
|
||||
* ورود به پنل ادمین: the brand over the sign-in card in the form column. The form renders only in
|
||||
* the browser, once the viewer is known to be a guest (0062, as 0013).
|
||||
*/
|
||||
export default function LoginPage() {
|
||||
const skeleton = (
|
||||
<SkeletonPreset
|
||||
preset="form"
|
||||
count={1}
|
||||
label={i18n.t('auth:login.title')}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag="main"
|
||||
justifyContent="justify-center"
|
||||
alignItems="items-center"
|
||||
className="min-h-dvh bg-bg-page px-4 py-10"
|
||||
>
|
||||
<FlexBox direction="flex-col" gap="gap-6" className="w-full max-w-form">
|
||||
<FlexBox
|
||||
alignItems="items-baseline"
|
||||
gap="gap-2"
|
||||
justifyContent="justify-center"
|
||||
>
|
||||
<Typography
|
||||
tag="p"
|
||||
variant="heading-md"
|
||||
className="m-0 font-bold text-action-primary-text"
|
||||
>
|
||||
{i18n.t('app.brand')}
|
||||
</Typography>
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
{i18n.t('app.panel')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
<Card padding="lg">
|
||||
<GuestGuard fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<LoginTemplate />
|
||||
</Suspense>
|
||||
</GuestGuard>
|
||||
</Card>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
'use client';
|
||||
|
||||
import { useLoginPage } from '@lumina/garden-roof/features/auth';
|
||||
import {
|
||||
RETURN_TO_PARAM,
|
||||
safeReturnPath,
|
||||
} from '@lumina/garden-roof/app/navigation';
|
||||
import {
|
||||
formatMobile,
|
||||
translateMessage,
|
||||
} from '@lumina/garden-roof/shared/utils';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { OtpInput } from '@lumina/island/molecules/otp-input';
|
||||
import { TextInput } from '@lumina/island/molecules/text-input';
|
||||
import { clock } from '@lumina/tools/format';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
/** Seconds left until `endsAt`, ticking once a second. */
|
||||
function useSecondsLeft(endsAt: number | null): number {
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
useEffect(() => {
|
||||
if (endsAt === null) return;
|
||||
const timer = window.setInterval(() => setNow(Date.now()), 1000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [endsAt]);
|
||||
return endsAt === null ? 0 : Math.max(0, Math.ceil((endsAt - now) / 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* The admin's sign-in (0061): the number, then the code, in one card. A signed-in admin goes on
|
||||
* to the page they came for.
|
||||
*/
|
||||
export function LoginTemplate() {
|
||||
const { t } = useTranslation('auth');
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const model = useLoginPage({
|
||||
onSignedIn: () =>
|
||||
router.replace(safeReturnPath(searchParams.get(RETURN_TO_PARAM))),
|
||||
});
|
||||
const secondsLeft = useSecondsLeft(model.resendEndsAt);
|
||||
const { errors } = model.phoneForm.formState;
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6">
|
||||
<FlexBox direction="flex-col" gap="gap-1">
|
||||
<Typography tag="h1" variant="heading-md" className="m-0">
|
||||
{model.step === 'phone' ? t('login.title') : t('login.code-title')}
|
||||
</Typography>
|
||||
<Typography variant="body-sm" color="secondary" className="m-0">
|
||||
{model.step === 'phone'
|
||||
? t('login.subtitle')
|
||||
: t('login.code-subtitle', { phone: formatMobile(model.phone) })}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
{model.step === 'phone' ? (
|
||||
<FlexBox
|
||||
tag="form"
|
||||
noValidate
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
model.submitPhone();
|
||||
}}
|
||||
>
|
||||
<TextInput
|
||||
{...model.phoneForm.register('phone')}
|
||||
label={t('login.phone-label')}
|
||||
placeholder={t('login.phone-placeholder')}
|
||||
inputMode="tel"
|
||||
autoComplete="tel"
|
||||
dir="ltr"
|
||||
// The page holds only this form, so focus starts in its one field.
|
||||
// oxlint-disable-next-line jsx-a11y/no-autofocus
|
||||
autoFocus
|
||||
error={translateMessage(t, errors.phone?.message)}
|
||||
/>
|
||||
<Button type="submit" block isLoading={model.isSending}>
|
||||
{t('login.send')}
|
||||
</Button>
|
||||
</FlexBox>
|
||||
) : (
|
||||
<FlexBox direction="flex-col" gap="gap-4">
|
||||
<OtpInput
|
||||
// A refused code remounts the cells, so focus (dropped while they were disabled for the
|
||||
// check) comes back for the retry.
|
||||
key={model.attempt}
|
||||
label={t('login.code-label')}
|
||||
value={model.code}
|
||||
onChange={model.setCode}
|
||||
onComplete={model.submitCode}
|
||||
status={model.isVerifying ? 'verifying' : 'idle'}
|
||||
error={model.codeError ?? undefined}
|
||||
// The code step replaced the number step, or a code was refused: focus goes to the cells.
|
||||
// oxlint-disable-next-line jsx-a11y/no-autofocus
|
||||
autoFocus
|
||||
webOtp={false}
|
||||
/>
|
||||
<Button
|
||||
block
|
||||
isLoading={model.isVerifying}
|
||||
onClick={() => model.submitCode(model.code)}
|
||||
>
|
||||
{t('login.verify')}
|
||||
</Button>
|
||||
<FlexBox justifyContent="justify-between" alignItems="items-center">
|
||||
<Button variant="ghost" size="sm" onClick={model.editPhone}>
|
||||
{t('login.edit-phone')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
frozen={secondsLeft > 0}
|
||||
isLoading={model.isResending}
|
||||
onClick={model.resend}
|
||||
>
|
||||
{secondsLeft > 0
|
||||
? t('login.resend-in', { time: clock(secondsLeft) })
|
||||
: t('login.resend')}
|
||||
</Button>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { LoginTemplate } from './LoginTemplate';
|
||||
export type { LoginTemplateProps } from './types';
|
||||
|
|
@ -0,0 +1 @@
|
|||
export type LoginTemplateProps = Record<string, never>;
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { i18n } from '../../../../i18n';
|
||||
import { DetailSkeleton } from './organisms/analyst-detail';
|
||||
|
||||
/** The analyst before they arrive: the way back over the skeleton. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<DetailSkeleton
|
||||
label={i18n.t('analysts:detail.loading')}
|
||||
title={i18n.t('analysts:detail.title')}
|
||||
backLabel={i18n.t('analysts:detail.back')}
|
||||
delayed
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
'use client';
|
||||
|
||||
import { ROUTES } from '@lumina/garden-roof/app/navigation';
|
||||
import { AuditLog } from '@lumina/garden-roof/app/screens';
|
||||
import { useAnalystDetailPage } from '@lumina/garden-roof/features/analysts';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import {
|
||||
AccountActionButton,
|
||||
AccountDialogs,
|
||||
} from '../../../organisms/account-dialogs';
|
||||
import { AccountBadges } from './components/AccountBadges';
|
||||
import { AnalystFacts } from './components/AnalystFacts';
|
||||
import type { AnalystDetailProps } from './types';
|
||||
|
||||
/**
|
||||
* One analyst (J11-4b): the name over @username with both states and the one account action in
|
||||
* the header, the facts in the 432px column and «گزارش ممیزی» beside them. On a phone the states
|
||||
* and the action sit under the title, full width. A suspension or reinstatement updates the page
|
||||
* in place (J11-5d, J11-5f).
|
||||
*/
|
||||
export function AnalystDetail({ id }: AnalystDetailProps) {
|
||||
const { t } = useTranslation('analysts');
|
||||
const { analyst, account } = useAnalystDetailPage(id);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={analyst.fullName}
|
||||
subtitle={
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{analyst.username}
|
||||
</Element>
|
||||
}
|
||||
backHref={ROUTES.analysts}
|
||||
backLabel={t('detail.back')}
|
||||
actions={
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-2"
|
||||
className="hidden desktop:flex"
|
||||
>
|
||||
<AccountBadges analyst={analyst} />
|
||||
<AccountActionButton
|
||||
target={analyst}
|
||||
account={account}
|
||||
size="md"
|
||||
withIcon
|
||||
/>
|
||||
</FlexBox>
|
||||
}
|
||||
/>
|
||||
<FlexBox direction="flex-col" gap="gap-3" className="desktop:hidden">
|
||||
<FlexBox gap="gap-2" wrap="flex-wrap">
|
||||
<AccountBadges analyst={analyst} />
|
||||
</FlexBox>
|
||||
<AccountActionButton
|
||||
target={analyst}
|
||||
account={account}
|
||||
size="md"
|
||||
withIcon
|
||||
block
|
||||
/>
|
||||
</FlexBox>
|
||||
<GridBox
|
||||
gap="gap-6"
|
||||
alignItems="items-start"
|
||||
className="desktop:grid-cols-[27rem_minmax(0,1fr)]"
|
||||
>
|
||||
<AnalystFacts analyst={analyst} />
|
||||
<AuditLog entries={analyst.audit} />
|
||||
</GridBox>
|
||||
<AccountDialogs account={account} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
'use client';
|
||||
|
||||
import { StatusBadge } from '@lumina/island/atoms/status-badge';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { AccountBadgesProps } from '../types';
|
||||
|
||||
/** Verification and account side by side: independent states (J11-4). */
|
||||
export function AccountBadges({ analyst }: AccountBadgesProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
<StatusBadge status={`verification.${analyst.verificationStatus}`}>
|
||||
{t(`status.verification.${analyst.verificationStatus}`)}
|
||||
</StatusBadge>
|
||||
<StatusBadge status={`account.${analyst.accountStatus}`}>
|
||||
{t(`status.account.${analyst.accountStatus}`)}
|
||||
</StatusBadge>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
'use client';
|
||||
|
||||
import { formatMobile } from '@lumina/garden-roof/shared/utils';
|
||||
import { StatusBadge } from '@lumina/island/atoms/status-badge';
|
||||
import { DetailRow } from '@lumina/island/molecules/detail-row';
|
||||
import { KeyValue } from '@lumina/island/molecules/key-value';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { AnalystFactsProps } from '../types';
|
||||
|
||||
/** Who the analyst is, both of their states and how many subscribe now (J11-4b). */
|
||||
export function AnalystFacts({ analyst }: AnalystFactsProps) {
|
||||
const { t } = useTranslation(['analysts', 'common']);
|
||||
|
||||
return (
|
||||
<KeyValue tone="card">
|
||||
<DetailRow label={t('detail.fields.name')} strong>
|
||||
{analyst.fullName}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('detail.fields.username')} ltr>
|
||||
@{analyst.username}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('detail.fields.phone')} ltr>
|
||||
{analyst.phone ? formatMobile(analyst.phone) : '—'}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('detail.fields.verification')}>
|
||||
<StatusBadge status={`verification.${analyst.verificationStatus}`}>
|
||||
{t(`common:status.verification.${analyst.verificationStatus}`)}
|
||||
</StatusBadge>
|
||||
</DetailRow>
|
||||
<DetailRow label={t('detail.fields.account')}>
|
||||
<StatusBadge status={`account.${analyst.accountStatus}`}>
|
||||
{t(`common:status.account.${analyst.accountStatus}`)}
|
||||
</StatusBadge>
|
||||
</DetailRow>
|
||||
<DetailRow label={t('detail.fields.subscribers')} strong>
|
||||
{number(analyst.activeSubscriptions)}
|
||||
</DetailRow>
|
||||
</KeyValue>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { ROUTES } from '@lumina/garden-roof/app/navigation';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { Skeleton, SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
||||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
|
||||
import type { DetailSkeletonProps } from '../types';
|
||||
|
||||
/** The analyst before they arrive: the way back, then the facts card and the audit card. */
|
||||
export function DetailSkeleton({
|
||||
label,
|
||||
title,
|
||||
backLabel,
|
||||
delayed,
|
||||
}: DetailSkeletonProps) {
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={title}
|
||||
backHref={ROUTES.analysts}
|
||||
backLabel={backLabel}
|
||||
/>
|
||||
<SkeletonRegion label={label} delayed={delayed}>
|
||||
<GridBox
|
||||
gap="gap-6"
|
||||
className="desktop:grid-cols-[27rem_minmax(0,1fr)]"
|
||||
>
|
||||
<Skeleton className="h-80 rounded-lg" />
|
||||
<Skeleton className="h-64 rounded-lg" />
|
||||
</GridBox>
|
||||
</SkeletonRegion>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export { AnalystDetail } from './AnalystDetail';
|
||||
export { DetailSkeleton } from './components/DetailSkeleton';
|
||||
export type { AnalystDetailProps } from './types';
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import type { AnalystDetailPayload } from '@lumina/garden-roof/features/analysts';
|
||||
|
||||
export type AnalystDetailProps = { id: string };
|
||||
|
||||
export type AnalystFactsProps = { analyst: AnalystDetailPayload };
|
||||
|
||||
export type AccountBadgesProps = { analyst: AnalystDetailPayload };
|
||||
|
||||
export type DetailSkeletonProps = {
|
||||
label: string;
|
||||
/** The page's title until the analyst's name arrives. */
|
||||
title: string;
|
||||
backLabel: string;
|
||||
delayed?: boolean;
|
||||
};
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { AdminGuard } from '@lumina/garden-roof/app/guards';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import { AnalystDetail, DetailSkeleton } from './organisms/analyst-detail';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: i18n.t('analysts:detail.meta-title'),
|
||||
};
|
||||
|
||||
type AnalystPageProps = { params: Promise<{ id: string }> };
|
||||
|
||||
/**
|
||||
* One analyst (J11-4b): the header carries the analyst's name, so the whole page renders in the
|
||||
* browser once the admin is known (0062); until then, its way back over the skeleton.
|
||||
*/
|
||||
export default async function AnalystPage({ params }: AnalystPageProps) {
|
||||
const { id } = await params;
|
||||
const skeleton = (
|
||||
<DetailSkeleton
|
||||
label={i18n.t('analysts:detail.loading')}
|
||||
title={i18n.t('analysts:detail.title')}
|
||||
backLabel={i18n.t('analysts:detail.back')}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<AdminGuard fallback={skeleton}>
|
||||
<PartBoundary
|
||||
name="analyst-detail"
|
||||
description={i18n.t('analysts:detail.error')}
|
||||
>
|
||||
<Suspense fallback={skeleton}>
|
||||
<AnalystDetail id={id} />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</AdminGuard>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import { ListSkeleton } from './organisms/analysts-list';
|
||||
|
||||
/** The list before it arrives: its title over the table skeleton. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={i18n.t('analysts:list.title')} />
|
||||
<ListSkeleton label={i18n.t('analysts:list.loading')} delayed />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
'use client';
|
||||
|
||||
import { ReasonDialog } from '@lumina/garden-roof/app/screens';
|
||||
import { SUSPEND_TEMPLATES } from '@lumina/garden-roof/features/analysts';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import { exactDuration, number } from '@lumina/tools/format';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
|
||||
import { TargetLine } from './components/TargetLine';
|
||||
import type { AccountDialogsProps } from './types';
|
||||
|
||||
/**
|
||||
* «تعلیق حساب تحلیلگر» (J11-5, J11-5b with a template) and «رفع تعلیق حساب» (J11-5e). Each says
|
||||
* whom it touches: the active subscribers losing access, or the subscriptions extended and by how
|
||||
* long. A suspension's reason reaches the analyst (never the subscribers); a reinstatement's stays
|
||||
* in the audit log. Only a suspended channel extends; after an account-only suspension the analyst may still
|
||||
* have subscribers, and the dialog says none of them is extended. Both stay mounted, so each keeps
|
||||
* animating out and clears its text once it's gone.
|
||||
*/
|
||||
export function AccountDialogs({ account }: AccountDialogsProps) {
|
||||
const { t } = useTranslation(['analysts', 'common']);
|
||||
const { dialog } = account;
|
||||
const target = dialog?.target;
|
||||
const subscribers = target?.activeSubscriptions ?? 0;
|
||||
const reinstate = dialog?.kind === 'reinstate' ? dialog : null;
|
||||
const extendedCount = reinstate?.extendedCount ?? 0;
|
||||
|
||||
return (
|
||||
<>
|
||||
<ReasonDialog
|
||||
open={dialog?.kind === 'suspend' && dialog.open}
|
||||
onClose={account.closeDialog}
|
||||
title={t('suspend.title')}
|
||||
description={<TargetLine target={target} />}
|
||||
fieldLabel={t('suspend.field')}
|
||||
placeholder={t('suspend.placeholder')}
|
||||
hint={t('suspend.hint')}
|
||||
templatesLabel={t('suspend.templates-label')}
|
||||
templates={SUSPEND_TEMPLATES.map((id) => ({
|
||||
id,
|
||||
label: t(`suspend.templates.${id}.label`),
|
||||
text: t(`suspend.templates.${id}.text`),
|
||||
}))}
|
||||
emptyReason={t('suspend.empty')}
|
||||
form={account.suspendForm}
|
||||
onSubmit={account.confirmSuspend}
|
||||
isSubmitting={account.isSuspending}
|
||||
confirmLabel={t('suspend.confirm')}
|
||||
>
|
||||
{subscribers > 0 ? (
|
||||
<Banner tone="danger" icon="users">
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="suspend.impact"
|
||||
values={{ subscribers: number(subscribers) }}
|
||||
components={{
|
||||
strong: (
|
||||
<Typography
|
||||
tag="strong"
|
||||
variant="inherit"
|
||||
color="inherit"
|
||||
className="font-bold"
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Banner>
|
||||
) : (
|
||||
<Banner tone="neutral" icon="users">
|
||||
{t('suspend.impact-none')}
|
||||
</Banner>
|
||||
)}
|
||||
</ReasonDialog>
|
||||
<ReasonDialog
|
||||
open={dialog?.kind === 'reinstate' && dialog.open}
|
||||
onClose={account.closeDialog}
|
||||
title={t('reinstate.title')}
|
||||
description={<TargetLine target={target} />}
|
||||
fieldLabel={t('reinstate.field')}
|
||||
placeholder={t('reinstate.placeholder')}
|
||||
emptyReason={t('reinstate.empty')}
|
||||
form={account.reinstateForm}
|
||||
onSubmit={account.confirmReinstate}
|
||||
isSubmitting={account.isReinstating}
|
||||
confirmLabel={t('reinstate.confirm')}
|
||||
confirmVariant="primary"
|
||||
>
|
||||
<Typography tag="p" variant="body-md" className="m-0">
|
||||
{t('reinstate.description')}
|
||||
</Typography>
|
||||
{extendedCount > 0 ? (
|
||||
<Banner tone="danger" icon="clock">
|
||||
{t('reinstate.impact', {
|
||||
subscriptions: number(extendedCount),
|
||||
duration: exactDuration(reinstate?.extensionMinutes ?? 0),
|
||||
})}
|
||||
</Banner>
|
||||
) : (
|
||||
<Banner tone="neutral" icon="clock">
|
||||
{subscribers > 0
|
||||
? t('reinstate.impact-account-only')
|
||||
: t('reinstate.impact-none')}
|
||||
</Banner>
|
||||
)}
|
||||
</ReasonDialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { AccountActionButtonProps } from '../types';
|
||||
|
||||
/**
|
||||
* The one account action an analyst has (J11-4): «تعلیق حساب» (danger) while فعال, «رفع تعلیق»
|
||||
* (primary) while تعلیقشده, never both. Its accessible name says whose account.
|
||||
*/
|
||||
export function AccountActionButton({
|
||||
target,
|
||||
account,
|
||||
size = 'sm',
|
||||
withIcon = false,
|
||||
block,
|
||||
}: AccountActionButtonProps) {
|
||||
const { t } = useTranslation('analysts');
|
||||
|
||||
return target.accountStatus === 'suspended' ? (
|
||||
<Button
|
||||
variant="primary"
|
||||
size={size}
|
||||
block={block}
|
||||
icon={withIcon ? 'check' : undefined}
|
||||
aria-label={t('account.reinstate-of', { name: target.fullName })}
|
||||
onClick={() => account.openReinstate(target)}
|
||||
>
|
||||
{t('account.reinstate')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="danger"
|
||||
size={size}
|
||||
block={block}
|
||||
icon={withIcon ? 'ban' : undefined}
|
||||
aria-label={t('account.suspend-of', { name: target.fullName })}
|
||||
onClick={() => account.openSuspend(target)}
|
||||
>
|
||||
{t('account.suspend')}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
|
||||
import type { TargetLineProps } from '../types';
|
||||
|
||||
/** Whom the dialog acts on, under its title: «علی محمدی · @ali_gold». */
|
||||
export function TargetLine({ target }: TargetLineProps) {
|
||||
if (!target) return null;
|
||||
return (
|
||||
<Typography tag="p" variant="caption" color="secondary" className="m-0">
|
||||
{target.fullName} ·{' '}
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{target.username}
|
||||
</Element>
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export { AccountDialogs } from './AccountDialogs';
|
||||
export { AccountActionButton } from './components/AccountActionButton';
|
||||
export type { AccountActionButtonProps, AccountDialogsProps } from './types';
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import type {
|
||||
AccountTarget,
|
||||
AnalystAccountModel,
|
||||
} from '@lumina/garden-roof/features/analysts';
|
||||
import type { ButtonProps } from '@lumina/island/atoms/button';
|
||||
|
||||
export type AccountDialogsProps = { account: AnalystAccountModel };
|
||||
|
||||
export type AccountActionButtonProps = {
|
||||
target: AccountTarget;
|
||||
account: AnalystAccountModel;
|
||||
size?: ButtonProps['size'];
|
||||
/** The detail header's `ban` / `check` before the label (J11-4b). */
|
||||
withIcon?: boolean;
|
||||
block?: boolean;
|
||||
};
|
||||
|
||||
export type TargetLineProps = { target: AccountTarget | undefined };
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
'use client';
|
||||
|
||||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { useAnalystsPage } from '@lumina/garden-roof/features/analysts';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { SearchField } from '@lumina/island/molecules/search-field';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { Suspense } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { AccountDialogs } from '../account-dialogs';
|
||||
import { AnalystRows } from './components/AnalystRows';
|
||||
import { ListSkeleton } from './components/ListSkeleton';
|
||||
|
||||
/**
|
||||
* مدیریت تحلیلگران (J11-4): the search, in the URL, over every analyst. A new search or page
|
||||
* remounts the rows behind the table skeleton; a failed read errors in their place. The account
|
||||
* dialogs sit outside the rows, so the rows can reload under them.
|
||||
*/
|
||||
export function AnalystsList() {
|
||||
const { t } = useTranslation(['analysts', 'common']);
|
||||
const model = useAnalystsPage();
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6">
|
||||
<Element className="w-full desktop:w-110">
|
||||
<SearchField
|
||||
label={t('list.search')}
|
||||
placeholder={t('list.search')}
|
||||
clearLabel={t('common:search.clear')}
|
||||
value={model.search.value}
|
||||
onValueChange={model.search.setValue}
|
||||
/>
|
||||
</Element>
|
||||
<PartBoundary
|
||||
key={model.argsKey}
|
||||
name="analysts-list"
|
||||
description={t('list.error')}
|
||||
>
|
||||
<Suspense fallback={<ListSkeleton label={t('list.loading')} />}>
|
||||
<AnalystRows args={model.args} account={model.account} />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
<AccountDialogs account={model.account} />
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
'use client';
|
||||
|
||||
import { ROUTES } from '@lumina/garden-roof/app/navigation';
|
||||
import { useAnalystListPart } from '@lumina/garden-roof/features/analysts';
|
||||
import { Avatar } from '@lumina/island/atoms/avatar';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { StatusBadge } from '@lumina/island/atoms/status-badge';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { ListRow } from '@lumina/island/molecules/list-row';
|
||||
import { Pager } from '@lumina/island/molecules/pager';
|
||||
import { DataTable } from '@lumina/island/organisms/data-table';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
|
||||
import { AccountActionButton } from '../../account-dialogs';
|
||||
import type { AnalystRowsProps } from '../types';
|
||||
import { AnalystsEmpty } from './AnalystsEmpty';
|
||||
|
||||
/**
|
||||
* Every analyst for the search and page: a table from 1024px up (J11-4), a card per analyst on a
|
||||
* phone (J11-4 M, 0063). A suspended account's row is tinted. The row opens the analyst; its one
|
||||
* account action opens its dialog in place.
|
||||
*/
|
||||
export function AnalystRows({ args, account }: AnalystRowsProps) {
|
||||
const { t } = useTranslation(['analysts', 'common']);
|
||||
const router = useRouter();
|
||||
const part = useAnalystListPart(args);
|
||||
|
||||
if (part.empty) {
|
||||
return (
|
||||
<AnalystsEmpty
|
||||
kind={part.empty}
|
||||
onClearSearch={() => router.replace(ROUTES.analysts)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-4">
|
||||
<Element className="hidden overflow-x-auto desktop:block">
|
||||
<DataTable label={t('list.table-label')}>
|
||||
<DataTable.Head>
|
||||
<DataTable.HeaderCell>
|
||||
{t('list.columns.analyst')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('list.columns.username')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('list.columns.verification')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('list.columns.account')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('list.columns.subscribers')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell hidden shrink>
|
||||
{t('list.columns.actions')}
|
||||
</DataTable.HeaderCell>
|
||||
</DataTable.Head>
|
||||
<DataTable.Body>
|
||||
{part.rows.map((row) => (
|
||||
<DataTable.Row
|
||||
key={row.id}
|
||||
tone={row.accountStatus === 'suspended' ? 'danger' : 'default'}
|
||||
onActivate={() => router.push(ROUTES.analyst(row.id))}
|
||||
>
|
||||
<DataTable.Cell>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
wrap="flex-nowrap"
|
||||
>
|
||||
<Avatar name={row.username} src={row.avatarUrl} size="sm" />
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="inherit"
|
||||
className="font-semibold"
|
||||
>
|
||||
{row.fullName}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{row.username}
|
||||
</Element>
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
<StatusBadge
|
||||
status={`verification.${row.verificationStatus}`}
|
||||
>
|
||||
{t(`common:status.verification.${row.verificationStatus}`)}
|
||||
</StatusBadge>
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
<StatusBadge status={`account.${row.accountStatus}`}>
|
||||
{t(`common:status.account.${row.accountStatus}`)}
|
||||
</StatusBadge>
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
{number(row.activeSubscriptions)}
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell shrink>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-2"
|
||||
wrap="flex-nowrap"
|
||||
>
|
||||
<AccountActionButton target={row} account={account} />
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="chevron-left"
|
||||
label={t('list.open-row', { name: row.fullName })}
|
||||
href={ROUTES.analyst(row.id)}
|
||||
/>
|
||||
</FlexBox>
|
||||
</DataTable.Cell>
|
||||
</DataTable.Row>
|
||||
))}
|
||||
</DataTable.Body>
|
||||
</DataTable>
|
||||
</Element>
|
||||
<FlexBox
|
||||
tag="ul"
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
className="m-0 list-none p-0 desktop:hidden"
|
||||
>
|
||||
{part.rows.map((row) => (
|
||||
<Element tag="li" key={row.id}>
|
||||
<Card
|
||||
padding="none"
|
||||
accent={row.accountStatus === 'suspended' ? 'danger' : undefined}
|
||||
className="overflow-hidden"
|
||||
>
|
||||
<Element tag="ul" className="m-0 list-none p-0">
|
||||
<ListRow
|
||||
href={ROUTES.analyst(row.id)}
|
||||
leading={
|
||||
<Avatar name={row.username} src={row.avatarUrl} size="md" />
|
||||
}
|
||||
title={row.fullName}
|
||||
subtitle={
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{row.username}
|
||||
</Element>
|
||||
}
|
||||
>
|
||||
<FlexBox
|
||||
tag="span"
|
||||
gap="gap-2"
|
||||
wrap="flex-wrap"
|
||||
className="pt-1"
|
||||
>
|
||||
<StatusBadge
|
||||
status={`verification.${row.verificationStatus}`}
|
||||
>
|
||||
{t(
|
||||
`common:status.verification.${row.verificationStatus}`,
|
||||
)}
|
||||
</StatusBadge>
|
||||
<StatusBadge status={`account.${row.accountStatus}`}>
|
||||
{t(`common:status.account.${row.accountStatus}`)}
|
||||
</StatusBadge>
|
||||
</FlexBox>
|
||||
</ListRow>
|
||||
</Element>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-between"
|
||||
gap="gap-3"
|
||||
className="pe-4 pb-3 ps-17"
|
||||
>
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey="list.subscribers"
|
||||
values={{ subscribers: number(row.activeSubscriptions) }}
|
||||
components={{
|
||||
strong: (
|
||||
<Typography
|
||||
tag="strong"
|
||||
variant="inherit"
|
||||
color="primary"
|
||||
className="font-semibold"
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Typography>
|
||||
<AccountActionButton target={row} account={account} size="md" />
|
||||
</FlexBox>
|
||||
</Card>
|
||||
</Element>
|
||||
))}
|
||||
</FlexBox>
|
||||
<Pager
|
||||
page={part.page}
|
||||
pageCount={part.pageCount}
|
||||
hrefFor={part.pageHref}
|
||||
summary={t('common:pager.summary', {
|
||||
from: number(part.from),
|
||||
to: number(part.to),
|
||||
total: number(part.total),
|
||||
})}
|
||||
labels={{
|
||||
nav: t('common:pager.label'),
|
||||
previous: t('common:pager.previous'),
|
||||
next: t('common:pager.next'),
|
||||
page: (page) => t('common:pager.page', { page: number(page) }),
|
||||
}}
|
||||
/>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { EmptyState } from '@lumina/island/molecules/empty-state';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { AnalystsEmptyProps } from '../types';
|
||||
|
||||
/** No row: no analyst has signed up yet, or nothing matched the search. */
|
||||
export function AnalystsEmpty({ kind, onClearSearch }: AnalystsEmptyProps) {
|
||||
const { t } = useTranslation('analysts');
|
||||
|
||||
return (
|
||||
<Card padding="none">
|
||||
{kind === 'search' ? (
|
||||
<EmptyState
|
||||
tone="neutral"
|
||||
title={t('list.empty.search.title')}
|
||||
description={t('list.empty.search.description')}
|
||||
>
|
||||
<Button variant="secondary" onClick={onClearSearch}>
|
||||
{t('list.empty.search.clear')}
|
||||
</Button>
|
||||
</EmptyState>
|
||||
) : (
|
||||
<EmptyState
|
||||
tone="neutral"
|
||||
icon="users"
|
||||
title={t('list.empty.list.title')}
|
||||
description={t('list.empty.list.description')}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
/** The list's rows before they arrive: the admin table preset (J11-4). */
|
||||
export function ListSkeleton({
|
||||
label,
|
||||
delayed,
|
||||
}: {
|
||||
label: string;
|
||||
delayed?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<SkeletonPreset
|
||||
preset="table"
|
||||
columns={6}
|
||||
count={5}
|
||||
label={label}
|
||||
delayed={delayed}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export { AnalystsList } from './AnalystsList';
|
||||
export { ListSkeleton } from './components/ListSkeleton';
|
||||
export type { AnalystsListProps } from './types';
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import type {
|
||||
AnalystAccountModel,
|
||||
ListAnalystsArgs,
|
||||
} from '@lumina/garden-roof/features/analysts';
|
||||
|
||||
export type AnalystsListProps = Record<string, never>;
|
||||
|
||||
export type AnalystRowsProps = {
|
||||
args: ListAnalystsArgs;
|
||||
account: AnalystAccountModel;
|
||||
};
|
||||
|
||||
export type AnalystsEmptyProps = {
|
||||
kind: 'list' | 'search';
|
||||
onClearSearch: () => void;
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import { AdminGuard } from '@lumina/garden-roof/app/guards';
|
||||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import { AnalystsList, ListSkeleton } from './organisms/analysts-list';
|
||||
|
||||
export const metadata: Metadata = { title: i18n.t('analysts:list.meta-title') };
|
||||
|
||||
/**
|
||||
* مدیریت تحلیلگران (J11-4): the title on the server; every analyst in the browser once the admin
|
||||
* is known (0062).
|
||||
*/
|
||||
export default function AnalystsPage() {
|
||||
const skeleton = <ListSkeleton label={i18n.t('analysts:list.loading')} />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={i18n.t('analysts:list.title')} />
|
||||
<AdminGuard fallback={skeleton}>
|
||||
<Suspense fallback={skeleton}>
|
||||
<AnalystsList />
|
||||
</Suspense>
|
||||
</AdminGuard>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
'use client';
|
||||
|
||||
import { ErrorFallback } from '@lumina/garden-roof/app/error-boundaries';
|
||||
|
||||
type GroupErrorProps = {
|
||||
error: Error & { digest?: string };
|
||||
retry: () => void;
|
||||
};
|
||||
|
||||
/** A failed panel page: the state in the page's column; the layout keeps the sidebar. */
|
||||
export default function GroupError({ error, retry }: GroupErrorProps) {
|
||||
return (
|
||||
<ErrorFallback error={error} size="page" name="panel" onRetry={retry} />
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import { FeaturedSkeleton } from './organisms/featured-list';
|
||||
|
||||
/** The list before it arrives: its title and subtitle over the skeleton. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={i18n.t('featured:page.title')}
|
||||
subtitle={i18n.t('featured:page.subtitle')}
|
||||
/>
|
||||
<FeaturedSkeleton label={i18n.t('featured:page.loading')} delayed />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
'use client';
|
||||
|
||||
import { AuditLog } from '@lumina/garden-roof/app/screens';
|
||||
import { useFeaturedPage } from '@lumina/garden-roof/features/featured';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { EmptyState } from '@lumina/island/molecules/empty-state';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { AddFeaturedButton } from './components/AddFeaturedButton';
|
||||
import { AddFeaturedDialog } from './components/AddFeaturedDialog';
|
||||
import { FeaturedPreview } from './components/FeaturedPreview';
|
||||
import { FeaturedTable } from './components/FeaturedTable';
|
||||
import { FewerBanner } from './components/FewerBanner';
|
||||
import { PageVisibility } from './components/PageVisibility';
|
||||
import { RemoveFeaturedDialog } from './components/RemoveFeaturedDialog';
|
||||
|
||||
/**
|
||||
* تحلیلگران منتخب (J11-10): with fewer than three visible, the warning first (J11-10e); the list in
|
||||
* the admin's order, reordered by drag, keyboard or the row menu and saved on drop (J11-10b,
|
||||
* J11-10g); where the analysts show while fewer than three are visible; the preview of the first
|
||||
* cards; and «گزارش ممیزی», folded. The add and remove dialogs (J11-10c, J11-10d) sit over it.
|
||||
*/
|
||||
export function FeaturedList() {
|
||||
const { t } = useTranslation('featured');
|
||||
const model = useFeaturedPage();
|
||||
const { featured } = model;
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6">
|
||||
<FewerBanner featured={featured} />
|
||||
{model.rows.length === 0 ? (
|
||||
<Card padding="none">
|
||||
<EmptyState
|
||||
title={t('empty.title')}
|
||||
description={t('empty.description')}
|
||||
>
|
||||
<AddFeaturedButton label={t('page.add')} />
|
||||
</EmptyState>
|
||||
</Card>
|
||||
) : (
|
||||
<FeaturedTable model={model} />
|
||||
)}
|
||||
<PageVisibility featured={featured} />
|
||||
<FeaturedPreview model={model} />
|
||||
<AuditLog entries={featured.audit} collapsible />
|
||||
<RemoveFeaturedDialog model={model} />
|
||||
<AddFeaturedDialog
|
||||
open={model.isAddOpen}
|
||||
featured={featured}
|
||||
onClose={model.closeAdd}
|
||||
/>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
'use client';
|
||||
|
||||
import { ROUTES } from '@lumina/garden-roof/app/navigation';
|
||||
import { FEATURED_PARAMS } from '@lumina/garden-roof/features/featured';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
|
||||
/**
|
||||
* «افزودن تحلیلگر» in the page header (J11-10): it opens «افزودن تحلیلگر منتخب» through `?add=1`,
|
||||
* so the server renders the header and a reload keeps the dialog open.
|
||||
*/
|
||||
export function AddFeaturedButton({ label }: { label: string }) {
|
||||
return (
|
||||
<Button
|
||||
icon="plus"
|
||||
href={`${ROUTES.featured}?${FEATURED_PARAMS.add}=1`}
|
||||
replace
|
||||
scroll={false}
|
||||
>
|
||||
{label}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
'use client';
|
||||
|
||||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { useAddFeaturedDialog } from '@lumina/garden-roof/features/featured';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Modal } from '@lumina/island/molecules/modal';
|
||||
import { SearchField } from '@lumina/island/molecules/search-field';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { Suspense } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { AddFeaturedDialogProps } from '../types';
|
||||
import { CandidateOptions } from './CandidateOptions';
|
||||
|
||||
/**
|
||||
* «افزودن تحلیلگر منتخب» (J11-10c): the search, then what it finds behind its own skeleton and
|
||||
* error, the note that new analysts join the end, and «افزودن به منتخب (n)», which waits for a pick.
|
||||
* Picks survive a new search; the dialog forgets them once closed.
|
||||
*/
|
||||
export function AddFeaturedDialog({
|
||||
open,
|
||||
featured,
|
||||
onClose,
|
||||
}: AddFeaturedDialogProps) {
|
||||
const { t } = useTranslation(['featured', 'common']);
|
||||
const model = useAddFeaturedDialog({ featured, onClose });
|
||||
const count = model.picked.length;
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={model.isAdding ? undefined : onClose}
|
||||
dismissible={!model.isAdding}
|
||||
onExited={model.reset}
|
||||
title={t('add.title')}
|
||||
actions={
|
||||
<>
|
||||
<Button
|
||||
block
|
||||
isLoading={model.isAdding}
|
||||
frozen={count === 0}
|
||||
frozenReason={t('add.nothing-picked')}
|
||||
onClick={model.confirm}
|
||||
>
|
||||
{count === 0
|
||||
? t('add.confirm')
|
||||
: t('add.confirm-count', { total: number(count) })}
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
block
|
||||
disabled={model.isAdding}
|
||||
onClick={onClose}
|
||||
>
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<FlexBox direction="flex-col" gap="gap-4">
|
||||
<SearchField
|
||||
label={t('add.search')}
|
||||
placeholder={t('add.search')}
|
||||
clearLabel={t('common:search.clear')}
|
||||
value={model.search.value}
|
||||
onValueChange={model.search.setValue}
|
||||
/>
|
||||
<PartBoundary
|
||||
key={model.search.query}
|
||||
name="featured-candidates"
|
||||
description={t('add.error')}
|
||||
>
|
||||
<Suspense
|
||||
fallback={
|
||||
<SkeletonPreset
|
||||
preset="list"
|
||||
count={3}
|
||||
label={t('add.loading')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<CandidateOptions
|
||||
query={model.search.query}
|
||||
isPicked={model.isPicked}
|
||||
onToggle={model.toggle}
|
||||
/>
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
<Typography tag="p" variant="caption" color="secondary" className="m-0">
|
||||
{t('add.note')}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
'use client';
|
||||
|
||||
import { useFeaturedCandidatesPart } from '@lumina/garden-roof/features/featured';
|
||||
import type { FeaturedCandidatePayload } from '@lumina/garden-roof/features/featured';
|
||||
import { Avatar } from '@lumina/island/atoms/avatar';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Tag } from '@lumina/island/atoms/tag';
|
||||
import { ChoiceCard } from '@lumina/island/molecules/choice-card';
|
||||
import { EmptyState } from '@lumina/island/molecules/empty-state';
|
||||
import { List, ListRow } from '@lumina/island/molecules/list-row';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { CandidateOptionsProps } from '../types';
|
||||
|
||||
/**
|
||||
* What a search finds (J11-10c): each eligible analyst a checkbox card, «@user · بازار»; under them
|
||||
* the ones who can't be added yet, dimmed, each with the first check they fail.
|
||||
*/
|
||||
export function CandidateOptions({
|
||||
query,
|
||||
isPicked,
|
||||
onToggle,
|
||||
}: CandidateOptionsProps) {
|
||||
const { t } = useTranslation(['featured', 'common']);
|
||||
const part = useFeaturedCandidatesPart(query);
|
||||
|
||||
if (part.isEmpty) {
|
||||
return (
|
||||
<EmptyState
|
||||
tone="neutral"
|
||||
size="compact"
|
||||
title={t('add.empty.title')}
|
||||
description={t('add.empty.description')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const handle = (candidate: FeaturedCandidatePayload) => (
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{candidate.username}
|
||||
</Element>
|
||||
);
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
{part.eligible.length > 0 && (
|
||||
<FlexBox
|
||||
tag="fieldset"
|
||||
aria-label={t('add.eligible-label')}
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
className="m-0 min-w-0 border-0 p-0"
|
||||
>
|
||||
{part.eligible.map((candidate) => (
|
||||
<ChoiceCard
|
||||
key={candidate.id}
|
||||
multiple
|
||||
name="analystIds"
|
||||
value={candidate.id}
|
||||
checked={isPicked(candidate.id)}
|
||||
onChange={() => onToggle(candidate)}
|
||||
title={candidate.fullName}
|
||||
description={
|
||||
<>
|
||||
{handle(candidate)} ·{' '}
|
||||
{candidate.markets
|
||||
.map((market) => t(`common:markets.${market}`))
|
||||
.join('، ')}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</FlexBox>
|
||||
)}
|
||||
{part.ineligible.length > 0 && (
|
||||
<List tone="flush" aria-label={t('add.ineligible-label')}>
|
||||
{part.ineligible.map((candidate) => (
|
||||
<ListRow
|
||||
key={candidate.id}
|
||||
dimmed
|
||||
leading={
|
||||
<Avatar
|
||||
name={candidate.username}
|
||||
src={candidate.avatarUrl}
|
||||
size="md"
|
||||
/>
|
||||
}
|
||||
title={candidate.fullName}
|
||||
subtitle={handle(candidate)}
|
||||
end={
|
||||
candidate.ineligibleReason && (
|
||||
<Tag variant="neutral">
|
||||
{t(`add.reasons.${candidate.ineligibleReason}`)}
|
||||
</Tag>
|
||||
)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { Tag } from '@lumina/island/atoms/tag';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { AnalystCard } from '@lumina/island/organisms/analyst-card';
|
||||
import type { AnalystCardLabels } from '@lumina/island/organisms/analyst-card';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useId } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { FeaturedPartProps } from '../types';
|
||||
|
||||
/**
|
||||
* «پیشنمایش» (J11-10): the first three visible cards in the saved order, as the public card draws
|
||||
* them, so a drag shows here only once it's dropped. Hidden analysts are skipped (J11-10f); with
|
||||
* fewer than three visible the landing has none, so the title names only خانه and «تحلیلگران
|
||||
* منتخب» (J11-10e).
|
||||
*/
|
||||
export function FeaturedPreview({ model }: FeaturedPartProps) {
|
||||
const { t } = useTranslation(['featured', 'common']);
|
||||
const titleId = useId();
|
||||
const { featured, preview } = model;
|
||||
if (preview.length === 0) return null;
|
||||
|
||||
const labels: AnalystCardLabels = {
|
||||
verified: t('card.verified'),
|
||||
markets: t('card.markets'),
|
||||
winRate: t('card.win-rate'),
|
||||
predictions: t('card.predictions'),
|
||||
avgRoi: t('card.avg-roi'),
|
||||
noRecord: t('card.no-record'),
|
||||
followers: (followers) => t('card.followers', { followers }),
|
||||
view: t('card.view'),
|
||||
};
|
||||
const shown = number(preview.length);
|
||||
const caption = !featured.landingVisible
|
||||
? t('preview.visible', { total: number(featured.visibleCount) })
|
||||
: featured.visibleCount < featured.items.length
|
||||
? t('preview.first-visible', {
|
||||
shown,
|
||||
total: number(featured.visibleCount),
|
||||
})
|
||||
: t('preview.first', { shown, total: number(featured.items.length) });
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag="section"
|
||||
aria-labelledby={titleId}
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-between"
|
||||
gap="gap-3"
|
||||
>
|
||||
<FlexBox alignItems="items-center" gap="gap-2">
|
||||
<Typography
|
||||
tag="h2"
|
||||
id={titleId}
|
||||
variant="heading-sm"
|
||||
className="m-0"
|
||||
>
|
||||
{featured.landingVisible
|
||||
? t('preview.landing-title')
|
||||
: t('preview.home-title')}
|
||||
</Typography>
|
||||
<Tag variant="neutral" icon="eye">
|
||||
{t('preview.tag')}
|
||||
</Tag>
|
||||
</FlexBox>
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
{caption}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
<GridBox cols="grid-cols-1" gap="gap-4" className="desktop:grid-cols-3">
|
||||
{preview.map((analyst) => (
|
||||
<AnalystCard
|
||||
key={analyst.id}
|
||||
analyst={{
|
||||
username: analyst.username,
|
||||
displayName: analyst.fullName,
|
||||
avatar: analyst.avatarUrl,
|
||||
verified: true,
|
||||
markets: analyst.markets.map((market) =>
|
||||
t(`common:markets.${market}`),
|
||||
),
|
||||
bio: analyst.bio,
|
||||
followers: analyst.followers,
|
||||
stats: analyst.stats,
|
||||
}}
|
||||
labels={labels}
|
||||
/>
|
||||
))}
|
||||
</GridBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
'use client';
|
||||
|
||||
import { Avatar } from '@lumina/island/atoms/avatar';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Icon } from '@lumina/island/atoms/icon';
|
||||
import { StatusBadge } from '@lumina/island/atoms/status-badge';
|
||||
import { Tag } from '@lumina/island/atoms/tag';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { PersonSummary } from '@lumina/island/molecules/person-summary';
|
||||
import { DataTable } from '@lumina/island/organisms/data-table';
|
||||
import { cn } from '@lumina/island/tools/cn';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { FeaturedRowProps } from '../types';
|
||||
import { RowMenu } from './RowMenu';
|
||||
|
||||
/**
|
||||
* One analyst at their place (J11-10): the grip, the admin-only number, who, markets, public track
|
||||
* record, account status, «حذف از منتخب» and «بیشتر». The moving row sits on the sunken ground and
|
||||
* says where it is (J11-10b); a hidden one (suspended) is dimmed and says why (J11-10f).
|
||||
*/
|
||||
export function FeaturedRow({
|
||||
row,
|
||||
total,
|
||||
grip,
|
||||
onRemove,
|
||||
onMoveUp,
|
||||
onMoveDown,
|
||||
}: FeaturedRowProps) {
|
||||
const { t } = useTranslation(['featured', 'common']);
|
||||
|
||||
return (
|
||||
<DataTable.Row
|
||||
tone={row.isVisible ? 'default' : 'dimmed'}
|
||||
className={cn(row.isMoving && '[&>td]:bg-surface-sunken')}
|
||||
>
|
||||
<DataTable.Cell shrink>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="grip"
|
||||
label={t('reorder.grip', { name: row.fullName })}
|
||||
className="cursor-grab touch-none"
|
||||
{...grip}
|
||||
/>
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell shrink>{number(row.position)}</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
{row.isMoving ? (
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
wrap="flex-nowrap"
|
||||
className="min-w-0"
|
||||
>
|
||||
<Avatar name={row.username} src={row.avatarUrl} size="sm" />
|
||||
<FlexBox direction="flex-col" className="min-w-0">
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="body-sm"
|
||||
className="truncate font-semibold"
|
||||
>
|
||||
{row.fullName}
|
||||
</Typography>
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="caption"
|
||||
color="secondary"
|
||||
className="truncate"
|
||||
>
|
||||
{t('reorder.moving-row', {
|
||||
position: number(row.position),
|
||||
total: number(total),
|
||||
})}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
) : (
|
||||
<PersonSummary
|
||||
name={row.fullName}
|
||||
username={row.username}
|
||||
avatarSrc={row.avatarUrl}
|
||||
meta={
|
||||
row.hiddenReason
|
||||
? t('table.hidden', {
|
||||
reason: t(`table.hidden-reasons.${row.hiddenReason}`),
|
||||
})
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
<FlexBox gap="gap-1" wrap="flex-nowrap">
|
||||
{row.markets.map((market) => (
|
||||
<Tag key={market}>{t(`common:markets.${market}`)}</Tag>
|
||||
))}
|
||||
</FlexBox>
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
{row.hasPublicTrackRecord ? (
|
||||
<Icon name="check" size={18} label={t('table.track-record.yes')} />
|
||||
) : (
|
||||
<Icon
|
||||
name="minus"
|
||||
size={18}
|
||||
label={t('table.track-record.no')}
|
||||
className="text-text-tertiary"
|
||||
/>
|
||||
)}
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
<StatusBadge status={`account.${row.accountStatus}`}>
|
||||
{t(`common:status.account.${row.accountStatus}`)}
|
||||
</StatusBadge>
|
||||
</DataTable.Cell>
|
||||
{/* A dimmed row's cells are their own layers: while its menu is open the cell is opaque and above the rows under it. */}
|
||||
<DataTable.Cell
|
||||
shrink
|
||||
className="relative has-[[aria-expanded=true]]:z-10 has-[[aria-expanded=true]]:opacity-100"
|
||||
>
|
||||
<FlexBox alignItems="items-center" gap="gap-2" wrap="flex-nowrap">
|
||||
<Button variant="danger" size="sm" onClick={onRemove}>
|
||||
{t('table.remove')}
|
||||
</Button>
|
||||
<RowMenu
|
||||
name={row.fullName}
|
||||
canMoveUp={row.canMoveUp}
|
||||
canMoveDown={row.canMoveDown}
|
||||
onMoveUp={onMoveUp}
|
||||
onMoveDown={onMoveDown}
|
||||
/>
|
||||
</FlexBox>
|
||||
</DataTable.Cell>
|
||||
</DataTable.Row>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
|
||||
import type { FeaturedSkeletonProps } from '../types';
|
||||
|
||||
/** The list before it arrives: the table preset over the preview's three cards (J11-10). */
|
||||
export function FeaturedSkeleton({ label, delayed }: FeaturedSkeletonProps) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6">
|
||||
<SkeletonPreset
|
||||
preset="table"
|
||||
columns={7}
|
||||
count={5}
|
||||
label={label}
|
||||
delayed={delayed}
|
||||
/>
|
||||
<GridBox gap="gap-4" className="desktop:grid-cols-3">
|
||||
<Skeleton className="h-64 rounded-lg" />
|
||||
<Skeleton className="h-64 rounded-lg" />
|
||||
<Skeleton className="h-64 rounded-lg" />
|
||||
</GridBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { DataTable } from '@lumina/island/organisms/data-table';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { cn } from '@lumina/island/tools/cn';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { FeaturedPartProps } from '../types';
|
||||
import { FeaturedRow } from './FeaturedRow';
|
||||
|
||||
/**
|
||||
* The list in the admin's order (J11-10), reordered in place (J11-10b, J11-10g). It scrolls
|
||||
* sideways while the column is narrower than its seven columns (below 1280px); from there its
|
||||
* overflow stays visible, so a row's menu isn't clipped, and the corners are rounded on the cells. Under it, the live caption that follows a moving row, and the note
|
||||
* on hidden (suspended) analysts (J11-10f).
|
||||
*/
|
||||
export function FeaturedTable({ model }: FeaturedPartProps) {
|
||||
const { t } = useTranslation('featured');
|
||||
const { reorder, rows } = model;
|
||||
const { announcement } = reorder;
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-3">
|
||||
<Element className="overflow-x-auto wide:overflow-visible">
|
||||
<DataTable
|
||||
label={t('table.label')}
|
||||
className={cn(
|
||||
'wide:overflow-visible [&_tbody>tr:last-child>td:first-child]:rounded-es-lg [&_tbody>tr:last-child>td:last-child]:rounded-ee-lg [&_thead_th:first-child]:rounded-ss-lg [&_thead_th:last-child]:rounded-se-lg',
|
||||
reorder.isDragging && 'cursor-grabbing select-none',
|
||||
)}
|
||||
>
|
||||
<DataTable.Head>
|
||||
<DataTable.HeaderCell shrink>
|
||||
{t('table.columns.move')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell shrink>
|
||||
{t('table.columns.position')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('table.columns.analyst')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('table.columns.markets')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('table.columns.track-record')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('table.columns.status')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell shrink>
|
||||
{t('table.columns.actions')}
|
||||
</DataTable.HeaderCell>
|
||||
</DataTable.Head>
|
||||
<DataTable.Body>
|
||||
{rows.map((row) => (
|
||||
<FeaturedRow
|
||||
key={row.id}
|
||||
row={row}
|
||||
total={rows.length}
|
||||
grip={reorder.gripProps(row.id)}
|
||||
onRemove={() => model.openRemove(row.id)}
|
||||
onMoveUp={() => model.moveUp(row.id)}
|
||||
onMoveDown={() => model.moveDown(row.id)}
|
||||
/>
|
||||
))}
|
||||
</DataTable.Body>
|
||||
</DataTable>
|
||||
</Element>
|
||||
<Typography
|
||||
tag="output"
|
||||
variant="caption"
|
||||
color="secondary"
|
||||
aria-live="polite"
|
||||
className={cn(
|
||||
'm-0 block',
|
||||
announcement?.kind !== 'moving' && 'sr-only',
|
||||
)}
|
||||
>
|
||||
{announcement &&
|
||||
t(`reorder.${announcement.kind}`, {
|
||||
name: announcement.name,
|
||||
position: number(announcement.position),
|
||||
total: number(announcement.total),
|
||||
})}
|
||||
</Typography>
|
||||
{model.hasSuspended && (
|
||||
<Typography tag="p" variant="caption" color="secondary" className="m-0">
|
||||
{t('table.hidden-note')}
|
||||
</Typography>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
'use client';
|
||||
|
||||
import { LANDING_MIN_VISIBLE } from '@lumina/garden-roof/features/featured';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { FeaturedListPartProps } from '../types';
|
||||
|
||||
/**
|
||||
* «کمتر از ۳ تحلیلگر منتخب» (J11-10e): the landing hides its analysts section; خانه and «تحلیلگران
|
||||
* منتخب» show the visible ones, and the banner says how many more bring the section back.
|
||||
*/
|
||||
export function FewerBanner({ featured }: FeaturedListPartProps) {
|
||||
const { t } = useTranslation('featured');
|
||||
if (featured.landingVisible) return null;
|
||||
const visible = featured.visibleCount;
|
||||
const needed = LANDING_MIN_VISIBLE - visible;
|
||||
|
||||
return (
|
||||
<Banner tone="warning" title={t('fewer.title')}>
|
||||
{visible === 0
|
||||
? t('fewer.shown-none')
|
||||
: t('fewer.shown', { total: number(visible) })}{' '}
|
||||
{needed === 1
|
||||
? t('fewer.needed-one')
|
||||
: t('fewer.needed', { total: number(needed) })}
|
||||
</Banner>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
'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 { Element } from '@lumina/island/primitives/element';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useId } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { FeaturedListPartProps } from '../types';
|
||||
|
||||
/**
|
||||
* «نمایش در صفحهها» (J11-10e), while fewer than three analysts are visible: the landing hides its
|
||||
* section, خانه and «تحلیلگران منتخب» show what's left.
|
||||
*/
|
||||
export function PageVisibility({ featured }: FeaturedListPartProps) {
|
||||
const { t } = useTranslation('featured');
|
||||
const titleId = useId();
|
||||
if (featured.landingVisible) return null;
|
||||
const cards = t('pages.cards', { total: number(featured.visibleCount) });
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag="section"
|
||||
aria-labelledby={titleId}
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
>
|
||||
<Typography tag="h2" id={titleId} variant="heading-sm" className="m-0">
|
||||
{t('pages.title')}
|
||||
</Typography>
|
||||
<GridBox gap="gap-4" className="desktop:grid-cols-3">
|
||||
<StatTile
|
||||
label={t('pages.landing')}
|
||||
icon="home"
|
||||
value={t('pages.landing-hidden')}
|
||||
valueTone="warning"
|
||||
hint={t('pages.landing-hint')}
|
||||
/>
|
||||
<StatTile
|
||||
label={t('pages.home')}
|
||||
icon="dashboard"
|
||||
value={cards}
|
||||
hint={t('pages.home-hint')}
|
||||
/>
|
||||
<StatTile
|
||||
label={t('pages.analysts')}
|
||||
icon="users"
|
||||
value={cards}
|
||||
hint={
|
||||
<Element tag="bdi" dir="ltr">
|
||||
{t('pages.analysts-path')}
|
||||
</Element>
|
||||
}
|
||||
/>
|
||||
</GridBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
'use client';
|
||||
|
||||
import { ReasonDialog } from '@lumina/garden-roof/app/screens';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { FeaturedPartProps } from '../types';
|
||||
|
||||
/**
|
||||
* «حذف از تحلیلگران منتخب» (J11-10d): who and at which place, what changes for them (nothing but
|
||||
* the slider), and «دلیل» for «گزارش ممیزی».
|
||||
*/
|
||||
export function RemoveFeaturedDialog({ model }: FeaturedPartProps) {
|
||||
const { t } = useTranslation('featured');
|
||||
const row = model.removing;
|
||||
|
||||
return (
|
||||
<ReasonDialog
|
||||
open={model.isRemoveOpen}
|
||||
onClose={model.closeRemove}
|
||||
title={t('remove.title')}
|
||||
description={
|
||||
row && (
|
||||
<Typography tag="p" variant="body-md" className="m-0">
|
||||
{row.fullName} ·{' '}
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{row.username}
|
||||
</Element>{' '}
|
||||
· {t('remove.position', { position: number(row.position) })}
|
||||
</Typography>
|
||||
)
|
||||
}
|
||||
emptyReason={t('remove.empty')}
|
||||
form={model.removeForm}
|
||||
onSubmit={model.confirmRemove}
|
||||
isSubmitting={model.isRemoving}
|
||||
confirmLabel={t('remove.confirm')}
|
||||
>
|
||||
{row && (
|
||||
<Banner tone="danger" icon="alert">
|
||||
{t('remove.impact', { name: row.fullName })}
|
||||
</Banner>
|
||||
)}
|
||||
</ReasonDialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { ActionMenu } from '@lumina/island/molecules/action-menu';
|
||||
import type { ActionMenuItem } from '@lumina/island/molecules/action-menu';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { RowMenuProps } from '../types';
|
||||
|
||||
/**
|
||||
* «بیشتر» on a row (J11-10g): «انتقال به بالا» and «انتقال به پایین», one place each, saved at once
|
||||
* like a drop. The first row has no «بالا», the last no «پایین»; a lone row has no menu.
|
||||
*/
|
||||
export function RowMenu({
|
||||
name,
|
||||
canMoveUp,
|
||||
canMoveDown,
|
||||
onMoveUp,
|
||||
onMoveDown,
|
||||
}: RowMenuProps) {
|
||||
const { t } = useTranslation('featured');
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const items: ActionMenuItem[] = [
|
||||
...(canMoveUp
|
||||
? [
|
||||
{
|
||||
label: t('table.move-up'),
|
||||
icon: 'arrow-up' as const,
|
||||
onSelect: onMoveUp,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(canMoveDown
|
||||
? [
|
||||
{
|
||||
label: t('table.move-down'),
|
||||
icon: 'arrow-down' as const,
|
||||
onSelect: onMoveDown,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
if (items.length === 0) return null;
|
||||
|
||||
return (
|
||||
<Element className="relative">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="more"
|
||||
label={t('table.more', { name })}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={isOpen}
|
||||
onClick={() => setIsOpen((open) => !open)}
|
||||
/>
|
||||
<ActionMenu
|
||||
open={isOpen}
|
||||
onClose={() => setIsOpen(false)}
|
||||
label={t('table.menu-label', { name })}
|
||||
items={items}
|
||||
/>
|
||||
</Element>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
export { AddFeaturedButton } from './components/AddFeaturedButton';
|
||||
export { FeaturedSkeleton } from './components/FeaturedSkeleton';
|
||||
export { FeaturedList } from './FeaturedList';
|
||||
export type { FeaturedListProps } from './types';
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import type {
|
||||
FeaturedCandidatePayload,
|
||||
FeaturedPageModel,
|
||||
FeaturedPayload,
|
||||
FeaturedRowModel,
|
||||
GripProps,
|
||||
} from '@lumina/garden-roof/features/featured';
|
||||
|
||||
export type FeaturedListProps = Record<string, never>;
|
||||
|
||||
export type FeaturedPartProps = { model: FeaturedPageModel };
|
||||
|
||||
export type FeaturedSkeletonProps = { label: string; delayed?: boolean };
|
||||
|
||||
export type FeaturedListPartProps = { featured: FeaturedPayload };
|
||||
|
||||
export type FeaturedRowProps = {
|
||||
row: FeaturedRowModel;
|
||||
total: number;
|
||||
grip: GripProps;
|
||||
onRemove: () => void;
|
||||
onMoveUp: () => void;
|
||||
onMoveDown: () => void;
|
||||
};
|
||||
|
||||
export type RowMenuProps = {
|
||||
name: string;
|
||||
canMoveUp: boolean;
|
||||
canMoveDown: boolean;
|
||||
onMoveUp: () => void;
|
||||
onMoveDown: () => void;
|
||||
};
|
||||
|
||||
export type AddFeaturedDialogProps = {
|
||||
open: boolean;
|
||||
featured: FeaturedPayload;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export type CandidateOptionsProps = {
|
||||
query: string;
|
||||
isPicked: (id: string) => boolean;
|
||||
onToggle: (candidate: FeaturedCandidatePayload) => void;
|
||||
};
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { AdminGuard } from '@lumina/garden-roof/app/guards';
|
||||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import {
|
||||
AddFeaturedButton,
|
||||
FeaturedList,
|
||||
FeaturedSkeleton,
|
||||
} from './organisms/featured-list';
|
||||
|
||||
export const metadata: Metadata = { title: i18n.t('featured:page.meta-title') };
|
||||
|
||||
/**
|
||||
* تحلیلگران منتخب (J11-10): the title, what the order drives and «افزودن تحلیلگر» on the server;
|
||||
* the list in the browser once the admin is known (0062).
|
||||
*/
|
||||
export default function FeaturedPage() {
|
||||
const skeleton = <FeaturedSkeleton label={i18n.t('featured:page.loading')} />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={i18n.t('featured:page.title')}
|
||||
subtitle={i18n.t('featured:page.subtitle')}
|
||||
actions={<AddFeaturedButton label={i18n.t('featured:page.add')} />}
|
||||
/>
|
||||
<AdminGuard fallback={skeleton}>
|
||||
<PartBoundary
|
||||
name="featured"
|
||||
description={i18n.t('featured:page.error')}
|
||||
>
|
||||
<Suspense fallback={skeleton}>
|
||||
<FeaturedList />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</AdminGuard>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import {
|
||||
BetaHealthSkeleton,
|
||||
BetaSubtitle,
|
||||
BetaUpdatedAt,
|
||||
} from './organisms/beta-health';
|
||||
|
||||
/** The main tab before it arrives: its header over the parts' skeletons. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={i18n.t('health:title')}
|
||||
subtitle={<BetaSubtitle />}
|
||||
actions={<BetaUpdatedAt />}
|
||||
/>
|
||||
<BetaHealthSkeleton tab="main" delayed />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
'use client';
|
||||
|
||||
import { useBetaHealthPage } from '@lumina/garden-roof/features/health';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
|
||||
import { HealthTabs } from './components/HealthTabs';
|
||||
import { MainParts } from './components/MainParts';
|
||||
import { NotScheduled } from './components/NotScheduled';
|
||||
import { PreLaunch } from './components/PreLaunch';
|
||||
import { SecondaryParts } from './components/SecondaryParts';
|
||||
import type { BetaHealthProps } from './types';
|
||||
|
||||
/**
|
||||
* سلامت بتا (J11-1, J11-1b): the tabs over the route's parts, each part on its own read; before
|
||||
* the first day, the pre-launch state in their place (J11-1c), and without a start date the
|
||||
* configuration state.
|
||||
*/
|
||||
export function BetaHealth({ tab }: BetaHealthProps) {
|
||||
const model = useBetaHealthPage();
|
||||
|
||||
if (!model.overview) return <NotScheduled />;
|
||||
if (model.isUpcoming) return <PreLaunch />;
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6">
|
||||
<HealthTabs tab={tab} />
|
||||
{tab === 'main' ? (
|
||||
<MainParts overview={model.overview} />
|
||||
) : (
|
||||
<SecondaryParts />
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
'use client';
|
||||
|
||||
import { useFunnelPart } from '@lumina/garden-roof/features/health';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { FunnelMeters } from './FunnelMeters';
|
||||
import { HealthPanel } from './HealthPanel';
|
||||
|
||||
/** «قیف آمادهسازی تحلیلگر» (J11-1b): documents sent, verified, first prediction published (J2). */
|
||||
export function AnalystFunnel() {
|
||||
const { t } = useTranslation('health');
|
||||
const funnel = useFunnelPart('analyst');
|
||||
|
||||
return (
|
||||
<HealthPanel
|
||||
title={t('analyst-funnel.title')}
|
||||
caption={t('analyst-funnel.caption')}
|
||||
>
|
||||
<FunnelMeters funnel={funnel} />
|
||||
</HealthPanel>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
'use client';
|
||||
|
||||
import { SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { PartSkeletonProps } from '../types';
|
||||
import { HealthPanel } from './HealthPanel';
|
||||
import { MeterSkeletons } from './MeterSkeletons';
|
||||
|
||||
/** The analyst funnel before it arrives (J11-1b): three bars in its real card. */
|
||||
export function AnalystFunnelSkeleton({ delayed }: PartSkeletonProps) {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<HealthPanel
|
||||
title={t('analyst-funnel.title')}
|
||||
caption={t('analyst-funnel.caption')}
|
||||
>
|
||||
<SkeletonRegion
|
||||
label={t('analyst-funnel.loading')}
|
||||
delayed={delayed}
|
||||
className="gap-4"
|
||||
>
|
||||
<MeterSkeletons count={3} />
|
||||
</SkeletonRegion>
|
||||
</HealthPanel>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
'use client';
|
||||
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { PartSkeletonProps } from '../types';
|
||||
import { HealthSection } from './HealthSection';
|
||||
|
||||
/** The analysts table before it arrives (J11-1 States: table): five rows of five columns. */
|
||||
export function AnalystsSkeleton({ delayed }: PartSkeletonProps) {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<HealthSection
|
||||
title={t('analysts.title')}
|
||||
caption={<Skeleton className="inline-block w-56 align-middle" />}
|
||||
>
|
||||
<SkeletonPreset
|
||||
preset="table"
|
||||
columns={5}
|
||||
count={5}
|
||||
label={t('analysts.loading')}
|
||||
delayed={delayed}
|
||||
/>
|
||||
</HealthSection>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
'use client';
|
||||
|
||||
import { useBetaAnalystsPart } from '@lumina/garden-roof/features/health';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Meter } from '@lumina/island/molecules/meter';
|
||||
import { PersonSummary } from '@lumina/island/molecules/person-summary';
|
||||
import { DataTable } from '@lumina/island/organisms/data-table';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { compactPercent } from '../utils';
|
||||
import { HealthSection } from './HealthSection';
|
||||
|
||||
/**
|
||||
* «تحلیلگران بتا» (J11-1): the beta's analysts, most paid subscribers first, with what an inactive
|
||||
* one lacks under the name, the invite code's seats (amber when full) and the payment completion.
|
||||
* Desktop only: on a phone the table scrolls sideways (0063).
|
||||
*/
|
||||
export function BetaAnalysts() {
|
||||
const { t } = useTranslation('health');
|
||||
const part = useBetaAnalystsPart();
|
||||
|
||||
return (
|
||||
<HealthSection
|
||||
title={t('analysts.title')}
|
||||
caption={t('analysts.caption', {
|
||||
total: number(part.total),
|
||||
active: number(part.active),
|
||||
})}
|
||||
>
|
||||
<Element className="overflow-x-auto">
|
||||
<DataTable label={t('analysts.table-label')}>
|
||||
<DataTable.Head>
|
||||
<DataTable.HeaderCell>
|
||||
{t('analysts.columns.analyst')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('analysts.columns.paid')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('analysts.columns.predictions')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('analysts.columns.capacity')}
|
||||
</DataTable.HeaderCell>
|
||||
<DataTable.HeaderCell>
|
||||
{t('analysts.columns.completion')}
|
||||
</DataTable.HeaderCell>
|
||||
</DataTable.Head>
|
||||
<DataTable.Body>
|
||||
{part.rows.map((row) => (
|
||||
<DataTable.Row key={row.id}>
|
||||
<DataTable.Cell>
|
||||
<PersonSummary
|
||||
name={row.fullName}
|
||||
username={row.username}
|
||||
avatarSrc={row.avatarUrl}
|
||||
meta={
|
||||
row.inactiveReason
|
||||
? t(`analysts.inactive.${row.inactiveReason}`)
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>{number(row.paidSubscribers)}</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
{number(row.publishedPredictions)}
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
{row.code ? (
|
||||
<Element className="w-32">
|
||||
<Meter
|
||||
value={row.code.used}
|
||||
max={row.code.max}
|
||||
tone={row.code.isFull ? 'warning' : 'brand'}
|
||||
label={t('analysts.capacity', {
|
||||
used: number(row.code.used),
|
||||
max: number(row.code.max),
|
||||
})}
|
||||
/>
|
||||
</Element>
|
||||
) : (
|
||||
t('analysts.no-code')
|
||||
)}
|
||||
</DataTable.Cell>
|
||||
<DataTable.Cell>
|
||||
{row.payments.rate == null ? (
|
||||
t('none')
|
||||
) : (
|
||||
<>
|
||||
{compactPercent(row.payments.rate)}{' '}
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="caption"
|
||||
color="secondary"
|
||||
>
|
||||
{t('analysts.completion-basis', {
|
||||
completed: number(row.payments.completed),
|
||||
started: number(row.payments.started),
|
||||
})}
|
||||
</Typography>
|
||||
</>
|
||||
)}
|
||||
</DataTable.Cell>
|
||||
</DataTable.Row>
|
||||
))}
|
||||
</DataTable.Body>
|
||||
</DataTable>
|
||||
</Element>
|
||||
</HealthSection>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
|
||||
import type { BetaHealthSkeletonProps } from '../types';
|
||||
import { AnalystFunnelSkeleton } from './AnalystFunnelSkeleton';
|
||||
import { AnalystsSkeleton } from './AnalystsSkeleton';
|
||||
import { ExitSkeleton } from './ExitSkeleton';
|
||||
import { FunnelSkeleton } from './FunnelSkeleton';
|
||||
import { HealthTabs } from './HealthTabs';
|
||||
import { SecondarySkeleton } from './SecondarySkeleton';
|
||||
|
||||
/**
|
||||
* The tab before the admin and the overview are known: the live tabs over every part's own
|
||||
* skeleton, so nothing moves when the parts arrive.
|
||||
*/
|
||||
export function BetaHealthSkeleton({ tab, delayed }: BetaHealthSkeletonProps) {
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-6">
|
||||
<HealthTabs tab={tab} />
|
||||
{tab === 'main' ? (
|
||||
<>
|
||||
<ExitSkeleton delayed={delayed} />
|
||||
<FunnelSkeleton delayed={delayed} />
|
||||
<AnalystsSkeleton delayed={delayed} />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<SecondarySkeleton delayed={delayed} />
|
||||
<AnalystFunnelSkeleton delayed={delayed} />
|
||||
</>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
'use client';
|
||||
|
||||
import { useBetaHeader } from '@lumina/garden-roof/features/health';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { date, number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { betaRange } from '../utils';
|
||||
|
||||
/**
|
||||
* The header's line under «سلامت بتا» (J11-1): «روز ۱۸ از ۳۰ · بتای بسته از …», or the start date
|
||||
* before the beta (J11-1c). Inline, since it sits in the header's paragraph.
|
||||
*/
|
||||
export function BetaSubtitle() {
|
||||
const { t } = useTranslation('health');
|
||||
const { overview, isLoading } = useBetaHeader();
|
||||
|
||||
if (isLoading) {
|
||||
return <Skeleton className="inline-block w-80 align-middle" />;
|
||||
}
|
||||
if (!overview) return null;
|
||||
if (overview.phase === 'upcoming') {
|
||||
return t('subtitle-upcoming', {
|
||||
start: date(overview.startsAt, { time: false }),
|
||||
});
|
||||
}
|
||||
return t('subtitle', {
|
||||
day: number(overview.day),
|
||||
total: number(overview.totalDays),
|
||||
...betaRange(overview.startsAt, overview.endsAt),
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
'use client';
|
||||
|
||||
import { DetailRow } from '@lumina/island/molecules/detail-row';
|
||||
import { KeyValue } from '@lumina/island/molecules/key-value';
|
||||
import { Meter } from '@lumina/island/molecules/meter';
|
||||
import { date, number, percent } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { BetaTimelineProps } from '../types';
|
||||
import { HealthPanel } from './HealthPanel';
|
||||
|
||||
/**
|
||||
* «زمانبندی بتا» (J11-1): the day of 30 with the days left, the dates, the analysts, and the
|
||||
* investors and whole-funnel conversion from the funnel beside it.
|
||||
*/
|
||||
export function BetaTimeline({ overview, funnel }: BetaTimelineProps) {
|
||||
const { t } = useTranslation('health');
|
||||
const registered = funnel.steps.find(
|
||||
(step) => step.event === 'register_done',
|
||||
)?.count;
|
||||
|
||||
return (
|
||||
<HealthPanel title={t('timeline.title')}>
|
||||
<Meter
|
||||
label={t('timeline.day', {
|
||||
day: number(overview.day),
|
||||
total: number(overview.totalDays),
|
||||
})}
|
||||
caption={t('timeline.days-left', { days: number(overview.daysLeft) })}
|
||||
value={overview.day}
|
||||
max={overview.totalDays}
|
||||
/>
|
||||
<KeyValue>
|
||||
<DetailRow label={t('timeline.start')}>
|
||||
{date(overview.startsAt, { time: false })}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('timeline.end')}>
|
||||
{date(overview.endsAt, { time: false })}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('timeline.analysts')}>
|
||||
{t('timeline.analysts-value', {
|
||||
total: number(overview.analysts),
|
||||
active: number(overview.activeAnalysts),
|
||||
})}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('timeline.investors')}>
|
||||
{registered == null
|
||||
? t('none')
|
||||
: t('timeline.investors-value', { people: number(registered) })}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('timeline.conversion')} strong>
|
||||
{funnel.overall == null ? t('none') : percent(funnel.overall, 1)}
|
||||
</DetailRow>
|
||||
</KeyValue>
|
||||
</HealthPanel>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
'use client';
|
||||
|
||||
import { useBetaHeader } from '@lumina/garden-roof/features/health';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { date, time } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
/**
|
||||
* «بهروزرسانی: ۱۰ مهر ۱۴۰۵، ۱۱:۳۰» at the header's end (J11-1): when the API last computed the
|
||||
* metrics, which moves every 5 minutes. None before the beta starts (J11-1c).
|
||||
*/
|
||||
export function BetaUpdatedAt() {
|
||||
const { t } = useTranslation('health');
|
||||
const { overview, isLoading } = useBetaHeader();
|
||||
|
||||
if (isLoading) return <Skeleton className="w-40" />;
|
||||
if (!overview || overview.phase === 'upcoming') return null;
|
||||
return (
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
{t('updated', {
|
||||
date: date(overview.updatedAt, { time: false }),
|
||||
time: time(overview.updatedAt),
|
||||
})}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
'use client';
|
||||
|
||||
import { useExitMetricsPart } from '@lumina/garden-roof/features/health';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { EXIT_GRID } from '../constants';
|
||||
import { ExitTile } from './ExitTile';
|
||||
import { HealthSection } from './HealthSection';
|
||||
|
||||
/** «شاخصهای خروج از فاز ۰» (J11-1): the four metrics phase 0 exits on, each against its target. */
|
||||
export function ExitMetrics() {
|
||||
const { t } = useTranslation('health');
|
||||
const part = useExitMetricsPart();
|
||||
|
||||
return (
|
||||
<HealthSection title={t('exit.title')} caption={t('exit.caption')}>
|
||||
<GridBox cols="grid-cols-1" gap="gap-4" className={EXIT_GRID}>
|
||||
{part.metrics.map((metric) => (
|
||||
<ExitTile key={metric.key} metric={metric} day={part.day} />
|
||||
))}
|
||||
</GridBox>
|
||||
</HealthSection>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
'use client';
|
||||
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { EXIT_GRID } from '../constants';
|
||||
import type { PartSkeletonProps } from '../types';
|
||||
import { HealthSection } from './HealthSection';
|
||||
import { TileSkeleton } from './TileSkeleton';
|
||||
|
||||
/** The exit tiles before they arrive (J11-1 States: figure), under their real heading. */
|
||||
export function ExitSkeleton({ delayed }: PartSkeletonProps) {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<HealthSection title={t('exit.title')} caption={t('exit.caption')}>
|
||||
<SkeletonRegion label={t('exit.loading')} delayed={delayed}>
|
||||
<GridBox cols="grid-cols-1" gap="gap-4" className={EXIT_GRID}>
|
||||
{[0, 1, 2, 3].map((index) => (
|
||||
<TileSkeleton key={index} progress />
|
||||
))}
|
||||
</GridBox>
|
||||
</SkeletonRegion>
|
||||
</HealthSection>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { StatusBadge } from '@lumina/island/atoms/status-badge';
|
||||
import { Meter } from '@lumina/island/molecules/meter';
|
||||
import { StatTile } from '@lumina/island/molecules/stat-tile';
|
||||
import { number, percent } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { EXIT_FORMATS } from '../constants';
|
||||
import type { ExitTileProps } from '../types';
|
||||
|
||||
/**
|
||||
* One exit metric (DS StatTile with progress): the value over its end-of-beta target, the bar in
|
||||
* the status hue, then today's expectation (cumulative), the counts behind a percentage, or the
|
||||
* target, and «در مسیر» / «عقبتر از هدف».
|
||||
*/
|
||||
export function ExitTile({ metric, day }: ExitTileProps) {
|
||||
const { t } = useTranslation('health');
|
||||
const format = EXIT_FORMATS[metric.key];
|
||||
const write = (value: number, decimals = format.decimals) =>
|
||||
format.percent ? percent(value, 0) : number(value, decimals);
|
||||
const label = t(`exit.labels.${metric.key}`);
|
||||
const value = t('exit.value', {
|
||||
value: write(metric.value),
|
||||
target: write(metric.target, 0),
|
||||
});
|
||||
const onTrack = metric.status === 'on_track';
|
||||
const hint =
|
||||
metric.expected != null
|
||||
? t('exit.expected', {
|
||||
day: number(day),
|
||||
expected: write(metric.expected),
|
||||
})
|
||||
: metric.basis
|
||||
? t('exit.basis', {
|
||||
part: number(metric.basis.count),
|
||||
whole: number(metric.basis.of),
|
||||
})
|
||||
: t('exit.target-analysts', { target: number(metric.target) });
|
||||
|
||||
return (
|
||||
<StatTile
|
||||
label={label}
|
||||
value={value}
|
||||
hint={hint}
|
||||
footer={
|
||||
<FlexBox>
|
||||
<StatusBadge
|
||||
tone={onTrack ? 'success' : 'warning'}
|
||||
icon={onTrack ? 'check' : 'alert'}
|
||||
>
|
||||
{t(`exit.status.${metric.status}`)}
|
||||
</StatusBadge>
|
||||
</FlexBox>
|
||||
}
|
||||
>
|
||||
<Meter
|
||||
value={metric.value}
|
||||
max={metric.target}
|
||||
tone={onTrack ? 'success' : 'warning'}
|
||||
ariaLabel={label}
|
||||
valueText={value}
|
||||
/>
|
||||
</StatTile>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
'use client';
|
||||
|
||||
import { Meter } from '@lumina/island/molecules/meter';
|
||||
import { number, percent } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { FunnelMetersProps } from '../types';
|
||||
|
||||
/**
|
||||
* A funnel's steps as bars against its first step (J11-1, J11-1b): «۴۱۲ نفر · ۳۳٫۲٪», each percent
|
||||
* of the last known step before, and those still under review where ops hold a step. A step
|
||||
* nothing records yet reads «—».
|
||||
*/
|
||||
export function FunnelMeters({ funnel }: FunnelMetersProps) {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<>
|
||||
{funnel.steps.map((step) => {
|
||||
const label = t(`funnel.events.${step.event}`);
|
||||
// Nothing records this step yet: «—» over an empty bar, so the rows keep their widths.
|
||||
if (step.count == null) {
|
||||
return (
|
||||
<Meter
|
||||
key={step.event}
|
||||
label={label}
|
||||
caption={t('none')}
|
||||
value={0}
|
||||
max={Math.max(funnel.top, 1)}
|
||||
valueText={t('funnel.not-recorded')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
const people = number(step.count);
|
||||
const caption =
|
||||
step.conversion == null
|
||||
? t('funnel.people', { people })
|
||||
: t('funnel.people-rate', {
|
||||
people,
|
||||
rate: percent(step.conversion, 1),
|
||||
});
|
||||
return (
|
||||
<Meter
|
||||
key={step.event}
|
||||
label={label}
|
||||
caption={
|
||||
step.awaitingReview
|
||||
? `${caption} · ${t('funnel.awaiting', {
|
||||
waiting: number(step.awaitingReview),
|
||||
})}`
|
||||
: caption
|
||||
}
|
||||
value={step.count}
|
||||
max={Math.max(funnel.top, 1)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
'use client';
|
||||
|
||||
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 { useTranslation } from 'react-i18next';
|
||||
|
||||
import { PAIR_GRID } from '../constants';
|
||||
import type { PartSkeletonProps } from '../types';
|
||||
import { HealthPanel } from './HealthPanel';
|
||||
import { MeterSkeletons } from './MeterSkeletons';
|
||||
|
||||
/**
|
||||
* The funnel and the timeline before they arrive (J11-1 States: list): five bars, and the day's
|
||||
* bar over five key–value rows, in their real cards.
|
||||
*/
|
||||
export function FunnelSkeleton({ delayed }: PartSkeletonProps) {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<GridBox
|
||||
cols="grid-cols-1"
|
||||
gap="gap-4"
|
||||
alignItems="items-start"
|
||||
className={PAIR_GRID}
|
||||
>
|
||||
<HealthPanel title={t('funnel.title')} caption={t('funnel.caption')}>
|
||||
<SkeletonRegion
|
||||
label={t('funnel.loading')}
|
||||
delayed={delayed}
|
||||
className="gap-4"
|
||||
>
|
||||
<MeterSkeletons count={5} />
|
||||
</SkeletonRegion>
|
||||
</HealthPanel>
|
||||
<HealthPanel title={t('timeline.title')}>
|
||||
<MeterSkeletons count={1} />
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
className="divide-y divide-border-subtle"
|
||||
aria-hidden
|
||||
>
|
||||
{[0, 1, 2, 3, 4].map((index) => (
|
||||
<FlexBox
|
||||
key={index}
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-between"
|
||||
className="box-content h-6.5 py-2"
|
||||
>
|
||||
<Skeleton className="w-24" />
|
||||
<Skeleton className={index % 2 ? 'w-20' : 'w-28'} />
|
||||
</FlexBox>
|
||||
))}
|
||||
</FlexBox>
|
||||
</HealthPanel>
|
||||
</GridBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
|
||||
import type { HealthSectionProps } from '../types';
|
||||
import { SectionHeading } from './SectionHeading';
|
||||
|
||||
/** A titled part in a card (DS `lm-panel lm-stack--lg`), such as a funnel or the timeline. */
|
||||
export function HealthPanel({ title, caption, children }: HealthSectionProps) {
|
||||
return (
|
||||
<Card tag="section" aria-label={title} className="min-w-0">
|
||||
<FlexBox direction="flex-col" gap="gap-4">
|
||||
<SectionHeading title={title} caption={caption} />
|
||||
{children}
|
||||
</FlexBox>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
|
||||
import type { HealthSectionProps } from '../types';
|
||||
import { SectionHeading } from './SectionHeading';
|
||||
|
||||
/** A titled part on the page's ground (DS `lm-stack`), such as the exit tiles or the table. */
|
||||
export function HealthSection({
|
||||
title,
|
||||
caption,
|
||||
children,
|
||||
}: HealthSectionProps) {
|
||||
return (
|
||||
<FlexBox
|
||||
tag="section"
|
||||
aria-label={title}
|
||||
direction="flex-col"
|
||||
gap="gap-3"
|
||||
className="min-w-0"
|
||||
>
|
||||
<SectionHeading title={title} caption={caption} />
|
||||
{children}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
'use client';
|
||||
|
||||
import { ROUTES } from '@lumina/garden-roof/app/navigation';
|
||||
import { HEALTH_TABS } from '@lumina/garden-roof/features/health';
|
||||
import type { HealthTab } from '@lumina/garden-roof/features/health';
|
||||
import { TabLinks } from '@lumina/island/molecules/tab-links';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { HealthTabsProps } from '../types';
|
||||
|
||||
const TAB_ROUTES: Record<HealthTab, string> = {
|
||||
main: ROUTES.health,
|
||||
secondary: ROUTES.healthSecondary,
|
||||
};
|
||||
|
||||
/** «شاخصهای اصلی» · «شاخصهای ثانویه» (J11-1): each tab its own route. */
|
||||
export function HealthTabs({ tab }: HealthTabsProps) {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<TabLinks
|
||||
label={t('tabs-label')}
|
||||
items={HEALTH_TABS.map((item) => ({
|
||||
href: TAB_ROUTES[item],
|
||||
label: t(`tabs.${item}`),
|
||||
isActive: item === tab,
|
||||
}))}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
'use client';
|
||||
|
||||
import { useFunnelPart } from '@lumina/garden-roof/features/health';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { PAIR_GRID } from '../constants';
|
||||
import type { MainPartsProps } from '../types';
|
||||
import { BetaTimeline } from './BetaTimeline';
|
||||
import { FunnelMeters } from './FunnelMeters';
|
||||
import { HealthPanel } from './HealthPanel';
|
||||
|
||||
/**
|
||||
* «قیف بازدیدکننده تا سرمایهگذار» beside «زمانبندی بتا» (J11-1): one part, since the timeline's
|
||||
* investors and conversion come from the funnel's read.
|
||||
*/
|
||||
export function InvestorFunnel({ overview }: MainPartsProps) {
|
||||
const { t } = useTranslation('health');
|
||||
const funnel = useFunnelPart('investor');
|
||||
|
||||
return (
|
||||
<GridBox
|
||||
cols="grid-cols-1"
|
||||
gap="gap-4"
|
||||
alignItems="items-start"
|
||||
className={PAIR_GRID}
|
||||
>
|
||||
<HealthPanel title={t('funnel.title')} caption={t('funnel.caption')}>
|
||||
<FunnelMeters funnel={funnel} />
|
||||
</HealthPanel>
|
||||
<BetaTimeline overview={overview} funnel={funnel} />
|
||||
</GridBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
'use client';
|
||||
|
||||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { Suspense } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { MainPartsProps } from '../types';
|
||||
import { AnalystsSkeleton } from './AnalystsSkeleton';
|
||||
import { BetaAnalysts } from './BetaAnalysts';
|
||||
import { ExitMetrics } from './ExitMetrics';
|
||||
import { ExitSkeleton } from './ExitSkeleton';
|
||||
import { FunnelSkeleton } from './FunnelSkeleton';
|
||||
import { InvestorFunnel } from './InvestorFunnel';
|
||||
|
||||
/**
|
||||
* «شاخصهای اصلی» (J11-1): the exit metrics, the funnel with the timeline, and the analysts, each
|
||||
* loading behind its own skeleton and failing alone («A failed section errors alone»).
|
||||
*/
|
||||
export function MainParts({ overview }: MainPartsProps) {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<>
|
||||
<PartBoundary
|
||||
name="beta-health-exit"
|
||||
description={t('exit.error')}
|
||||
framed
|
||||
>
|
||||
<Suspense fallback={<ExitSkeleton />}>
|
||||
<ExitMetrics />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
<PartBoundary
|
||||
name="beta-health-funnel"
|
||||
description={t('funnel.error')}
|
||||
framed
|
||||
>
|
||||
<Suspense fallback={<FunnelSkeleton />}>
|
||||
<InvestorFunnel overview={overview} />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
<PartBoundary
|
||||
name="beta-health-analysts"
|
||||
description={t('analysts.error')}
|
||||
framed
|
||||
>
|
||||
<Suspense fallback={<AnalystsSkeleton />}>
|
||||
<BetaAnalysts />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
|
||||
import type { MeterSkeletonsProps } from '../types';
|
||||
|
||||
/** Meters before they arrive: the label and caption row over the 8px bar, 16px apart. */
|
||||
export function MeterSkeletons({ count }: MeterSkeletonsProps) {
|
||||
return Array.from({ length: count }, (_, index) => (
|
||||
// Static placeholders that never reorder, so the index is a stable key.
|
||||
<FlexBox key={index} direction="flex-col" className="gap-1.5" aria-hidden>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-between"
|
||||
className="h-5.5"
|
||||
>
|
||||
<Skeleton className={index % 2 ? 'w-24' : 'w-32'} />
|
||||
<Skeleton className="w-20" />
|
||||
</FlexBox>
|
||||
<Skeleton shape="pill" className="h-2 w-full" />
|
||||
</FlexBox>
|
||||
));
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { EmptyState } from '@lumina/island/molecules/empty-state';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
/**
|
||||
* The beta has no start date yet (503 BETA_NOT_SCHEDULED on every part): a configuration state,
|
||||
* not an error, in the pre-launch state's panel that fills the column.
|
||||
*/
|
||||
export function NotScheduled() {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag={Card}
|
||||
padding="none"
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-center"
|
||||
className="flex-1"
|
||||
>
|
||||
<EmptyState
|
||||
tone="neutral"
|
||||
icon="calendar"
|
||||
size="page"
|
||||
title={t('not-scheduled.title')}
|
||||
description={t('not-scheduled.description')}
|
||||
/>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
'use client';
|
||||
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
import { EmptyState } from '@lumina/island/molecules/empty-state';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
/**
|
||||
* Before the beta's first day (J11-1c): no tabs and no figures, only «هنوز دادهای نیست» in a
|
||||
* panel that fills the column.
|
||||
*/
|
||||
export function PreLaunch() {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag={Card}
|
||||
padding="none"
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-center"
|
||||
className="flex-1"
|
||||
>
|
||||
<EmptyState
|
||||
tone="brand"
|
||||
icon="dashboard"
|
||||
size="page"
|
||||
title={t('upcoming.title')}
|
||||
description={t('upcoming.description')}
|
||||
/>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
'use client';
|
||||
|
||||
import { useSecondaryMetricsPart } from '@lumina/garden-roof/features/health';
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { StatTile } from '@lumina/island/molecules/stat-tile';
|
||||
import { number, percent } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SECONDARY_GRID } from '../constants';
|
||||
import { HealthSection } from './HealthSection';
|
||||
|
||||
/**
|
||||
* «شاخصهای ثانویه» (J11-1b): onboarding time, month-one churn, payment completion, prediction
|
||||
* pace and track-record views, each with what it is made of; «—» while there is nothing to divide.
|
||||
*/
|
||||
export function SecondaryMetrics() {
|
||||
const { t } = useTranslation('health');
|
||||
const part = useSecondaryMetricsPart();
|
||||
const { monthOneChurn: churn, paymentCompletion: completion } = part;
|
||||
const pace = part.predictionPace;
|
||||
|
||||
return (
|
||||
<HealthSection
|
||||
title={t('secondary.title')}
|
||||
caption={t('secondary.caption')}
|
||||
>
|
||||
<GridBox cols="grid-cols-1" gap="gap-4" className={SECONDARY_GRID}>
|
||||
<StatTile
|
||||
icon="clock"
|
||||
label={t('secondary.onboarding.label')}
|
||||
value={
|
||||
part.onboardingMedianDays == null
|
||||
? t('none')
|
||||
: t('secondary.onboarding.value', {
|
||||
days: number(part.onboardingMedianDays, 1),
|
||||
})
|
||||
}
|
||||
hint={t('secondary.onboarding.hint')}
|
||||
/>
|
||||
<StatTile
|
||||
icon="trend-down"
|
||||
label={t('secondary.churn.label')}
|
||||
value={churn.rate == null ? t('none') : percent(churn.rate, 0)}
|
||||
hint={t('secondary.churn.hint', {
|
||||
lapsed: number(churn.part),
|
||||
due: number(churn.whole),
|
||||
})}
|
||||
/>
|
||||
<StatTile
|
||||
icon="wallet"
|
||||
label={t('secondary.completion.label')}
|
||||
value={
|
||||
completion.rate == null ? t('none') : percent(completion.rate, 1)
|
||||
}
|
||||
hint={t('secondary.completion.hint', {
|
||||
completed: number(completion.part),
|
||||
started: number(completion.whole),
|
||||
})}
|
||||
/>
|
||||
<StatTile
|
||||
icon="target"
|
||||
label={t('secondary.pace.label')}
|
||||
value={
|
||||
pace.perAnalystMonth == null
|
||||
? t('none')
|
||||
: number(pace.perAnalystMonth, 1)
|
||||
}
|
||||
hint={t('secondary.pace.hint', {
|
||||
predictions: number(pace.predictions),
|
||||
days: number(pace.days),
|
||||
analysts: number(pace.activeAnalysts),
|
||||
})}
|
||||
/>
|
||||
<StatTile
|
||||
icon="eye"
|
||||
label={t('secondary.views.label')}
|
||||
value={
|
||||
part.trackRecordViews == null
|
||||
? t('none')
|
||||
: number(part.trackRecordViews)
|
||||
}
|
||||
hint={
|
||||
part.trackRecordViews == null
|
||||
? t('secondary.views.hint-none')
|
||||
: t('secondary.views.hint')
|
||||
}
|
||||
/>
|
||||
</GridBox>
|
||||
</HealthSection>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
'use client';
|
||||
|
||||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { Suspense } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { AnalystFunnel } from './AnalystFunnel';
|
||||
import { AnalystFunnelSkeleton } from './AnalystFunnelSkeleton';
|
||||
import { SecondaryMetrics } from './SecondaryMetrics';
|
||||
import { SecondarySkeleton } from './SecondarySkeleton';
|
||||
|
||||
/** «شاخصهای ثانویه» (J11-1b): the figures and the analyst funnel, each loading and failing alone. */
|
||||
export function SecondaryParts() {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<>
|
||||
<PartBoundary
|
||||
name="beta-health-secondary"
|
||||
description={t('secondary.error')}
|
||||
framed
|
||||
>
|
||||
<Suspense fallback={<SecondarySkeleton />}>
|
||||
<SecondaryMetrics />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
<PartBoundary
|
||||
name="beta-health-analyst-funnel"
|
||||
description={t('analyst-funnel.error')}
|
||||
framed
|
||||
>
|
||||
<Suspense fallback={<AnalystFunnelSkeleton />}>
|
||||
<AnalystFunnel />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
'use client';
|
||||
|
||||
import { GridBox } from '@lumina/island/atoms/grid-box';
|
||||
import { SkeletonRegion } from '@lumina/island/atoms/skeleton';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SECONDARY_GRID } from '../constants';
|
||||
import type { PartSkeletonProps } from '../types';
|
||||
import { HealthSection } from './HealthSection';
|
||||
import { TileSkeleton } from './TileSkeleton';
|
||||
|
||||
/** The secondary tiles before they arrive (J11-1b), under their real heading. */
|
||||
export function SecondarySkeleton({ delayed }: PartSkeletonProps) {
|
||||
const { t } = useTranslation('health');
|
||||
|
||||
return (
|
||||
<HealthSection
|
||||
title={t('secondary.title')}
|
||||
caption={t('secondary.caption')}
|
||||
>
|
||||
<SkeletonRegion label={t('secondary.loading')} delayed={delayed}>
|
||||
<GridBox cols="grid-cols-1" gap="gap-4" className={SECONDARY_GRID}>
|
||||
{[0, 1, 2, 3, 4].map((index) => (
|
||||
<TileSkeleton key={index} />
|
||||
))}
|
||||
</GridBox>
|
||||
</SkeletonRegion>
|
||||
</HealthSection>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
|
||||
import type { HealthSectionProps } from '../types';
|
||||
|
||||
/** A part's heading row (DS `lm-between`): the h2 at the start, its caption at the end. */
|
||||
export function SectionHeading({
|
||||
title,
|
||||
caption,
|
||||
}: Omit<HealthSectionProps, 'children'>) {
|
||||
return (
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-between"
|
||||
gap="gap-3"
|
||||
wrap="flex-wrap"
|
||||
className="min-w-0"
|
||||
>
|
||||
<Typography tag="h2" variant="heading-sm" className="m-0">
|
||||
{title}
|
||||
</Typography>
|
||||
{caption != null && (
|
||||
<Typography tag="span" variant="caption" color="secondary">
|
||||
{caption}
|
||||
</Typography>
|
||||
)}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Skeleton } from '@lumina/island/atoms/skeleton';
|
||||
import { Card } from '@lumina/island/molecules/card';
|
||||
|
||||
/**
|
||||
* A StatTile before it arrives, line for line: label, value, then the exit tiles' bar and badge
|
||||
* (`progress`) around the hint, so the grid lands at its height.
|
||||
*/
|
||||
export function TileSkeleton({ progress = false }: { progress?: boolean }) {
|
||||
return (
|
||||
<Card aria-hidden>
|
||||
<FlexBox direction="flex-col" className="gap-1.5">
|
||||
<FlexBox alignItems="items-center" className="h-5.5">
|
||||
<Skeleton className="w-32" />
|
||||
</FlexBox>
|
||||
<FlexBox alignItems="items-center" className="h-9">
|
||||
<Skeleton shape="rect" className="h-6 w-24" />
|
||||
</FlexBox>
|
||||
{progress && <Skeleton shape="pill" className="h-2 w-full" />}
|
||||
<FlexBox alignItems="items-center" className="h-5.5">
|
||||
<Skeleton className="w-40" />
|
||||
</FlexBox>
|
||||
{progress && <Skeleton shape="pill" className="h-6 w-24" />}
|
||||
</FlexBox>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import type { ExitMetricKey } from '@lumina/garden-roof/features/health';
|
||||
|
||||
/** The exit tiles: one column on a phone, two on a tablet, the board's four from 1024px. */
|
||||
export const EXIT_GRID = 'tablet:grid-cols-2 desktop:grid-cols-4';
|
||||
|
||||
/** The funnel and the timeline side by side from 1024px, stacked below (DS `lm-grid2`). */
|
||||
export const PAIR_GRID = 'desktop:grid-cols-2';
|
||||
|
||||
/** The secondary tiles: the board's three a row from 1024px (DS `lm-grid3`). */
|
||||
export const SECONDARY_GRID = 'tablet:grid-cols-2 desktop:grid-cols-3';
|
||||
|
||||
/**
|
||||
* How each exit metric is written (J11-1): «۴ / ۵», «۶٫۲ / ۱۰», «۷۵٪ / ۸۰٪», «۳۱ / ۵۰». `decimals`
|
||||
* is for the value and «انتظار روز ۱۸» alike; targets are whole.
|
||||
*/
|
||||
export const EXIT_FORMATS: Record<
|
||||
ExitMetricKey,
|
||||
{ decimals: number; percent: boolean }
|
||||
> = {
|
||||
active_analysts: { decimals: 0, percent: false },
|
||||
avg_paid_subscribers: { decimals: 1, percent: false },
|
||||
publishing_analysts: { decimals: 0, percent: true },
|
||||
paid_subscribers: { decimals: 0, percent: false },
|
||||
};
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
export { BetaHealth } from './BetaHealth';
|
||||
export { BetaHealthSkeleton } from './components/BetaHealthSkeleton';
|
||||
export { BetaSubtitle } from './components/BetaSubtitle';
|
||||
export { BetaUpdatedAt } from './components/BetaUpdatedAt';
|
||||
export type { BetaHealthProps, BetaHealthSkeletonProps } from './types';
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import type {
|
||||
BetaOverviewPayload,
|
||||
ExitMetricPayload,
|
||||
FunnelPayload,
|
||||
HealthTab,
|
||||
} from '@lumina/garden-roof/features/health';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
export type BetaHealthProps = {
|
||||
/** The tab this route is: «شاخصهای اصلی» or «شاخصهای ثانویه». */
|
||||
tab: HealthTab;
|
||||
};
|
||||
|
||||
export type BetaHealthSkeletonProps = BetaHealthProps & {
|
||||
/** In loading.tsx only: fades in after 300ms. */
|
||||
delayed?: boolean;
|
||||
};
|
||||
|
||||
export type HealthTabsProps = BetaHealthProps;
|
||||
|
||||
export type PartSkeletonProps = { delayed?: boolean };
|
||||
|
||||
export type MainPartsProps = { overview: BetaOverviewPayload };
|
||||
|
||||
export type HealthSectionProps = {
|
||||
title: string;
|
||||
/** At the end of the heading row, such as «مقدار فعلی / هدف پایان بتا». */
|
||||
caption?: ReactNode;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export type ExitTileProps = { metric: ExitMetricPayload; day: number };
|
||||
|
||||
export type FunnelMetersProps = { funnel: FunnelPayload };
|
||||
|
||||
export type BetaTimelineProps = {
|
||||
overview: BetaOverviewPayload;
|
||||
funnel: FunnelPayload;
|
||||
};
|
||||
|
||||
export type MeterSkeletonsProps = { count: number };
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { date, LOCALE, percent, TIME_ZONE } from '@lumina/tools/format';
|
||||
|
||||
const dayMonthFormatter = new Intl.DateTimeFormat(LOCALE, {
|
||||
timeZone: TIME_ZONE,
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
});
|
||||
const yearFormatter = new Intl.DateTimeFormat(LOCALE, {
|
||||
timeZone: TIME_ZONE,
|
||||
year: 'numeric',
|
||||
});
|
||||
|
||||
/** «۲۴ شهریور» … «۲۲ مهر ۱۴۰۵»: the start drops its year when the end is in the same one (J11-1). */
|
||||
export function betaRange(
|
||||
startsAt: string,
|
||||
endsAt: string,
|
||||
): { start: string; end: string } {
|
||||
const start = new Date(startsAt);
|
||||
const end = new Date(endsAt);
|
||||
return {
|
||||
start:
|
||||
yearFormatter.format(start) === yearFormatter.format(end)
|
||||
? dayMonthFormatter.format(start)
|
||||
: date(start, { time: false }),
|
||||
end: date(end, { time: false }),
|
||||
};
|
||||
}
|
||||
|
||||
/** `80` → «۸۰٪», `81.82` → «۸۱٫۸٪»: one decimal, dropped when it's 0, as the table writes rates. */
|
||||
export function compactPercent(value: number): string {
|
||||
const rounded = Math.round(value * 10) / 10;
|
||||
return percent(rounded, Number.isInteger(rounded) ? 0 : 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { AdminGuard } from '@lumina/garden-roof/app/guards';
|
||||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import {
|
||||
BetaHealth,
|
||||
BetaHealthSkeleton,
|
||||
BetaSubtitle,
|
||||
BetaUpdatedAt,
|
||||
} from './organisms/beta-health';
|
||||
|
||||
export const metadata: Metadata = { title: i18n.t('health:meta-title') };
|
||||
|
||||
/**
|
||||
* سلامت بتا · شاخصهای اصلی (J11-1): the title on the server, with the beta's day and update time
|
||||
* filled in the browser; the parts once the admin is known (0062). The overview decides between
|
||||
* the parts and the pre-launch state, so its failure is the page's.
|
||||
*/
|
||||
export default function HealthPage() {
|
||||
const skeleton = <BetaHealthSkeleton tab="main" />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={i18n.t('health:title')}
|
||||
subtitle={<BetaSubtitle />}
|
||||
actions={<BetaUpdatedAt />}
|
||||
/>
|
||||
<AdminGuard fallback={skeleton}>
|
||||
<PartBoundary
|
||||
name="beta-health"
|
||||
description={i18n.t('health:error')}
|
||||
size="page"
|
||||
>
|
||||
<Suspense fallback={skeleton}>
|
||||
<BetaHealth tab="main" />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</AdminGuard>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import {
|
||||
BetaHealthSkeleton,
|
||||
BetaSubtitle,
|
||||
BetaUpdatedAt,
|
||||
} from '../organisms/beta-health';
|
||||
|
||||
/** The secondary tab before it arrives: its header over the parts' skeletons. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={i18n.t('health:title')}
|
||||
subtitle={<BetaSubtitle />}
|
||||
actions={<BetaUpdatedAt />}
|
||||
/>
|
||||
<BetaHealthSkeleton tab="secondary" delayed />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { AdminGuard } from '@lumina/garden-roof/app/guards';
|
||||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
import type { Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
|
||||
import { i18n } from '../../../../i18n';
|
||||
import {
|
||||
BetaHealth,
|
||||
BetaHealthSkeleton,
|
||||
BetaSubtitle,
|
||||
BetaUpdatedAt,
|
||||
} from '../organisms/beta-health';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: i18n.t('health:meta-title-secondary'),
|
||||
};
|
||||
|
||||
/**
|
||||
* سلامت بتا · شاخصهای ثانویه (J11-1b): the same header and tabs as the main tab, over the
|
||||
* secondary figures and the analyst funnel, each on its own read (0062).
|
||||
*/
|
||||
export default function HealthSecondaryPage() {
|
||||
const skeleton = <BetaHealthSkeleton tab="secondary" />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={i18n.t('health:title')}
|
||||
subtitle={<BetaSubtitle />}
|
||||
actions={<BetaUpdatedAt />}
|
||||
/>
|
||||
<AdminGuard fallback={skeleton}>
|
||||
<PartBoundary
|
||||
name="beta-health"
|
||||
description={i18n.t('health:error')}
|
||||
size="page"
|
||||
>
|
||||
<Suspense fallback={skeleton}>
|
||||
<BetaHealth tab="secondary" />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
</AdminGuard>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { PageHeader } from '@lumina/island/molecules/page-header';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import { i18n } from '../../../i18n';
|
||||
import { CodesSearch, CodesTabs } from './organisms/codes-header';
|
||||
|
||||
/**
|
||||
* کدهای دعوت (J11-6, 6d): the title and its search on the server's header, then «همه کدها» ·
|
||||
* «درخواستهای افزایش»; both tabs keep this frame, so the search stays put between them.
|
||||
*/
|
||||
export default function InviteCodesLayout({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={i18n.t('codes:header.title')}
|
||||
subtitle={i18n.t('codes:header.subtitle')}
|
||||
actions={<CodesSearch />}
|
||||
/>
|
||||
<CodesTabs />
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { i18n } from '../../../i18n';
|
||||
import { TableSkeleton } from './organisms/invite-codes';
|
||||
|
||||
/** The codes before they arrive, under the section's header and tabs. */
|
||||
export default function Loading() {
|
||||
return (
|
||||
<TableSkeleton columns={6} label={i18n.t('codes:list.loading')} delayed />
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
'use client';
|
||||
|
||||
import { useInviteCodesSearch } from '@lumina/garden-roof/features/invite-codes';
|
||||
import { SearchField } from '@lumina/island/molecules/search-field';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
/** «جستجوی تحلیلگر یا کد» at the header's end (J11-6): both tabs filter by it. */
|
||||
export function CodesSearch() {
|
||||
const { t } = useTranslation(['codes', 'common']);
|
||||
const search = useInviteCodesSearch();
|
||||
|
||||
return (
|
||||
<Element className="w-44 desktop:w-80">
|
||||
<SearchField
|
||||
label={t('header.search')}
|
||||
placeholder={t('header.search')}
|
||||
clearLabel={t('common:search.clear')}
|
||||
value={search.value}
|
||||
onValueChange={search.setValue}
|
||||
/>
|
||||
</Element>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
'use client';
|
||||
|
||||
import { ROUTES } from '@lumina/garden-roof/app/navigation';
|
||||
import { useInviteCodesTabs } from '@lumina/garden-roof/features/invite-codes';
|
||||
import { TabLinks } from '@lumina/island/molecules/tab-links';
|
||||
import { number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const ROUTES_BY_TAB = {
|
||||
codes: ROUTES.codes,
|
||||
requests: ROUTES.capacityRequests,
|
||||
};
|
||||
|
||||
/** «همه کدها» · «درخواستهای افزایش ۲» (J11-6, 6d): two routes, the pending count on the second. */
|
||||
export function CodesTabs() {
|
||||
const { t } = useTranslation('codes');
|
||||
const model = useInviteCodesTabs({ routes: ROUTES_BY_TAB });
|
||||
|
||||
return (
|
||||
<TabLinks
|
||||
label={t('header.tabs-label')}
|
||||
items={[
|
||||
{
|
||||
href: model.hrefs.codes,
|
||||
label: t('header.tabs.codes'),
|
||||
isActive: model.active === 'codes',
|
||||
},
|
||||
{
|
||||
href: model.hrefs.requests,
|
||||
label: t('header.tabs.requests'),
|
||||
isActive: model.active === 'requests',
|
||||
count: model.pendingRequests,
|
||||
countLabel: t('header.pending', {
|
||||
value: number(model.pendingRequests),
|
||||
}),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export { CodesSearch } from './CodesSearch';
|
||||
export { CodesTabs } from './CodesTabs';
|
||||
export type { CodesSearchProps, CodesTabsProps } from './types';
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export type CodesSearchProps = Record<string, never>;
|
||||
|
||||
export type CodesTabsProps = Record<string, never>;
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
'use client';
|
||||
|
||||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { useCapacityRequestsPage } from '@lumina/garden-roof/features/invite-codes';
|
||||
import { Suspense } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { CodeDialogs } from './components/CodeDialogs';
|
||||
import { RequestRows } from './components/RequestRows';
|
||||
import { TableSkeleton } from './components/TableSkeleton';
|
||||
|
||||
/**
|
||||
* «درخواستهای افزایش» (J11-6d): the pending requests for the header's search and the page, and
|
||||
* their dialogs. A decision drops the row and the tab's and sidebar's counts together.
|
||||
*/
|
||||
export function CapacityRequests() {
|
||||
const { t } = useTranslation('codes');
|
||||
const model = useCapacityRequestsPage();
|
||||
|
||||
return (
|
||||
<>
|
||||
<PartBoundary
|
||||
key={model.argsKey}
|
||||
name="capacity-requests"
|
||||
description={t('requests.error')}
|
||||
>
|
||||
<Suspense
|
||||
fallback={<TableSkeleton columns={7} label={t('requests.loading')} />}
|
||||
>
|
||||
<RequestRows model={model} />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
<CodeDialogs actions={model.actions} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
'use client';
|
||||
|
||||
import { PartBoundary } from '@lumina/garden-roof/app/error-boundaries';
|
||||
import { useInviteCodesPage } from '@lumina/garden-roof/features/invite-codes';
|
||||
import { Suspense } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { CodeDetailSheet } from './components/CodeDetailSheet';
|
||||
import { CodeDialogs } from './components/CodeDialogs';
|
||||
import { CodeRows } from './components/CodeRows';
|
||||
import { TableSkeleton } from './components/TableSkeleton';
|
||||
|
||||
/**
|
||||
* «همه کدها» (J11-6): the rows for the header's search and the page, the open code's details
|
||||
* beside them (J11-6g) and the dialogs. A new search or page remounts the rows behind the table
|
||||
* skeleton; a failed read errors in their place.
|
||||
*/
|
||||
export function InviteCodes() {
|
||||
const { t } = useTranslation('codes');
|
||||
const model = useInviteCodesPage();
|
||||
|
||||
return (
|
||||
<>
|
||||
<PartBoundary
|
||||
key={model.argsKey}
|
||||
name="invite-codes"
|
||||
description={t('list.error')}
|
||||
>
|
||||
<Suspense
|
||||
fallback={<TableSkeleton columns={6} label={t('list.loading')} />}
|
||||
>
|
||||
<CodeRows model={model} />
|
||||
</Suspense>
|
||||
</PartBoundary>
|
||||
<CodeDetailSheet model={model} />
|
||||
<CodeDialogs actions={model.actions} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
'use client';
|
||||
|
||||
import { CODE_MAX_USES } from '@lumina/garden-roof/features/invite-codes';
|
||||
import { translateMessage } from '@lumina/garden-roof/shared/utils';
|
||||
import { REASON_MAX_LENGTH } from '@lumina/garden-roof/shared/validations';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { Banner } from '@lumina/island/molecules/banner';
|
||||
import { DetailRow } from '@lumina/island/molecules/detail-row';
|
||||
import { KeyValue } from '@lumina/island/molecules/key-value';
|
||||
import { Modal } from '@lumina/island/molecules/modal';
|
||||
import { TextInput } from '@lumina/island/molecules/text-input';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { date, number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { CodeDialogsProps } from '../types';
|
||||
import { CodeStatusBadge } from './CodeStatusBadge';
|
||||
|
||||
/**
|
||||
* «تغییر ظرفیت کد دعوت» (J11-6b): the code's seats and list, the analyst's request when there is
|
||||
* one (then saving approves it), the new capacity from the seats used up to 1000, and the reason
|
||||
* (the analyst sees it on their card when it approves their request; a plain change keeps it in the
|
||||
* audit log).
|
||||
* When the typed capacity opens seats on a full code, a banner says who hears «ظرفیت باز شد» and
|
||||
* the button becomes «ذخیره و اطلاعرسانی».
|
||||
*/
|
||||
export function CapacityDialog({ actions }: CodeDialogsProps) {
|
||||
const { t } = useTranslation(['codes', 'common']);
|
||||
const dialog = actions.dialog?.kind === 'capacity' ? actions.dialog : null;
|
||||
const form = actions.capacityForm;
|
||||
const { errors } = form.formState;
|
||||
const { isSubmitting, capacityNotice } = actions;
|
||||
|
||||
return (
|
||||
<Modal
|
||||
open={actions.isOpen && dialog !== null}
|
||||
onClose={isSubmitting ? undefined : actions.close}
|
||||
dismissible={!isSubmitting}
|
||||
title={t('capacity.title')}
|
||||
actions={
|
||||
<>
|
||||
<Button
|
||||
block
|
||||
isLoading={isSubmitting}
|
||||
onClick={actions.submitCapacity}
|
||||
>
|
||||
{capacityNotice === 'notify'
|
||||
? t('capacity.save-notify')
|
||||
: t('capacity.save')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
block
|
||||
disabled={isSubmitting}
|
||||
onClick={actions.close}
|
||||
>
|
||||
{t('common:actions.cancel')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
{dialog && (
|
||||
<Element
|
||||
tag="form"
|
||||
noValidate
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
actions.submitCapacity();
|
||||
}}
|
||||
>
|
||||
<FlexBox direction="flex-col" gap="gap-4">
|
||||
<Typography tag="p" variant="body-md" className="m-0">
|
||||
{dialog.code.analyst.fullName} ·{' '}
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{dialog.code.analyst.username}
|
||||
</Element>
|
||||
</Typography>
|
||||
<KeyValue tone="soft">
|
||||
<DetailRow label={t('capacity.fields.code')} ltr strong>
|
||||
{dialog.code.code}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('capacity.fields.used')}>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-end"
|
||||
gap="gap-2"
|
||||
wrap="flex-wrap"
|
||||
>
|
||||
{dialog.code.status === 'full' && (
|
||||
<CodeStatusBadge status="full" />
|
||||
)}
|
||||
{t('usage', {
|
||||
used: number(dialog.code.usedCount),
|
||||
max: number(dialog.code.maxUses),
|
||||
})}
|
||||
</FlexBox>
|
||||
</DetailRow>
|
||||
<DetailRow label={t('capacity.fields.waitlist')}>
|
||||
{dialog.code.waitlistCount > 0
|
||||
? t('people', { value: number(dialog.code.waitlistCount) })
|
||||
: t('none')}
|
||||
</DetailRow>
|
||||
{dialog.request && (
|
||||
<DetailRow label={t('capacity.fields.request')}>
|
||||
{t('capacity.request-value', {
|
||||
people: t('people', {
|
||||
value: number(dialog.request.requestedMaxUses),
|
||||
}),
|
||||
date: date(dialog.request.createdAt, { time: false }),
|
||||
})}
|
||||
</DetailRow>
|
||||
)}
|
||||
</KeyValue>
|
||||
<TextInput
|
||||
{...form.register('maxUses')}
|
||||
label={t('capacity.field')}
|
||||
hint={t('capacity.hint', {
|
||||
min: number(dialog.code.usedCount),
|
||||
max: CODE_MAX_USES,
|
||||
})}
|
||||
error={translateMessage(t, errors.maxUses?.message)}
|
||||
dir="ltr"
|
||||
inputMode="numeric"
|
||||
autoComplete="off"
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
<TextInput
|
||||
{...form.register('reason')}
|
||||
label={t('common:reason.label')}
|
||||
hint={
|
||||
dialog.request
|
||||
? t('common:reason.hint-analyst')
|
||||
: t('common:reason.hint')
|
||||
}
|
||||
error={translateMessage(t, errors.reason?.message)}
|
||||
multiline
|
||||
rows={3}
|
||||
maxLength={REASON_MAX_LENGTH}
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
{capacityNotice && (
|
||||
<Banner
|
||||
tone={capacityNotice === 'notify' ? 'info' : 'warning'}
|
||||
icon={capacityNotice === 'notify' ? 'message' : 'bell-off'}
|
||||
>
|
||||
{capacityNotice === 'notify'
|
||||
? t('capacity.notify', {
|
||||
people: t('people', {
|
||||
value: number(dialog.code.waitlistCount),
|
||||
}),
|
||||
})
|
||||
: t('capacity.held')}
|
||||
</Banner>
|
||||
)}
|
||||
</FlexBox>
|
||||
</Element>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
'use client';
|
||||
|
||||
import { AuditLog } from '@lumina/garden-roof/app/screens';
|
||||
import { useInviteCodeDetailPart } from '@lumina/garden-roof/features/invite-codes';
|
||||
import { Button } from '@lumina/island/atoms/button';
|
||||
import { FlexBox } from '@lumina/island/atoms/flex-box';
|
||||
import { Typography } from '@lumina/island/atoms/typography';
|
||||
import { DetailRow } from '@lumina/island/molecules/detail-row';
|
||||
import { KeyValue } from '@lumina/island/molecules/key-value';
|
||||
import { Element } from '@lumina/island/primitives/element';
|
||||
import { date, number } from '@lumina/tools/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { CodeDetailProps } from '../types';
|
||||
import { CodeStatusBadge } from './CodeStatusBadge';
|
||||
|
||||
/**
|
||||
* One code (J11-6g): the code with «کپی کد» and its status, who it belongs to, its seats, the
|
||||
* list and its last SMS, when it was made and the link the analyst shares; then «گزارش ممیزی» and
|
||||
* the code's actions. The dialogs open over the panel, which shows the change once it's made.
|
||||
*/
|
||||
export function CodeDetail({ id, actions }: CodeDetailProps) {
|
||||
const { t } = useTranslation(['codes', 'common']);
|
||||
const { code, copyCode } = useInviteCodeDetailPart(id);
|
||||
const waitlist =
|
||||
code.waitlistCount > 0
|
||||
? t('people', { value: number(code.waitlistCount) })
|
||||
: t('none');
|
||||
|
||||
return (
|
||||
<FlexBox direction="flex-col" gap="gap-5">
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-between"
|
||||
gap="gap-2"
|
||||
>
|
||||
<FlexBox alignItems="items-center" gap="gap-1">
|
||||
<Typography tag="span" variant="heading-sm">
|
||||
<Element tag="bdi" dir="ltr">
|
||||
{code.code}
|
||||
</Element>
|
||||
</Typography>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="copy"
|
||||
label={t('detail.copy')}
|
||||
onClick={copyCode}
|
||||
/>
|
||||
</FlexBox>
|
||||
<CodeStatusBadge status={code.status} />
|
||||
</FlexBox>
|
||||
<KeyValue>
|
||||
<DetailRow label={t('detail.fields.analyst')}>
|
||||
{code.analyst.fullName}{' '}
|
||||
<Element tag="bdi" dir="ltr">
|
||||
@{code.analyst.username}
|
||||
</Element>
|
||||
{code.analyst.isSuspended && <> · {t('suspended')}</>}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('detail.fields.used')}>
|
||||
{t('usage', {
|
||||
used: number(code.usedCount),
|
||||
max: number(code.maxUses),
|
||||
})}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('detail.fields.waitlist')}>
|
||||
{code.lastNotifiedAt
|
||||
? t('detail.last-sms', {
|
||||
people: waitlist,
|
||||
time: date(code.lastNotifiedAt),
|
||||
})
|
||||
: waitlist}
|
||||
</DetailRow>
|
||||
{code.pendingRequest && (
|
||||
<DetailRow label={t('detail.fields.request')}>
|
||||
{t('people', {
|
||||
value: number(code.pendingRequest.requestedMaxUses),
|
||||
})}
|
||||
</DetailRow>
|
||||
)}
|
||||
<DetailRow label={t('detail.fields.created')}>
|
||||
{date(code.createdAt, { time: false })}
|
||||
</DetailRow>
|
||||
<DetailRow label={t('detail.fields.link')} ltr>
|
||||
{code.inviteUrlLabel}
|
||||
</DetailRow>
|
||||
</KeyValue>
|
||||
<AuditLog entries={code.audit} framed={false} />
|
||||
<FlexBox direction="flex-col" gap="gap-2">
|
||||
{code.status === 'inactive' ? (
|
||||
<Button
|
||||
variant="secondary"
|
||||
block
|
||||
onClick={() => actions.openActivate(code)}
|
||||
>
|
||||
{t('detail.activate')}
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button
|
||||
variant="secondary"
|
||||
block
|
||||
onClick={() => actions.openCapacity(code)}
|
||||
>
|
||||
{t('detail.change-capacity')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="danger"
|
||||
block
|
||||
onClick={() => actions.openDeactivate(code)}
|
||||
>
|
||||
{t('detail.deactivate')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue