"use client" import { useMutation, useQueryClient } from "@tanstack/react-query" import { toast } from "sonner" import { CheckIcon, StarIcon, StarOffIcon, XIcon } from "lucide-react" import { TaxForm } from "@/modules/settings/tax-rates/tax-form" import { ResourcePage } from "@/shared/data-view/resource-page" import { ColumnHeader } from "@/shared/data-view/table-view" import FormDialog from "@/shared/components/form-dialog" import { Button } from "@/shared/components/ui/button" import { useAuthApi } from "@/shared/useApi" import { TAX_ROUTES } from "@garage/api" import type { TaxesClient } from "@garage/api" function TaxDefaultCell({ row }: { row: any }) { const api = useAuthApi() const queryClient = useQueryClient() const isDefault: boolean = row.is_default ?? false const { mutate, isPending } = useMutation({ mutationFn: () => { const promise = isDefault ? api.taxes.removeDefault({ id: row.id }) : api.taxes.setDefault({ id: row.id }) toast.promise(promise, { loading: isDefault ? "Removing default..." : "Setting as default...", success: isDefault ? "Default removed" : "Set as default", error: isDefault ? "Failed to remove default" : "Failed to set as default", }) return promise }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: [TAX_ROUTES.INDEX] }) }, }) return ( ) } export default function TaxesPage() { return ( pageTitle="Tax & Rates" routeKey={TAX_ROUTES.INDEX} getClient={(api) => api.taxes} headerProps={({ selectedItem, invalidateQuery }) => ({ actions: ( {(resourceId) => ( )} ), })} columns={({ actionsColumn }) => [ { accessorKey: "title", header: ({ column }) => , }, { accessorKey: "rate", header: ({ column }) => , cell: ({ row }) => `${(row.original as any).rate ?? 0}%`, }, { accessorKey: "note", header: ({ column }) => , cell: ({ row }) => ( {(row.original as any).note ?? "—"} ), }, { accessorKey: "is_default", header: ({ column }) => , cell: ({ row }) => (row.original as any).is_default ? : , }, { id: "set_default", header: () => Set Default, enableSorting: false, cell: ({ row }) => , }, actionsColumn(), ]} /> ) }