Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
138 lines
5.3 KiB
TypeScript
138 lines
5.3 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
import type { SortingState } from "@tanstack/react-table";
|
|
import Link from "next/link";
|
|
import { Plus } from "lucide-react";
|
|
import { Badge } from "@/app/components/ui/badge";
|
|
import { Button } from "@/app/components/ui/button";
|
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/app/components/ui/table";
|
|
import { SortableHead, sortRows } from "@/app/components/ui/sortable-head";
|
|
import { PageHeader } from "@/app/components/ui/page-header";
|
|
import { EmptyState, ErrorState, TableSkeleton } from "@/app/components/ui/states";
|
|
import { RequireModule } from "@/app/lib/RequireModule";
|
|
import { listForms } from "@/app/lib/services/adminForms";
|
|
import type { CmsFormListItem } from "@/app/lib/cmsForms";
|
|
import { formatDateTime } from "@/app/lib/format";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
// `/forms` (add-cms-forms): every CMS form with its field and submission counts.
|
|
|
|
function FormsPageContent() {
|
|
const t = useT();
|
|
const [rows, setRows] = useState<CmsFormListItem[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [reloadKey, setReloadKey] = useState(0);
|
|
const [sorting, setSorting] = useState<SortingState>([]);
|
|
|
|
const refetch = useCallback(() => setReloadKey((k) => k + 1), []);
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
// eslint-disable-next-line react-hooks/set-state-in-effect -- resets loading/error ahead of the reloadKey-triggered fetch below.
|
|
setLoading(true);
|
|
setError(null);
|
|
listForms()
|
|
.then((result) => {
|
|
if (!cancelled) setRows(result);
|
|
})
|
|
.catch((err: unknown) => {
|
|
if (!cancelled) setError(err instanceof Error ? err.message : "FrmListLoadFailed");
|
|
})
|
|
.finally(() => {
|
|
if (!cancelled) setLoading(false);
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [reloadKey]);
|
|
|
|
const sorted = useMemo(
|
|
() =>
|
|
sortRows(rows, sorting, {
|
|
name: (r) => r.name,
|
|
fields: (r) => r.fieldCount,
|
|
submissions: (r) => r.submissionCount,
|
|
status: (r) => t(r.status === "Y" ? "Visible" : "Hidden"),
|
|
updated: (r) => r.updatedAt,
|
|
}),
|
|
[rows, sorting, t],
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title={t("BO_FORMS")}
|
|
actions={
|
|
<Button asChild>
|
|
<Link href="/forms/new">
|
|
<Plus aria-hidden="true" className="size-4" />
|
|
{t("FrmNewForm")}
|
|
</Link>
|
|
</Button>
|
|
}
|
|
/>
|
|
|
|
{error && <ErrorState message={t(error)} onRetry={refetch} className="mb-4" />}
|
|
|
|
{error ? null : loading ? (
|
|
<TableSkeleton columns={5} />
|
|
) : rows.length === 0 ? (
|
|
<EmptyState title={t("FrmNoForms")} />
|
|
) : (
|
|
<div className="overflow-hidden rounded-table border bg-card">
|
|
<Table aria-label={t("BO_FORMS")}>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<SortableHead label={t("Name")} sortKey="name" sorting={sorting} onSortingChange={setSorting} />
|
|
<SortableHead label={t("FrmFields")} sortKey="fields" sorting={sorting} onSortingChange={setSorting} className="tabular" />
|
|
<SortableHead label={t("FrmSubmissions")} sortKey="submissions" sorting={sorting} onSortingChange={setSorting} />
|
|
<SortableHead label={t("Status")} sortKey="status" sorting={sorting} onSortingChange={setSorting} />
|
|
<SortableHead label={t("Updated")} sortKey="updated" sorting={sorting} onSortingChange={setSorting} className="tabular" />
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{sorted.map((row) => (
|
|
<TableRow key={row.id}>
|
|
<TableCell>
|
|
<Link
|
|
href={`/forms/${row.id}`}
|
|
className="font-medium text-primary underline-offset-4 hover:underline focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none"
|
|
>
|
|
{row.name}
|
|
</Link>
|
|
</TableCell>
|
|
<TableCell className="tabular">{row.fieldCount}</TableCell>
|
|
<TableCell>
|
|
<Link
|
|
href={`/forms/${row.id}/submissions`}
|
|
className="font-medium text-primary underline-offset-4 hover:underline focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none"
|
|
>
|
|
{t(row.submissionCount === 1 ? "FrmSubmissionCountOne" : "FrmSubmissionCountMany", { count: row.submissionCount })}
|
|
</Link>
|
|
</TableCell>
|
|
<TableCell>
|
|
<Badge variant={row.status === "Y" ? "positive" : "neutral"}>
|
|
{t(row.status === "Y" ? "Visible" : "Hidden")}
|
|
</Badge>
|
|
</TableCell>
|
|
<TableCell className="tabular">{formatDateTime(row.updatedAt)}</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default function FormsPage() {
|
|
return (
|
|
<RequireModule pathname="/forms">
|
|
<FormsPageContent />
|
|
</RequireModule>
|
|
);
|
|
}
|