fix build
This commit is contained in:
@@ -3,7 +3,47 @@
|
||||
import { CrudShowResponse, ExpensesClient } from "@garage/api"
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
export type ExpenseContextValue = CrudShowResponse<ExpensesClient>['data']
|
||||
type BaseExpenseContextValue = NonNullable<CrudShowResponse<ExpensesClient>["data"]>
|
||||
|
||||
type ExpenseNamedRelation = {
|
||||
id?: number
|
||||
name?: string | null
|
||||
title?: string | null
|
||||
}
|
||||
|
||||
type ExpenseVendorRelation = ExpenseNamedRelation & {
|
||||
company_name?: string | null
|
||||
first_name?: string | null
|
||||
last_name?: string | null
|
||||
}
|
||||
|
||||
type ExpenseJobCardRelation = {
|
||||
id?: number
|
||||
order_number?: string | null
|
||||
estimate_number?: string | null
|
||||
title?: string | null
|
||||
}
|
||||
|
||||
type ExpenseTaxRelation = ExpenseNamedRelation & {
|
||||
rate?: string | number | null
|
||||
}
|
||||
|
||||
type ExpenseLabel = {
|
||||
id?: number
|
||||
title?: string | null
|
||||
color_code?: string | null
|
||||
}
|
||||
|
||||
export type ExpenseContextValue = BaseExpenseContextValue & {
|
||||
discount?: string | null
|
||||
discount_amount_major?: number | null
|
||||
vendor?: ExpenseVendorRelation | null
|
||||
department?: ExpenseNamedRelation | null
|
||||
category?: ExpenseNamedRelation | null
|
||||
job_card?: ExpenseJobCardRelation | null
|
||||
tax?: ExpenseTaxRelation | null
|
||||
labels?: ExpenseLabel[] | null
|
||||
}
|
||||
|
||||
|
||||
const ExpenseContext = createContext<ExpenseContextValue | null>(null)
|
||||
|
||||
@@ -19,6 +19,7 @@ import { useAuthApi } from "@/shared/useApi"
|
||||
import { useResourceForm } from "@/shared/hooks/use-resource-form"
|
||||
import { useFormMutation } from "@/shared/hooks/use-form-mutation"
|
||||
import { getTodayDate, toRelation, toId } from "@/shared/lib/utils"
|
||||
import { formatTaxLabel } from "@/shared/utils/formatters"
|
||||
|
||||
import {
|
||||
expenseFormSchema,
|
||||
@@ -89,7 +90,7 @@ function mapToFormValues(data: unknown): ExpenseFormValues {
|
||||
category: toRelation(d.category_id, d.category?.name ?? d.category?.title ?? d.category_name),
|
||||
vendor: toRelation(d.vendor_id, d.vendor?.company_name ?? d.vendor?.name ?? d.vendor_name),
|
||||
department: toRelation(d.department_id, d.department?.name ?? d.department_name),
|
||||
tax: toRelation(d.tax_id, d.tax?.title ? `${d.tax.title} (${d.tax.rate}%)` : undefined),
|
||||
tax: toRelation(d.tax_id, formatTaxLabel(d.tax, d.tax_title ?? "") || undefined),
|
||||
title: d.title || "",
|
||||
invoice_number: d.invoice_number || "",
|
||||
expense_date: d.expense_date ? d.expense_date.split("T")[0] : "",
|
||||
|
||||
@@ -20,8 +20,7 @@ import {
|
||||
} from "@/shared/components/ui/card"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { cn } from "@/shared/lib/utils"
|
||||
import { formatDate, formatCurrency, formatEnum } from "@/shared/utils/formatters"
|
||||
import { getFullName } from "@/shared/utils/getFullName"
|
||||
import { formatDate, formatCurrency, formatEnum, formatTaxLabel } from "@/shared/utils/formatters"
|
||||
import { useExpense } from "./expense-context"
|
||||
|
||||
function InfoItem({
|
||||
@@ -68,9 +67,7 @@ export function ExpenseGeneralInfo() {
|
||||
const labels = (expense as any)?.labels || []
|
||||
const balanceDue = expense.balance_due ?? null
|
||||
const paymentsM = expense.payments_made ?? null
|
||||
const taxLabel = expense.tax?.title
|
||||
? `${expense.tax.title} (${expense.tax.rate}%)`
|
||||
: "Tax"
|
||||
const taxLabel = formatTaxLabel(expense.tax, "Tax")
|
||||
|
||||
return (
|
||||
<div className="grid gap-6">
|
||||
@@ -122,7 +119,7 @@ export function ExpenseGeneralInfo() {
|
||||
{/* ── Vendor ── */}
|
||||
<Card className="flex flex-col gap-1 p-4">
|
||||
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wide">Vendor</span>
|
||||
<span className="mt-1 text-lg font-semibold">{vendor.company_name || getFullName(vendor as any) || "—"}</span>
|
||||
<span className="mt-1 text-lg font-semibold">{vendor.name || "—"}</span>
|
||||
</Card>
|
||||
|
||||
{/* ── Expense Details ── */}
|
||||
|
||||
Reference in New Issue
Block a user