import { appPath } from "@agent-native/core/client/api-path"; import { useActionMutation, useActionQuery, } from "@agent-native/core/client/hooks"; import { isInAgentEmbed, postNavigate, } from "@agent-native/core/client/navigation"; import { IconCheck, IconX, IconArrowUpRight, IconShieldCheck, IconClock, IconAlertCircle, } from "@tabler/icons-react"; import { useSearchParams } from "react-router"; import { toast } from "sonner"; import { ActionQueryError } from "../../components/action-query-error"; import { ApprovalValueBlock, parseApprovalValue, } from "../../components/approval-value-block"; import { Badge } from "../../components/ui/badge"; import { Button } from "../../components/ui/button"; import { Skeleton } from "../../components/ui/skeleton"; export function meta() { return [{ title: "Approval — Dispatch" }]; } function StatusBadge({ status }: { status: string }) { if (status === "pending") { return ( Pending ); } if (status === "approved") { return ( Approved ); } return ( Rejected ); } export default function ApprovalPreviewRoute() { const [searchParams] = useSearchParams(); const id = searchParams.get("id") ?? ""; const approvalsQuery = useActionQuery("list-dispatch-approvals", {}); const { data: approvals, isLoading } = approvalsQuery; const approve = useActionMutation("approve-dispatch-change", { onSuccess: () => toast.success("Change approved"), }); const reject = useActionMutation("reject-dispatch-change", { onSuccess: () => toast.success("Change rejected"), }); const inEmbed = isInAgentEmbed(); const approval = approvals?.find((item: any) => item.id === id) ?? null; if (!id) { return (

No approval id provided

Add ?id=<id> to the URL.

); } if (isLoading) { return (
); } if (approvalsQuery.isError) { return (
void approvalsQuery.refetch()} />
); } if (!approval) { return (

Approval not found

The approval with id{" "} {id} does not exist.

{inEmbed && ( )}
); } const isPending = approval.status === "pending"; const beforeValue = parseApprovalValue(approval.beforeValue); const afterValue = parseApprovalValue(approval.afterValue); return (
{approval.summary}
Requested by{" "} {approval.requestedBy}
Change type {approval.changeType}
Target type {approval.targetType}
{approval.targetId && (
Target id {approval.targetId}
)} {approval.reviewedBy && (
Reviewed by {approval.reviewedBy}
)}
{(beforeValue !== null || afterValue !== null) && (
)} {isPending && (
)}
{inEmbed && (
)}
); }