862 lines
33 KiB
TypeScript
862 lines
33 KiB
TypeScript
import {
|
|
MerchantControls,
|
|
ChecklistControl,
|
|
ReviewHistory,
|
|
InteractionHistory,
|
|
MerchantTasks,
|
|
RecentInteractions,
|
|
} from '../components/merchant-workflow';
|
|
import { useEffect, useState } from 'react';
|
|
import { Link, useOutletContext, useParams, useSearchParams } from 'react-router';
|
|
import { keepPreviousData, useQuery } from '@tanstack/react-query';
|
|
import { useTranslation } from 'react-i18next';
|
|
import {
|
|
ArrowRight,
|
|
ArrowUpRight,
|
|
ArrowLeft,
|
|
Building2,
|
|
ShieldCheck,
|
|
Clock3,
|
|
Activity,
|
|
Search,
|
|
ChevronLeft,
|
|
ChevronRight,
|
|
Check,
|
|
FileText,
|
|
Globe2,
|
|
Mail,
|
|
ExternalLink,
|
|
SlidersHorizontal,
|
|
LoaderCircle,
|
|
} from 'lucide-react';
|
|
import {
|
|
dashboardSchema,
|
|
merchantListSchema,
|
|
merchantDetailSchema,
|
|
pipelineSchema,
|
|
taskListSchema,
|
|
statuses,
|
|
successfulStages,
|
|
statusSchema,
|
|
taskFilters,
|
|
canSeeReviewQueue,
|
|
type Status,
|
|
type User,
|
|
type TaskFilter,
|
|
type Merchant,
|
|
} from '@merchantflow/contracts';
|
|
import { Input } from '@merchantflow/ui/components/input';
|
|
import { NativeSelect } from '@merchantflow/ui/components/native-select';
|
|
import {
|
|
Table,
|
|
TableHeader,
|
|
TableBody,
|
|
TableRow,
|
|
TableHead,
|
|
TableCell,
|
|
} from '@merchantflow/ui/components/table';
|
|
import { Badge } from '@merchantflow/ui/components/badge';
|
|
import { cn } from '@merchantflow/ui/lib/utils';
|
|
import { api } from '../lib/api';
|
|
import { useFormat } from '../lib/format';
|
|
import {
|
|
PageHeader,
|
|
SectionHeader,
|
|
QueryBoundary,
|
|
LinkButton,
|
|
Button,
|
|
StatusBadge,
|
|
Avatar,
|
|
ActivityFeed,
|
|
TaskRow,
|
|
MerchantCard,
|
|
EmptyState,
|
|
stageColors,
|
|
} from '../components/shared';
|
|
export function Dashboard() {
|
|
const { t } = useTranslation();
|
|
const f = useFormat();
|
|
const user = useOutletContext<User>();
|
|
const query = useQuery({
|
|
queryKey: ['dashboard'],
|
|
queryFn: ({ signal }) => api('/dashboard', dashboardSchema, { signal }),
|
|
});
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title={t('dashboard.title')}
|
|
description={t('dashboard.description')}
|
|
eyebrow={t('dashboard.eyebrow')}
|
|
action={
|
|
<LinkButton to="/app/merchants">
|
|
{t('dashboard.view')}
|
|
<ArrowUpRight className="size-4" />
|
|
</LinkButton>
|
|
}
|
|
/>
|
|
<QueryBoundary query={query}>
|
|
{(data) => (
|
|
<div className="space-y-6">
|
|
<div className="grid grid-cols-1 gap-3 min-[360px]:grid-cols-2 xl:grid-cols-4">
|
|
{[
|
|
{ key: 'merchants', value: data.merchantCount, Icon: Building2 },
|
|
{ key: 'reviews', value: data.reviewCount, Icon: ShieldCheck },
|
|
{ key: 'overdue', value: data.overdueTasks, Icon: Clock3 },
|
|
{ key: 'changes', value: data.transitionsLast30Days, Icon: Activity },
|
|
].map(({ key, value, Icon }, i) => (
|
|
<section key={key} className="surface p-5">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<h2 className="text-xs font-medium text-muted-foreground">
|
|
{t(`dashboard.${key}`)}
|
|
</h2>
|
|
<div
|
|
className={cn(
|
|
'flex size-8 shrink-0 items-center justify-center rounded-lg',
|
|
i === 0 ? 'bg-[#edf4de] text-[#526a2e]' : 'bg-muted text-muted-foreground',
|
|
)}
|
|
>
|
|
<Icon className="size-4" aria-hidden="true" />
|
|
</div>
|
|
</div>
|
|
<p className="mb-2 mt-4 text-[32px] font-semibold leading-none tracking-tight tabular-nums">
|
|
{f.number(value)}
|
|
</p>
|
|
<p className="mt-3 text-[11px] text-muted-foreground">
|
|
{t(`dashboard.${key}Hint`)}
|
|
</p>
|
|
</section>
|
|
))}
|
|
</div>
|
|
<section className="surface">
|
|
<SectionHeader
|
|
title={t('dashboard.pipeline')}
|
|
description={t('dashboard.pipelineText')}
|
|
action={
|
|
<LinkButton to="/app/pipeline" variant="ghost" className="text-xs">
|
|
{t('dashboard.openPipeline')}
|
|
<ArrowRight className="size-3.5" />
|
|
</LinkButton>
|
|
}
|
|
/>
|
|
<div className="px-5 pb-6 pt-6 sm:px-6">
|
|
<div
|
|
className="mb-5 flex h-3 gap-1 overflow-hidden rounded-full"
|
|
aria-hidden="true"
|
|
>
|
|
{data.distribution
|
|
.filter((s) => s.status !== 'REJECTED' && s.count > 0)
|
|
.map((s) => (
|
|
<div
|
|
key={s.status}
|
|
style={{ flex: s.count, backgroundColor: stageColors[s.status] }}
|
|
/>
|
|
))}
|
|
</div>
|
|
<div className="grid grid-cols-2 gap-x-4 gap-y-4 sm:grid-cols-4 xl:grid-cols-8">
|
|
{data.distribution
|
|
.filter((s) => s.status !== 'REJECTED')
|
|
.map((s) => (
|
|
<Link
|
|
to={`/app/merchants?status=${s.status}`}
|
|
key={s.status}
|
|
className="flex min-h-11 flex-col justify-center gap-2 rounded-md"
|
|
>
|
|
<span className="flex items-start gap-1.5 text-[10px] leading-tight text-muted-foreground">
|
|
<span
|
|
style={{ backgroundColor: stageColors[s.status] }}
|
|
className="mt-0.5 size-1.5 shrink-0 rounded-full"
|
|
/>
|
|
{t(`statuses.${s.status}`)}
|
|
</span>
|
|
<span className="pl-3 text-lg font-semibold tabular-nums">
|
|
{f.number(s.count)}
|
|
</span>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
<div className="grid gap-6 xl:grid-cols-[1.12fr_1fr]">
|
|
<section className="surface">
|
|
<SectionHeader
|
|
title={t('dashboard.activity')}
|
|
description={t('dashboard.activityText')}
|
|
/>
|
|
<RecentInteractions activities={data.recentActivities} />
|
|
</section>
|
|
<section className="surface self-start">
|
|
<SectionHeader
|
|
title={t('dashboard.priorities')}
|
|
description={t('dashboard.prioritiesText')}
|
|
action={
|
|
<LinkButton to="/app/tasks" variant="ghost" className="text-xs">
|
|
{t('common.viewAll')}
|
|
<ArrowRight className="size-3.5" />
|
|
</LinkButton>
|
|
}
|
|
/>
|
|
<div className="mt-4">
|
|
{data.upcomingTasks.length ? (
|
|
data.upcomingTasks.map((task) => <TaskRow key={task.id} task={task} compact />)
|
|
) : (
|
|
<EmptyState title={t('tasks.empty')} />
|
|
)}
|
|
</div>
|
|
<div className="m-5 flex items-center gap-2 rounded-lg bg-[#f6f8f1] p-3 text-[11px] text-muted-foreground">
|
|
<ShieldCheck className="size-4 shrink-0 text-[#617d37]" aria-hidden="true" />
|
|
{t(
|
|
`dashboard.${user.role === 'HEAD_OF_SALES' ? 'scopeHead' : user.role === 'COMPLIANCE_OFFICER' ? 'scopeCompliance' : 'scopeManager'}`,
|
|
)}
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</QueryBoundary>
|
|
</>
|
|
);
|
|
}
|
|
function useDebounced(value: string) {
|
|
const [debounced, setDebounced] = useState(value);
|
|
useEffect(() => {
|
|
const timer = setTimeout(() => setDebounced(value), 200);
|
|
return () => clearTimeout(timer);
|
|
}, [value]);
|
|
return debounced;
|
|
}
|
|
function MerchantTable({ merchants }: { merchants: Merchant[] }) {
|
|
const { t } = useTranslation();
|
|
const f = useFormat();
|
|
return (
|
|
<>
|
|
<div className="hidden md:block">
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow className="bg-[#fafbf9] hover:bg-[#fafbf9]">
|
|
<TableHead className="pl-6">{t('common.merchant')}</TableHead>
|
|
<TableHead>{t('common.status')}</TableHead>
|
|
<TableHead>{t('merchants.location')}</TableHead>
|
|
<TableHead>{t('common.owner')}</TableHead>
|
|
<TableHead className="pr-6 text-right">{t('common.created')}</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{merchants.map((m) => (
|
|
<TableRow key={m.id} className="hover-surface">
|
|
<TableCell className="pl-6">
|
|
<Link
|
|
to={`/app/merchants/${m.id}`}
|
|
className="flex min-h-14 items-center gap-3 py-2"
|
|
>
|
|
<Avatar name={m.name} small />
|
|
<div>
|
|
<p className="text-[13px] font-semibold">{m.name}</p>
|
|
<p className="mt-1 text-[11px] text-muted-foreground">
|
|
{t(`industry.${m.industry}`)}
|
|
</p>
|
|
</div>
|
|
</Link>
|
|
</TableCell>
|
|
<TableCell>
|
|
<StatusBadge status={m.status} />
|
|
</TableCell>
|
|
<TableCell className="text-xs text-muted-foreground">
|
|
{f.country(m.country)}
|
|
</TableCell>
|
|
<TableCell className="text-xs">
|
|
{m.owner?.name ?? t('workflow.unassigned')}
|
|
</TableCell>
|
|
<TableCell className="pr-6 text-right text-xs text-muted-foreground">
|
|
{f.shortDate(m.createdAt)}
|
|
</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
</div>
|
|
<div className="divide-y md:hidden">
|
|
{merchants.map((m) => (
|
|
<Link key={m.id} to={`/app/merchants/${m.id}`} className="hover-surface block p-4">
|
|
<div className="flex items-center gap-3">
|
|
<Avatar name={m.name} />
|
|
<div className="min-w-0">
|
|
<h2 className="truncate text-sm font-semibold">{m.name}</h2>
|
|
<p className="mt-1 text-xs text-muted-foreground">
|
|
{t(`industry.${m.industry}`)} · {f.country(m.country)}
|
|
</p>
|
|
</div>
|
|
<ChevronRight className="ml-auto size-4 shrink-0 text-muted-foreground" />
|
|
</div>
|
|
<div className="mt-4 flex flex-wrap items-center justify-between gap-2">
|
|
<StatusBadge status={m.status} />
|
|
<span className="text-xs text-muted-foreground">
|
|
{m.owner?.name ?? t('workflow.unassigned')}
|
|
</span>
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
export function Merchants() {
|
|
const { t } = useTranslation();
|
|
const f = useFormat();
|
|
const [params, setParams] = useSearchParams();
|
|
const search = params.get('search') ?? '';
|
|
const debounced = useDebounced(search);
|
|
const parsedStatus = statusSchema.safeParse(params.get('status'));
|
|
const status = parsedStatus.success ? parsedStatus.data : '';
|
|
const page = Math.max(1, Math.min(10000, Number(params.get('page')) || 1));
|
|
const update = (key: string, value: string) => {
|
|
const next = new URLSearchParams(params);
|
|
if (value) next.set(key, value);
|
|
else next.delete(key);
|
|
if (key !== 'page') next.delete('page');
|
|
setParams(next, { replace: true });
|
|
};
|
|
const query = useQuery({
|
|
queryKey: ['merchants', debounced, status, page],
|
|
queryFn: ({ signal }) =>
|
|
api(
|
|
`/merchants?${new URLSearchParams({ search: debounced, ...(status ? { status } : {}), page: String(page) })}`,
|
|
merchantListSchema,
|
|
{ signal },
|
|
),
|
|
placeholderData: keepPreviousData,
|
|
});
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title={t('merchants.title')}
|
|
description={t('merchants.description')}
|
|
eyebrow={t('merchants.portfolio')}
|
|
/>
|
|
<section className="surface overflow-hidden">
|
|
<div className="flex flex-col gap-3 border-b p-4 sm:flex-row sm:items-center sm:justify-between sm:px-6">
|
|
<div className="relative w-full sm:max-w-sm">
|
|
<Search
|
|
className="pointer-events-none absolute left-3 top-3.5 size-4 text-muted-foreground"
|
|
aria-hidden="true"
|
|
/>
|
|
<Input
|
|
aria-label={t('merchants.search')}
|
|
value={search}
|
|
onChange={(e) => update('search', e.target.value)}
|
|
maxLength={100}
|
|
placeholder={t('merchants.search')}
|
|
className="bg-white pl-10"
|
|
/>
|
|
{query.isFetching && (
|
|
<LoaderCircle
|
|
aria-label={t('common.loading')}
|
|
className="absolute right-3 top-3.5 size-4 animate-spin text-muted-foreground"
|
|
/>
|
|
)}
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<SlidersHorizontal
|
|
className="size-4 shrink-0 text-muted-foreground"
|
|
aria-hidden="true"
|
|
/>
|
|
<NativeSelect
|
|
aria-label={t('merchants.filter')}
|
|
value={status}
|
|
onChange={(e) => update('status', e.target.value)}
|
|
className="w-full bg-white sm:min-w-[190px]"
|
|
>
|
|
<option value="">{t('merchants.allStages')}</option>
|
|
{statuses.map((s) => (
|
|
<option key={s} value={s}>
|
|
{t(`statuses.${s}`)}
|
|
</option>
|
|
))}
|
|
</NativeSelect>
|
|
</div>
|
|
</div>
|
|
<QueryBoundary query={query}>
|
|
{(data) =>
|
|
data.items.length ? (
|
|
<>
|
|
<MerchantTable merchants={data.items} />
|
|
<div className="flex flex-col items-center justify-between gap-3 border-t px-5 py-4 sm:flex-row sm:px-6">
|
|
<p className="text-xs text-muted-foreground">
|
|
{t('common.showing', {
|
|
from: f.number((page - 1) * data.pageSize + 1),
|
|
to: f.number(Math.min(page * data.pageSize, data.total)),
|
|
total: f.number(data.total),
|
|
})}
|
|
</p>
|
|
<nav
|
|
aria-label={t('common.page', {
|
|
page: f.number(page),
|
|
total: f.number(Math.ceil(data.total / data.pageSize)),
|
|
})}
|
|
className="flex items-center gap-2"
|
|
>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
aria-label={t('common.previous')}
|
|
disabled={page <= 1 || query.isPlaceholderData}
|
|
onClick={() => update('page', String(page - 1))}
|
|
>
|
|
<ChevronLeft className="size-4" />
|
|
</Button>
|
|
<span className="px-2 text-xs">
|
|
{f.number(page)} / {f.number(Math.ceil(data.total / data.pageSize))}
|
|
</span>
|
|
<Button
|
|
variant="outline"
|
|
size="icon"
|
|
aria-label={t('common.next')}
|
|
disabled={page * data.pageSize >= data.total || query.isPlaceholderData}
|
|
onClick={() => update('page', String(page + 1))}
|
|
>
|
|
<ChevronRight className="size-4" />
|
|
</Button>
|
|
</nav>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<EmptyState
|
|
title={t('common.noResults')}
|
|
description={t('common.noResultsText')}
|
|
action={
|
|
<Button variant="outline" onClick={() => setParams({})}>
|
|
{t('common.clear')}
|
|
</Button>
|
|
}
|
|
/>
|
|
)
|
|
}
|
|
</QueryBoundary>
|
|
</section>
|
|
</>
|
|
);
|
|
}
|
|
export function MerchantDetail() {
|
|
const { id } = useParams();
|
|
const { t } = useTranslation();
|
|
const f = useFormat();
|
|
const query = useQuery({
|
|
queryKey: ['merchant', id],
|
|
queryFn: ({ signal }) =>
|
|
api(`/merchants/${encodeURIComponent(id ?? '')}`, merchantDetailSchema, { signal }),
|
|
});
|
|
return (
|
|
<>
|
|
<Link
|
|
to="/app/merchants"
|
|
className="mb-5 inline-flex min-h-11 items-center gap-2 text-xs text-muted-foreground"
|
|
>
|
|
<ArrowLeft className="size-3.5" />
|
|
{t('merchants.back')}
|
|
</Link>
|
|
<QueryBoundary query={query}>
|
|
{(m) => (
|
|
<>
|
|
<div className="mb-7 flex flex-wrap items-center gap-4">
|
|
<Avatar name={m.name} />
|
|
<div className="min-w-0">
|
|
<h1 className="page-title">{m.name}</h1>
|
|
<p className="mt-1 text-xs text-muted-foreground">
|
|
{t(`industry.${m.industry}`)} · {f.country(m.country)}
|
|
</p>
|
|
</div>
|
|
<div className="ml-auto">
|
|
<StatusBadge status={m.status} />
|
|
<p className="mt-2 text-[11px] text-muted-foreground">
|
|
{t('merchants.since', { date: f.date(m.stageEnteredAt) })}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<MerchantControls merchant={m} />
|
|
<div className="grid gap-6 xl:grid-cols-[1.15fr_1fr]">
|
|
<div className="min-w-0 space-y-6">
|
|
<section className="surface">
|
|
<SectionHeader
|
|
title={t('merchants.overview')}
|
|
description={t('merchants.details')}
|
|
/>
|
|
<dl className="grid grid-cols-1 gap-5 p-5 sm:grid-cols-2 sm:p-6">
|
|
{[
|
|
{
|
|
label: t('common.owner'),
|
|
value: m.owner?.name ?? t('workflow.unassigned'),
|
|
},
|
|
{ label: t('merchants.contact'), value: m.contactName },
|
|
...(
|
|
[
|
|
'legalName',
|
|
'registrationNumber',
|
|
'address',
|
|
'contactPhone',
|
|
'contactTitle',
|
|
] as const
|
|
).map((key) => ({ label: t(`workflow.${key}`), value: m[key] ?? '—' })),
|
|
{
|
|
label: t('workflow.estimatedMonthlyVolumeUsd'),
|
|
value: f.usd(m.estimatedMonthlyVolumeUsd),
|
|
},
|
|
{
|
|
label: t('workflow.source'),
|
|
value: m.source ? t(`workflow.${m.source}`) : '—',
|
|
},
|
|
{
|
|
label: t('merchants.website'),
|
|
value: (
|
|
<a
|
|
href={m.website}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="inline-flex min-h-11 items-center gap-1.5 break-all hover:underline"
|
|
>
|
|
<Globe2 className="size-3.5 shrink-0" />
|
|
{new URL(m.website).hostname}
|
|
<ExternalLink className="size-3 shrink-0" />
|
|
</a>
|
|
),
|
|
},
|
|
{
|
|
label: t('auth.email'),
|
|
value: (
|
|
<a
|
|
href={`mailto:${m.contactEmail}`}
|
|
className="inline-flex min-h-11 items-center gap-1.5 break-all hover:underline"
|
|
>
|
|
<Mail className="size-3.5 shrink-0" />
|
|
{m.contactEmail}
|
|
</a>
|
|
),
|
|
},
|
|
].map((item, i) => (
|
|
<div key={i} className="min-w-0">
|
|
<dt className="text-xs text-muted-foreground">{item.label}</dt>
|
|
<dd className="mt-2 text-sm font-medium">{item.value}</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
</section>
|
|
<ReviewHistory merchant={m} />
|
|
<section id="checklist" className="surface">
|
|
<SectionHeader
|
|
title={t('merchants.checklist')}
|
|
description={t('merchants.checklistText')}
|
|
/>
|
|
<div className="mt-4">
|
|
{m.checklist.map((doc) => (
|
|
<div key={doc.id} className="flex gap-3 border-t px-5 py-4 sm:px-6">
|
|
<div
|
|
className={cn(
|
|
'mt-1 flex size-7 shrink-0 items-center justify-center rounded-lg',
|
|
doc.state === 'RECEIVED'
|
|
? 'bg-accent text-[#46641d]'
|
|
: 'bg-muted text-muted-foreground',
|
|
)}
|
|
>
|
|
{doc.state === 'RECEIVED' ? (
|
|
<Check className="size-4" />
|
|
) : (
|
|
<FileText className="size-4" />
|
|
)}
|
|
</div>
|
|
<div className="min-w-0 flex-1">
|
|
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
<p className="text-sm">{t(`documents.${doc.documentCode}`)}</p>
|
|
<Badge
|
|
variant="outline"
|
|
className={cn(
|
|
'text-[10px]',
|
|
doc.state === 'NEEDS_CORRECTION' &&
|
|
'border-amber-200 bg-amber-50 text-amber-800',
|
|
)}
|
|
>
|
|
{t(`checklist.${doc.state}`)}
|
|
</Badge>
|
|
</div>
|
|
<ChecklistControl merchant={m} item={doc} />
|
|
{doc.note && (
|
|
<p className="mt-2 text-xs leading-relaxed text-muted-foreground">
|
|
{doc.note}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</section>
|
|
<section className="surface">
|
|
<SectionHeader
|
|
title={t('merchants.notes')}
|
|
description={t('merchants.notesText')}
|
|
/>
|
|
<div className="space-y-4 p-5 sm:p-6">
|
|
{m.notes.length ? (
|
|
m.notes.map((note) => (
|
|
<article key={note.id} className="rounded-lg bg-background p-4">
|
|
<p className="whitespace-pre-wrap text-sm leading-7">{note.text}</p>
|
|
<p className="mt-3 text-[11px] text-muted-foreground">
|
|
{note.author.name} · {f.date(note.createdAt)}
|
|
</p>
|
|
</article>
|
|
))
|
|
) : (
|
|
<EmptyState title={t('merchants.noNotes')} />
|
|
)}
|
|
</div>
|
|
</section>
|
|
</div>
|
|
<div className="min-w-0 space-y-6">
|
|
<section className="surface">
|
|
<SectionHeader
|
|
title={t('merchants.history')}
|
|
description={t('merchants.historyText')}
|
|
/>
|
|
<ActivityFeed events={m.events} detail />
|
|
</section>
|
|
<MerchantTasks merchant={m} />
|
|
<InteractionHistory merchant={m} />
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</QueryBoundary>
|
|
</>
|
|
);
|
|
}
|
|
export function Pipeline() {
|
|
const { t } = useTranslation();
|
|
const f = useFormat();
|
|
const [stage, setStage] = useState<Status>('NEW_LEAD');
|
|
const query = useQuery({
|
|
queryKey: ['pipeline'],
|
|
queryFn: ({ signal }) => api('/pipeline', pipelineSchema, { signal }),
|
|
});
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title={t('pipeline.title')}
|
|
description={t('pipeline.description')}
|
|
eyebrow={t('pipeline.journey')}
|
|
/>
|
|
<QueryBoundary query={query}>
|
|
{(merchants) => (
|
|
<>
|
|
<NativeSelect
|
|
className="mb-5 w-full md:hidden"
|
|
aria-label={t('pipeline.stageSelect')}
|
|
value={stage}
|
|
onChange={(e) => setStage(e.target.value as Status)}
|
|
>
|
|
{successfulStages.map((s) => (
|
|
<option value={s} key={s}>
|
|
{t(`statuses.${s}`)} ({f.number(merchants.filter((m) => m.status === s).length)})
|
|
</option>
|
|
))}
|
|
</NativeSelect>
|
|
<div className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
|
|
{successfulStages.map((s, i) => {
|
|
const items = merchants.filter((m) => m.status === s);
|
|
return (
|
|
<section
|
|
key={s}
|
|
className={cn(
|
|
'min-w-0 rounded-xl border bg-[#f0f3ee] p-3',
|
|
s !== stage && 'hidden md:block',
|
|
)}
|
|
>
|
|
<div className="mb-4 flex min-h-10 items-center justify-between gap-2 px-1">
|
|
<h2 className="flex items-center gap-2 text-xs font-semibold">
|
|
<span
|
|
className="size-2 shrink-0 rounded-full"
|
|
style={{ backgroundColor: stageColors[s] }}
|
|
/>
|
|
{t(`statuses.${s}`)}
|
|
</h2>
|
|
<span className="rounded-md border bg-white px-2 py-1 text-[10px] tabular-nums">
|
|
{f.number(items.length)}
|
|
</span>
|
|
</div>
|
|
<div className="space-y-3">
|
|
{items.map((m) => (
|
|
<MerchantCard key={m.id} merchant={m} />
|
|
))}
|
|
{!items.length && (
|
|
<p className="flex min-h-36 items-center justify-center rounded-lg border border-dashed px-4 text-center text-xs leading-relaxed text-muted-foreground">
|
|
{t('pipeline.empty')}
|
|
</p>
|
|
)}
|
|
</div>
|
|
<p className="mt-4 px-1 text-[10px] text-muted-foreground">
|
|
{t('pipeline.stageCount', { number: f.number(i + 1) })}
|
|
</p>
|
|
</section>
|
|
);
|
|
})}
|
|
</div>
|
|
<section className="mt-7 rounded-xl border border-dashed p-5">
|
|
<h2 className="text-sm font-semibold">{t('pipeline.rejectedTitle')}</h2>
|
|
<p className="mb-4 mt-1 text-xs leading-relaxed text-muted-foreground">
|
|
{t('pipeline.rejectedText')}
|
|
</p>
|
|
<div className="grid gap-3 md:grid-cols-2 xl:grid-cols-4">
|
|
{merchants
|
|
.filter((m) => m.status === 'REJECTED')
|
|
.map((m) => (
|
|
<MerchantCard merchant={m} key={m.id} />
|
|
))}
|
|
{!merchants.some((m) => m.status === 'REJECTED') && (
|
|
<p className="text-xs text-muted-foreground">{t('pipeline.empty')}</p>
|
|
)}
|
|
</div>
|
|
</section>
|
|
</>
|
|
)}
|
|
</QueryBoundary>
|
|
</>
|
|
);
|
|
}
|
|
export function Tasks() {
|
|
const { t } = useTranslation();
|
|
const [params, setParams] = useSearchParams();
|
|
const raw = params.get('filter');
|
|
const filter: TaskFilter = taskFilters.includes(raw as TaskFilter) ? (raw as TaskFilter) : 'ALL';
|
|
const query = useQuery({
|
|
queryKey: ['tasks', filter],
|
|
queryFn: ({ signal }) => api(`/tasks?filter=${filter}`, taskListSchema, { signal }),
|
|
refetchInterval: 60000,
|
|
});
|
|
return (
|
|
<>
|
|
<PageHeader title={t('tasks.title')} description={t('tasks.description')} />
|
|
<section className="surface overflow-hidden">
|
|
<div
|
|
className="flex flex-wrap gap-1 border-b p-3"
|
|
role="group"
|
|
aria-label={t('tasks.filter')}
|
|
>
|
|
{taskFilters.map((s) => (
|
|
<Button
|
|
key={s}
|
|
variant="ghost"
|
|
aria-pressed={filter === s}
|
|
onClick={() => setParams(s === 'ALL' ? {} : { filter: s }, { replace: true })}
|
|
className={cn('text-xs', filter === s && 'bg-secondary')}
|
|
>
|
|
{t(`tasks.${s}`)}
|
|
</Button>
|
|
))}
|
|
</div>
|
|
<QueryBoundary query={query}>
|
|
{(tasks) =>
|
|
tasks.length ? (
|
|
<div>
|
|
{tasks.map((task) => (
|
|
<TaskRow key={task.id} task={task} />
|
|
))}
|
|
</div>
|
|
) : (
|
|
<EmptyState title={t('tasks.empty')} description={t('tasks.emptyText')} />
|
|
)
|
|
}
|
|
</QueryBoundary>
|
|
</section>
|
|
</>
|
|
);
|
|
}
|
|
export function ReviewQueue() {
|
|
const user = useOutletContext<User>();
|
|
const { t } = useTranslation();
|
|
const f = useFormat();
|
|
const allowed = canSeeReviewQueue(user.role);
|
|
const query = useQuery({
|
|
queryKey: ['review-queue'],
|
|
queryFn: ({ signal }) => api('/review-queue', pipelineSchema, { signal }),
|
|
enabled: allowed,
|
|
});
|
|
if (!allowed) return <NotFound forbidden />;
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title={t('review.title')}
|
|
description={t('review.description')}
|
|
eyebrow={t('review.eyebrow')}
|
|
/>
|
|
<QueryBoundary query={query}>
|
|
{(merchants) => (
|
|
<section className="surface overflow-hidden">
|
|
<div className="flex flex-wrap items-center justify-between gap-2 border-b px-5 py-5 sm:px-6">
|
|
<h2 className="text-sm font-semibold">
|
|
{t('review.count', { count: merchants.length })}
|
|
</h2>
|
|
<span className="inline-flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
<Clock3 className="size-3.5" />
|
|
{t('review.order')}
|
|
</span>
|
|
</div>
|
|
{merchants.length ? (
|
|
merchants.map((m) => (
|
|
<div
|
|
key={m.id}
|
|
className="flex flex-col gap-5 border-b p-5 last:border-0 sm:flex-row sm:items-center sm:justify-between sm:p-6"
|
|
>
|
|
<div className="flex items-center gap-3">
|
|
<Avatar name={m.name} />
|
|
<div>
|
|
<Link
|
|
to={`/app/merchants/${m.id}`}
|
|
className="text-sm font-semibold hover:underline"
|
|
>
|
|
{m.name}
|
|
</Link>
|
|
<p className="mt-1 text-xs text-muted-foreground">
|
|
{m.owner?.name ?? t('workflow.unassigned')} · {t(`industry.${m.industry}`)}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="flex flex-wrap items-center justify-between gap-4">
|
|
<div>
|
|
<p className="mb-1 text-[10px] text-muted-foreground">
|
|
{t('review.entered')}
|
|
</p>
|
|
<p className="text-xs">{f.date(m.stageEnteredAt)}</p>
|
|
</div>
|
|
<LinkButton
|
|
to={`/app/merchants/${m.id}#checklist`}
|
|
variant="outline"
|
|
className="text-xs"
|
|
>
|
|
{t('review.view')}
|
|
<ArrowRight className="size-3.5" />
|
|
</LinkButton>
|
|
</div>
|
|
</div>
|
|
))
|
|
) : (
|
|
<EmptyState title={t('review.empty')} description={t('review.emptyText')} />
|
|
)}
|
|
</section>
|
|
)}
|
|
</QueryBoundary>
|
|
</>
|
|
);
|
|
}
|
|
export function NotFound({ forbidden = false }: { forbidden?: boolean }) {
|
|
const { t } = useTranslation();
|
|
return (
|
|
<div className="mx-auto max-w-lg py-16">
|
|
<EmptyState
|
|
title={t(forbidden ? 'common.noAccess' : 'common.notFound')}
|
|
description={t(forbidden ? 'common.noAccessText' : 'common.notFoundText')}
|
|
action={
|
|
<LinkButton to="/app">
|
|
{t('common.goHome')}
|
|
<ArrowRight className="size-4" />
|
|
</LinkButton>
|
|
}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|