TorbatYar/frontend/modules/crm/features/sales/export.tsx
Mortezakoohjani e140908034 Ship enterprise CRM frontend with real API wiring and thin app routes.
Connect all CRM pages to the BFF and CRM service, add module docs, and mark CRM available in the SuperApp catalog.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-26 20:58:17 +03:30

93 lines
2.9 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useQuery } from "@tanstack/react-query";
import { Button, PageHeader } from "@/components/ds";
import { crmApi } from "@/modules/crm/services/crm-api";
import { useTenantId } from "@/hooks/useTenantId";
import { CrmPageLoader, CrmPageError, exportToCsv } from "@/modules/crm/pages/shared";
import { CrmBreadcrumbs } from "@/modules/crm/components/CrmBreadcrumbs";
export default function ExportPage() {
const { tenantId } = useTenantId();
const q = useQuery({
queryKey: ["crm", tenantId, "export-bundle"],
queryFn: async () => {
const [leads, contacts, orgs, opps] = await Promise.all([
crmApi.leads.list(tenantId!, { page: 1, page_size: 500 }),
crmApi.contacts.list(tenantId!, { page: 1, page_size: 500 }),
crmApi.organizations.list(tenantId!, { page: 1, page_size: 500 }),
crmApi.opportunities.list(tenantId!, { page: 1, page_size: 500 }),
]);
return { leads, contacts, orgs, opps };
},
enabled: !!tenantId,
});
if (!tenantId || q.isLoading) return <CrmPageLoader />;
if (q.error) return <CrmPageError error={q.error} onRetry={() => q.refetch()} />;
const d = q.data!;
return (
<div>
<CrmBreadcrumbs items={[{ label: "خروجی" }]} />
<PageHeader
title="خروجی داده"
description="Export client-side CSV از داده‌های fetch شده — بدون export API سرور."
/>
<div className="flex flex-wrap gap-3">
<Button
variant="outline"
onClick={() =>
exportToCsv("leads.csv", d.leads as unknown as Record<string, unknown>[], [
"lead_number",
"full_name",
"email",
"status",
])
}
>
سرنخها CSV
</Button>
<Button
variant="outline"
onClick={() =>
exportToCsv("contacts.csv", d.contacts as unknown as Record<string, unknown>[], [
"full_name",
"email",
"phone",
])
}
>
مخاطبین CSV
</Button>
<Button
variant="outline"
onClick={() =>
exportToCsv("organizations.csv", d.orgs as unknown as Record<string, unknown>[], [
"name",
"organization_number",
"status",
])
}
>
شرکتها CSV
</Button>
<Button
variant="outline"
onClick={() =>
exportToCsv("deals.csv", d.opps as unknown as Record<string, unknown>[], [
"opportunity_number",
"title",
"amount",
"status",
])
}
>
معاملات CSV
</Button>
</div>
</div>
);
}