feat(freight): track onboarding-phase edit history for companies

Ticket #238 — pre-approval edits and document uploads write straight
to the live company row with no approval gate and, until now, no
trace. Adds an append-only company_revisions log (diffed field
changes, document uploads) recorded from updateProfile and
uploadCompanyDocuments, exposed via GET /companies/:id/revisions and
shown as "Version history" on the backoffice customer detail page.
This commit is contained in:
Nathnael
2026-07-31 11:45:09 +00:00
parent d67297a601
commit 7c5d96795c
18 changed files with 383 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { Badge, Box, Card, Group, Stack, Text } from "@mantine/core";
import { useQuery } from "@tanstack/react-query";
import { History } from "lucide-react";
import { api } from "@/services/api";
import { formatDate } from "./format";
/**
* Onboarding-phase edit history: what changed on the company record before it
* reached Active, the write path that has no approval gate (unlike edits made
* after approval, which go through {@link ChangeRequestReview} instead).
*/
export function CompanyRevisionHistory({ companyId }: { companyId: string }) {
const query = useQuery(
api.customers.revisions.queryOptions({ input: { id: companyId } }),
);
const revisions = query.data ?? [];
if (revisions.length === 0) return null;
return (
<Card withBorder>
<Stack gap="sm">
<Group gap="xs">
<History size={16} />
<Text fw={600} c="edr-text">
Version history
</Text>
</Group>
{revisions.map((rev) => (
<Box key={rev.id}>
<Group gap="sm" wrap="nowrap" align="flex-start">
<Badge color="gray" variant="light" radius="md" tt="none">
{formatDate(rev.createdAt)}
</Badge>
<Text size="sm" c="edr-text" tt="capitalize">
{rev.summary}
</Text>
</Group>
{rev.changes.length > 0 && (
<Stack gap={2} ml={4} mt={4}>
{rev.changes.map((c, i) => (
<Text key={i} size="xs" c="dimmed">
{c.label}: {c.from ?? "—"} {c.to ?? "—"}
</Text>
))}
</Stack>
)}
</Box>
))}
</Stack>
</Card>
);
}

View File

@@ -13,6 +13,7 @@ export {
ChangeRequestReview,
ChangeRequestPendingBadge,
} from "./ChangeRequestReview";
export { CompanyRevisionHistory } from "./CompanyRevisionHistory";
export {
RequestDocumentChangeModal,
type RequestDocumentChangeModalProps,