fix bugs phase 2 (excel ) , download sample feature

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Mohammad Khyata 2026-05-01 11:04:38 +03:00
parent e1ef6fa2ea
commit 97364f4734
24 changed files with 597 additions and 85 deletions

View File

@ -6,6 +6,7 @@ import { ColumnHeader } from '@/shared/data-view/table-view'
import FormDialog from '@/shared/components/form-dialog' import FormDialog from '@/shared/components/form-dialog'
import { ImportDataButton } from '@/shared/components/import-data-button' import { ImportDataButton } from '@/shared/components/import-data-button'
import { ExportDataButton } from '@/shared/components/export-data-button' import { ExportDataButton } from '@/shared/components/export-data-button'
import { DownloadSampleButton } from '@/shared/components/download-sample-button'
import { useAuthApi } from '@/shared/useApi' import { useAuthApi } from '@/shared/useApi'
import { CustomerForm } from '@/modules/customers/customer-form' import { CustomerForm } from '@/modules/customers/customer-form'
import { CUSTOMER_ROUTES } from '@garage/api' import { CUSTOMER_ROUTES } from '@garage/api'
@ -24,6 +25,10 @@ export default function CustomersPage() {
headerProps={({ selectedItem, invalidateQuery }) => ({ headerProps={({ selectedItem, invalidateQuery }) => ({
actions: ( actions: (
<div className='flex items-center gap-2'> <div className='flex items-center gap-2'>
<DownloadSampleButton
onDownload={() => api.customers.downloadImportSample()}
fileName='customers-import-sample'
/>
<ImportDataButton <ImportDataButton
onImport={(file) => api.customers.importData(file)} onImport={(file) => api.customers.importData(file)}
onSuccess={invalidateQuery} onSuccess={invalidateQuery}

View File

@ -1,7 +1,8 @@
"use client" "use client"
import { useEffect } from "react"
import { use } from "react" import { use } from "react"
import { useRouter } from "next/navigation" import { usePathname, useRouter, useSearchParams } from "next/navigation"
import { ResourcePage } from "@/shared/data-view/resource-page" import { ResourcePage } from "@/shared/data-view/resource-page"
import { ColumnHeader } from "@/shared/data-view/table-view" import { ColumnHeader } from "@/shared/data-view/table-view"
import FormDialog from "@/shared/components/form-dialog" import FormDialog from "@/shared/components/form-dialog"
@ -27,8 +28,20 @@ export default function JobCardAppointmentsPage({
}) { }) {
const { id: jobCardId } = use(params) const { id: jobCardId } = use(params)
const router = useRouter() const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams()
const jobCard = useJobCard() const jobCard = useJobCard()
useEffect(() => {
if (searchParams.get("create") !== "1") return
const params = new URLSearchParams(searchParams.toString())
params.delete("create")
params.set("dialog", "true")
router.replace(`${pathname}?${params.toString()}`)
}, [pathname, router, searchParams])
const defaultJobCard = jobCard const defaultJobCard = jobCard
? { value: String((jobCard as any).id), label: (jobCard as any).label || (jobCard as any).title || `Job Card` } ? { value: String((jobCard as any).id), label: (jobCard as any).label || (jobCard as any).title || `Job Card` }
: null : null

View File

@ -48,7 +48,7 @@ export default function JobCardExpenseItemsPage({
const rows = (data as any)?.data ?? [] const rows = (data as any)?.data ?? []
const invalidate = () => queryClient.invalidateQueries({ queryKey }).then(() => router.refresh()) const invalidate = () => queryClient.invalidateQueries({ queryKey , refetchType:'all'}).then(() => router.refresh())
async function handleDelete(row: any) { async function handleDelete(row: any) {
const confirmed = await confirm({ const confirmed = await confirm({

View File

@ -58,15 +58,15 @@ export default async function JobCardDetailLayout(props: { params: Promise<{ id:
label: `Attachments (${docs?.length || 0})` label: `Attachments (${docs?.length || 0})`
}, },
{
href: `/sales/job-cards/${id}/appointments`,
label: `Appointments (${jobCard?.appointments_count || 0})`
},
// { // {
// href: `/sales/job-cards/${id}/inspections`, // href: `/sales/job-cards/${id}/inspections`,
// label: `Inspections (${(jobCard as any)?.inspections_count || 0})` // label: `Inspections (${(jobCard as any)?.inspections_count || 0})`
// }, // },
// {
// href: `/sales/job-cards/${id}/appointments`,
// label: `Appointments (${jobCard?.appointments_count || 0})`
// },
// { // {
// href: `/sales/job-cards/${id}/tasks`, // href: `/sales/job-cards/${id}/tasks`,

View File

@ -25,6 +25,7 @@ import { Ellipsis, Plus } from "lucide-react"
import type { ColumnDef } from "@tanstack/react-table" import type { ColumnDef } from "@tanstack/react-table"
import { JobCardPartForm } from "@/modules/job-cards/job-card-part-form" import { JobCardPartForm } from "@/modules/job-cards/job-card-part-form"
import { formatDate } from "@/shared/utils/formatters" import { formatDate } from "@/shared/utils/formatters"
import { JOB_CARD_ROUTES } from "@garage/api"
export default function JobCardPartsPage({ export default function JobCardPartsPage({
params, params,
@ -35,7 +36,7 @@ export default function JobCardPartsPage({
const api = useAuthApi() const api = useAuthApi()
const queryClient = useQueryClient() const queryClient = useQueryClient()
const router = useRouter() const router = useRouter()
const queryKey = ["job-card-parts", jobCardId] const queryKey = [JOB_CARD_ROUTES.GET_PARTS, jobCardId]
const [dialogOpen, setDialogOpen] = useState(false) const [dialogOpen, setDialogOpen] = useState(false)
const [editItem, setEditItem] = useState<any | null>(null) const [editItem, setEditItem] = useState<any | null>(null)
@ -47,7 +48,7 @@ export default function JobCardPartsPage({
const rows = (data as any)?.data ?? [] const rows = (data as any)?.data ?? []
const invalidate = () => queryClient.invalidateQueries({ queryKey }).then(() => router.refresh()) const invalidate = () => queryClient.invalidateQueries({ queryKey, type: 'all', refetchType: 'all' },).then(() => router.refresh())
async function handleDelete(row: any) { async function handleDelete(row: any) {
const confirmed = await confirm({ const confirmed = await confirm({

View File

@ -50,7 +50,7 @@ export default function JobCardServicesPage({
const rows = (data as any)?.data ?? [] const rows = (data as any)?.data ?? []
const invalidate = () => queryClient.invalidateQueries({ queryKey }).then(() => router.refresh()) const invalidate = () => queryClient.invalidateQueries({ queryKey , refetchType:'all'}).then(() => router.refresh())
async function handleDelete(row: any) { async function handleDelete(row: any) {
const confirmed = await confirm({ const confirmed = await confirm({

View File

@ -6,6 +6,7 @@ import { ColumnHeader } from '@/shared/data-view/table-view'
import FormDialog from '@/shared/components/form-dialog' import FormDialog from '@/shared/components/form-dialog'
import { ImportDataButton } from '@/shared/components/import-data-button' import { ImportDataButton } from '@/shared/components/import-data-button'
import { ExportDataButton } from '@/shared/components/export-data-button' import { ExportDataButton } from '@/shared/components/export-data-button'
import { DownloadSampleButton } from '@/shared/components/download-sample-button'
import { useAuthApi } from '@/shared/useApi' import { useAuthApi } from '@/shared/useApi'
import { VehicleForm } from '@/modules/vehicles/vehicle-form' import { VehicleForm } from '@/modules/vehicles/vehicle-form'
import { VEHICLE_ROUTES } from '@garage/api' import { VEHICLE_ROUTES } from '@garage/api'
@ -24,6 +25,10 @@ export default function VehiclesPage() {
headerProps={({ selectedItem, invalidateQuery }) => ({ headerProps={({ selectedItem, invalidateQuery }) => ({
actions: ( actions: (
<div className='flex items-center gap-2'> <div className='flex items-center gap-2'>
<DownloadSampleButton
onDownload={() => api.vehicles.downloadImportSample()}
fileName='vehicles-import-sample'
/>
<ImportDataButton <ImportDataButton
onImport={(file) => api.vehicles.importData(file)} onImport={(file) => api.vehicles.importData(file)}
onSuccess={invalidateQuery} onSuccess={invalidateQuery}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,21 @@
import { navGroups } from "@/config/navGroups"
function normalizeTitle(title: string) {
return title.trim().toLowerCase()
}
const titleToHref = new Map<string, string>()
for (const group of navGroups) {
for (const item of group.items) {
titleToHref.set(normalizeTitle(item.title), item.href)
for (const subItem of item.items ?? []) {
titleToHref.set(normalizeTitle(subItem.title), subItem.href)
}
}
}
export function getNavHrefByTitle(title: string) {
return titleToHref.get(normalizeTitle(title))
}

View File

@ -1,8 +1,10 @@
"use client" "use client"
import Link from "next/link"
import { FileText, FileSearch, Receipt, ShoppingCart } from "lucide-react" import { FileText, FileSearch, Receipt, ShoppingCart } from "lucide-react"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card" import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import type { DashboardData } from "./use-dashboard-data" import type { DashboardData } from "./use-dashboard-data"
import { getNavHrefByTitle } from "./nav-groups-links"
type Props = { data: DashboardData } type Props = { data: DashboardData }
@ -11,15 +13,15 @@ export function SalesPurchaseCards({ data }: Props) {
const purchase = data.purchase_totals const purchase = data.purchase_totals
const salesStats = [ const salesStats = [
{ label: "Inspections", value: sales?.inspections ?? 0, icon: FileSearch }, { label: "Inspections", value: sales?.inspections ?? 0, icon: FileSearch, href: getNavHrefByTitle("Inspections") },
{ label: "Estimates", value: sales?.estimates ?? 0, icon: FileText }, { label: "Estimates", value: sales?.estimates ?? 0, icon: FileText, href: getNavHrefByTitle("Estimates") },
{ label: "Invoices", value: sales?.invoices ?? 0, icon: Receipt }, { label: "Invoices", value: sales?.invoices ?? 0, icon: Receipt, href: getNavHrefByTitle("Invoices") },
] ]
const purchaseStats = [ const purchaseStats = [
{ label: "Purchase Orders", value: purchase?.purchase_orders ?? 0, icon: ShoppingCart }, { label: "Purchase Orders", value: purchase?.purchase_orders ?? 0, icon: ShoppingCart, href: getNavHrefByTitle("Purchase Orders") },
{ label: "Bills", value: purchase?.bills ?? 0, icon: Receipt }, { label: "Bills", value: purchase?.bills ?? 0, icon: Receipt, href: getNavHrefByTitle("Bills") },
{ label: "Expenses", value: purchase?.expenses ?? 0, icon: FileText }, { label: "Expenses", value: purchase?.expenses ?? 0, icon: FileText, href: getNavHrefByTitle("Expenses") },
] ]
return ( return (
@ -34,16 +36,30 @@ export function SalesPurchaseCards({ data }: Props) {
<CardContent> <CardContent>
<div className="grid grid-cols-3 gap-2"> <div className="grid grid-cols-3 gap-2">
{salesStats.map((stat) => ( {salesStats.map((stat) => (
<div stat.href ? (
key={stat.label} <Link
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center" key={stat.label}
> href={stat.href}
<stat.icon className="h-4 w-4 text-muted-foreground" /> className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center transition-colors hover:bg-muted/50"
<span className="text-lg font-bold">{stat.value}</span> >
<span className="text-[11px] text-muted-foreground leading-tight"> <stat.icon className="h-4 w-4 text-muted-foreground" />
{stat.label} <span className="text-lg font-bold">{stat.value}</span>
</span> <span className="text-[11px] text-muted-foreground leading-tight">
</div> {stat.label}
</span>
</Link>
) : (
<div
key={stat.label}
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center"
>
<stat.icon className="h-4 w-4 text-muted-foreground" />
<span className="text-lg font-bold">{stat.value}</span>
<span className="text-[11px] text-muted-foreground leading-tight">
{stat.label}
</span>
</div>
)
))} ))}
</div> </div>
</CardContent> </CardContent>
@ -59,16 +75,30 @@ export function SalesPurchaseCards({ data }: Props) {
<CardContent> <CardContent>
<div className="grid grid-cols-3 gap-2"> <div className="grid grid-cols-3 gap-2">
{purchaseStats.map((stat) => ( {purchaseStats.map((stat) => (
<div stat.href ? (
key={stat.label} <Link
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center" key={stat.label}
> href={stat.href}
<stat.icon className="h-4 w-4 text-muted-foreground" /> className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center transition-colors hover:bg-muted/50"
<span className="text-lg font-bold">{stat.value}</span> >
<span className="text-[11px] text-muted-foreground leading-tight"> <stat.icon className="h-4 w-4 text-muted-foreground" />
{stat.label} <span className="text-lg font-bold">{stat.value}</span>
</span> <span className="text-[11px] text-muted-foreground leading-tight">
</div> {stat.label}
</span>
</Link>
) : (
<div
key={stat.label}
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center"
>
<stat.icon className="h-4 w-4 text-muted-foreground" />
<span className="text-lg font-bold">{stat.value}</span>
<span className="text-[11px] text-muted-foreground leading-tight">
{stat.label}
</span>
</div>
)
))} ))}
</div> </div>
</CardContent> </CardContent>

View File

@ -5,7 +5,7 @@ import { confirm } from '@/shared/components/confirm-dialog';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/shared/components/ui/dropdown-menu' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/shared/components/ui/dropdown-menu'
import { Button } from '@/shared/components/ui/button' import { Button } from '@/shared/components/ui/button'
import { toast } from 'sonner' import { toast } from 'sonner'
import { Ellipsis, FileText, Pencil, Printer, Trash2 } from 'lucide-react'; import { CalendarPlus, Ellipsis, FileText, Pencil, Printer, Trash2 } from 'lucide-react';
import { useDocumentPrint } from '@/shared/hooks/use-document-print'; import { useDocumentPrint } from '@/shared/hooks/use-document-print';
import { useJobCard } from './job-card-context'; import { useJobCard } from './job-card-context';
import { useState } from 'react'; import { useState } from 'react';
@ -30,6 +30,10 @@ export default function JobCardDropdown({ id }: { id: string }) {
print("job_card", id, "print") print("job_card", id, "print")
} }
const handleCreateAppointment = () => {
router.push(`/sales/job-cards/${id}/appointments?create=1`)
}
const handleConvertToInvoice = async () => { const handleConvertToInvoice = async () => {
const confirmed = await confirm({ const confirmed = await confirm({
title: "Convert to Invoice", title: "Convert to Invoice",
@ -52,7 +56,7 @@ export default function JobCardDropdown({ id }: { id: string }) {
toast.info("An invoice already exists for this job card.") toast.info("An invoice already exists for this job card.")
router.push(`/sales/invoice/${conflictId}`) router.push(`/sales/invoice/${conflictId}`)
} else { } else {
toast.error("Failed to convert job card to invoice") toast.error(err?.message || "Failed to convert job card to invoice")
} }
} finally { } finally {
setIsConverting(false) setIsConverting(false)
@ -78,38 +82,52 @@ export default function JobCardDropdown({ id }: { id: string }) {
} }
} }
return ( return (
<div className="flex items-center gap-2">
{jobCard?.status !== "draft" && (
<DropdownMenu> <Button variant="outline" onClick={handleConvertToInvoice} disabled={isConverting}>
<DropdownMenuTrigger asChild> <FileText className="size-4" />
<Button variant="outline" size="icon" className="self-stretch h-auto aspect-square"> {isConverting ? "Converting..." : "Convert to Invoice"}
<Ellipsis className="size-4" />
</Button> </Button>
</DropdownMenuTrigger> )}
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={handleEdit}> <Button variant="outline" onClick={handleCreateAppointment}>
<Pencil className="size-4" /> <CalendarPlus className="size-4" />
Edit Create Appointment
</DropdownMenuItem> </Button>
<DropdownMenuItem onClick={handlePrint} disabled={isPrinting}>
<Printer className="size-4" /> <DropdownMenu>
{isPrinting ? "Printing..." : "Print"} <DropdownMenuTrigger asChild>
</DropdownMenuItem> <Button variant="outline" size="icon" className="self-stretch h-auto aspect-square">
{jobCard?.status !== "draft" && ( <Ellipsis className="size-4" />
<> </Button>
<DropdownMenuSeparator /> </DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={handleEdit}>
<Pencil className="size-4" />
Edit
</DropdownMenuItem>
<DropdownMenuItem onClick={handlePrint} disabled={isPrinting}>
<Printer className="size-4" />
{isPrinting ? "Printing..." : "Print"}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleCreateAppointment}>
<CalendarPlus className="size-4" />
Create Appointment
</DropdownMenuItem>
{jobCard?.status !== "draft" && (
<DropdownMenuItem onClick={handleConvertToInvoice} disabled={isConverting}> <DropdownMenuItem onClick={handleConvertToInvoice} disabled={isConverting}>
<FileText className="size-4" /> <FileText className="size-4" />
{isConverting ? "Converting..." : "Convert to Invoice"} {isConverting ? "Converting..." : "Convert to Invoice"}
</DropdownMenuItem> </DropdownMenuItem>
</> )}
)} <DropdownMenuSeparator />
<DropdownMenuSeparator /> <DropdownMenuItem variant="destructive" onClick={handleDelete}>
<DropdownMenuItem variant="destructive" onClick={handleDelete}> <Trash2 className="size-4" />
<Trash2 className="size-4" /> Delete
Delete </DropdownMenuItem>
</DropdownMenuItem> </DropdownMenuContent>
</DropdownMenuContent> </DropdownMenu>
</DropdownMenu> </div>
) )
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -0,0 +1 @@
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}

View File

@ -0,0 +1,47 @@
"use client"
import { useState } from "react"
import { Button } from "@/shared/components/ui/button"
import { Download, Loader2 } from "lucide-react"
import { toast } from "sonner"
type DownloadSampleButtonProps = {
onDownload: () => Promise<Blob>
fileName?: string
label?: string
}
export function DownloadSampleButton({
onDownload,
fileName = "import-sample",
label = "Sample",
}: DownloadSampleButtonProps) {
const [isPending, setIsPending] = useState(false)
const handleDownload = async () => {
setIsPending(true)
try {
const blob = await onDownload()
const url = URL.createObjectURL(blob)
const anchor = document.createElement("a")
anchor.href = url
anchor.download = `${fileName}.xlsx`
document.body.appendChild(anchor)
anchor.click()
document.body.removeChild(anchor)
URL.revokeObjectURL(url)
toast.success("Sample downloaded successfully")
} catch (err: any) {
toast.error(err?.message ?? "Failed to download sample")
} finally {
setIsPending(false)
}
}
return (
<Button size="sm" variant="outline" disabled={isPending} onClick={handleDownload}>
{isPending ? <Loader2 className="animate-spin" /> : <Download />}
{label}
</Button>
)
}

View File

@ -1700,6 +1700,19 @@
} }
} }
}, },
"/api/customers/import/sample": {
"get": {
"tags": [
"Customers"
],
"summary": "Download customers import sample (xlsx/csv)",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/customers/import": { "/api/customers/import": {
"post": { "post": {
"tags": [ "tags": [
@ -5122,6 +5135,19 @@
} }
} }
}, },
"/api/vehicles/import/sample": {
"get": {
"tags": [
"Vehicles"
],
"summary": "Download vehicles import sample (xlsx/csv)",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/vehicles/import": { "/api/vehicles/import": {
"post": { "post": {
"tags": [ "tags": [
@ -32921,6 +32947,19 @@
} }
} }
}, },
"/api/parts/import/sample": {
"get": {
"tags": [
"Import Parts"
],
"summary": "Download parts import sample (xlsx/csv)",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/parts/import": { "/api/parts/import": {
"post": { "post": {
"tags": [ "tags": [
@ -35132,6 +35171,19 @@
} }
} }
}, },
"/api/services/import/sample": {
"get": {
"tags": [
"Import Services"
],
"summary": "Download services import sample (xlsx/csv)",
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/import-services": { "/api/import-services": {
"post": { "post": {
"tags": [ "tags": [

View File

@ -1,6 +1,6 @@
{ {
"info": { "info": {
"_postman_id": "6ef9e473-ce87-4b4b-9e48-89d153d50fca", "_postman_id": "559bc27f-b656-4554-a080-73c56d317ce5",
"name": "Reparee Collection", "name": "Reparee Collection",
"description": "Auto-generated from OpenAPI spec. Import storage/app/openapi-default.json for the full schema.", "description": "Auto-generated from OpenAPI spec. Import storage/app/openapi-default.json for the full schema.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
@ -1343,6 +1343,48 @@
} }
] ]
}, },
{
"name": "Download customers import sample (xlsx/csv)",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{auth_token}}",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "Accept",
"value": "*/*"
}
],
"url": {
"raw": "{{base_url}}/api/customers/import/sample?format=xlsx",
"host": [
"{{base_url}}"
],
"path": [
"api",
"customers",
"import",
"sample"
],
"query": [
{
"key": "format",
"value": "xlsx",
"description": "xlsx | csv"
}
]
}
},
"response": []
},
{ {
"name": "Import customers from Excel file.", "name": "Import customers from Excel file.",
"request": { "request": {
@ -4917,6 +4959,48 @@
} }
] ]
}, },
{
"name": "Download vehicles import sample (xlsx/csv)",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{auth_token}}",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "Accept",
"value": "*/*"
}
],
"url": {
"raw": "{{base_url}}/api/vehicles/import/sample?format=xlsx",
"host": [
"{{base_url}}"
],
"path": [
"api",
"vehicles",
"import",
"sample"
],
"query": [
{
"key": "format",
"value": "xlsx",
"description": "xlsx | csv"
}
]
}
},
"response": []
},
{ {
"name": "Import vehicles from Excel file.", "name": "Import vehicles from Excel file.",
"request": { "request": {
@ -24371,6 +24455,48 @@
{ {
"name": "Import Parts", "name": "Import Parts",
"item": [ "item": [
{
"name": "Download parts import sample (xlsx/csv)",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{auth_token}}",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "Accept",
"value": "*/*"
}
],
"url": {
"raw": "{{base_url}}/api/parts/import/sample?format=xlsx",
"host": [
"{{base_url}}"
],
"path": [
"api",
"parts",
"import",
"sample"
],
"query": [
{
"key": "format",
"value": "xlsx",
"description": "xlsx | csv"
}
]
}
},
"response": []
},
{ {
"name": "Import parts from Excel file.", "name": "Import parts from Excel file.",
"request": { "request": {
@ -26187,6 +26313,48 @@
{ {
"name": "Import Services", "name": "Import Services",
"item": [ "item": [
{
"name": "Download services import sample (xlsx/csv)",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{auth_token}}",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "Accept",
"value": "*/*"
}
],
"url": {
"raw": "{{base_url}}/api/services/import/sample?format=xlsx",
"host": [
"{{base_url}}"
],
"path": [
"api",
"services",
"import",
"sample"
],
"query": [
{
"key": "format",
"value": "xlsx",
"description": "xlsx | csv"
}
]
}
},
"response": []
},
{ {
"name": "Import services from Excel file.", "name": "Import services from Excel file.",
"request": { "request": {
@ -43393,7 +43561,7 @@
{ {
"key": "type", "key": "type",
"value": "invoice", "value": "invoice",
"description": "inspection | estimate | job_card | invoice | payment_received | expense | purchase_order | bill | payment_made" "description": "Allowed values: inspection | estimate | job_card | invoice | payment_received | expense | purchase_order | bill | payment_made"
}, },
{ {
"key": "id", "key": "id",
@ -43435,7 +43603,12 @@
], ],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\n \"type\": \"job_card\",\n \"id\": 1,\n \"mode\": \"print\"\n}" "raw": "{\n \"type\": \"job_card\",\n \"id\": 1,\n \"mode\": \"print\"\n}",
"options": {
"raw": {
"language": "json"
}
}
}, },
"url": { "url": {
"raw": "{{base_url}}/api/document-print", "raw": "{{base_url}}/api/document-print",

View File

@ -1,6 +1,6 @@
import { CrudClient } from "../infra/crud-client" import { CrudClient } from "../infra/crud-client"
import { ApiClient, type ApiClientOptions } from "../infra/client" import type { ApiClientOptions } from "../infra/client"
import type { ApiPath, ApiRequestBody } from "../infra/types" import type { ApiPath } from "../infra/types"
import type { ApiListQueryParams } from "../contracts/types" import type { ApiListQueryParams } from "../contracts/types"
export const CUSTOMER_ROUTES = { export const CUSTOMER_ROUTES = {
@ -8,6 +8,7 @@ export const CUSTOMER_ROUTES = {
BY_ID: "/api/customers/{id}", BY_ID: "/api/customers/{id}",
EXPORT: "/api/customers/export", EXPORT: "/api/customers/export",
IMPORT: "/api/customers/import", IMPORT: "/api/customers/import",
IMPORT_SAMPLE: "/api/customers/import/sample",
CUSTOMER_TYPES: "/api/customer-types", CUSTOMER_TYPES: "/api/customer-types",
NOTES: "/api/customers/{id}/notes/{note_id}", NOTES: "/api/customers/{id}/notes/{note_id}",
} as const satisfies Record<string, ApiPath> } as const satisfies Record<string, ApiPath>
@ -15,7 +16,15 @@ export const CUSTOMER_ROUTES = {
export class CustomersClient extends CrudClient<typeof CUSTOMER_ROUTES.INDEX, typeof CUSTOMER_ROUTES.BY_ID> { export class CustomersClient extends CrudClient<typeof CUSTOMER_ROUTES.INDEX, typeof CUSTOMER_ROUTES.BY_ID> {
constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) { constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
super(baseUrl, defaultOptions, CUSTOMER_ROUTES.INDEX, CUSTOMER_ROUTES.BY_ID) super(
baseUrl,
defaultOptions,
CUSTOMER_ROUTES.INDEX,
CUSTOMER_ROUTES.BY_ID,
CUSTOMER_ROUTES.IMPORT,
CUSTOMER_ROUTES.EXPORT,
"GET",
)
} }
async getById(id: string) { async getById(id: string) {
@ -26,12 +35,8 @@ export class CustomersClient extends CrudClient<typeof CUSTOMER_ROUTES.INDEX, ty
return this.get(CUSTOMER_ROUTES.CUSTOMER_TYPES, query ? { query } as never : undefined) return this.get(CUSTOMER_ROUTES.CUSTOMER_TYPES, query ? { query } as never : undefined)
} }
async export() { async downloadImportSample() {
return this.get(CUSTOMER_ROUTES.EXPORT) return this.fetchBlob(CUSTOMER_ROUTES.IMPORT_SAMPLE, { method: "GET" })
}
async import(payload: ApiRequestBody<typeof CUSTOMER_ROUTES.IMPORT, "post">) {
return this.post(CUSTOMER_ROUTES.IMPORT, payload)
} }
async addNote(id: string, payload: { note: string }) { async addNote(id: string, payload: { note: string }) {

View File

@ -8,6 +8,7 @@ export const VEHICLE_ROUTES = {
BY_ID: "/api/vehicles/{id}", BY_ID: "/api/vehicles/{id}",
EXPORT: "/api/vehicles/export", EXPORT: "/api/vehicles/export",
IMPORT: "/api/vehicles/import", IMPORT: "/api/vehicles/import",
IMPORT_SAMPLE: "/api/vehicles/import/sample",
GET_OWNERS: "/api/get-vehicle-owners", GET_OWNERS: "/api/get-vehicle-owners",
LINK_CUSTOMER: "/api/link-customer-to-vehicle", LINK_CUSTOMER: "/api/link-customer-to-vehicle",
UNLINK_CUSTOMER: "/api/unlink-customer-from-vehicle", UNLINK_CUSTOMER: "/api/unlink-customer-from-vehicle",
@ -31,7 +32,15 @@ export class VehiclesClient extends CrudClient<
typeof VEHICLE_ROUTES.BY_ID typeof VEHICLE_ROUTES.BY_ID
> { > {
constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) { constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
super(baseUrl, defaultOptions, VEHICLE_ROUTES.INDEX, VEHICLE_ROUTES.BY_ID) super(
baseUrl,
defaultOptions,
VEHICLE_ROUTES.INDEX,
VEHICLE_ROUTES.BY_ID,
VEHICLE_ROUTES.IMPORT,
VEHICLE_ROUTES.EXPORT,
"GET",
)
} }
@ -53,12 +62,8 @@ export class VehiclesClient extends CrudClient<
return this.postFormData(url, fd) return this.postFormData(url, fd)
} }
async export() { async downloadImportSample() {
return this.get(VEHICLE_ROUTES.EXPORT) return this.fetchBlob(VEHICLE_ROUTES.IMPORT_SAMPLE, { method: "GET" })
}
async import(payload: ApiRequestBody<typeof VEHICLE_ROUTES.IMPORT, "post">) {
return this.post(VEHICLE_ROUTES.IMPORT, payload)
} }
async getOwners(vehicleId: string | number, query?: ApiListQueryParams) { async getOwners(vehicleId: string | number, query?: ApiListQueryParams) {

View File

@ -72,7 +72,7 @@ export abstract class CrudClient<
if (this.exportMethod === "POST") { if (this.exportMethod === "POST") {
return this.fetchBlob(route, { method: "POST", body: filters ?? {} }) return this.fetchBlob(route, { method: "POST", body: filters ?? {} })
} }
return this.fetchBlob(route) return this.fetchBlob(route, { method: "GET" })
} }
} }

View File

@ -1005,6 +1005,40 @@ export interface paths {
patch?: never; patch?: never;
trace?: never; trace?: never;
}; };
"/api/customers/import/sample": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Download customers import sample (xlsx/csv) */
get: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/customers/import": { "/api/customers/import": {
parameters: { parameters: {
query?: never; query?: never;
@ -3568,6 +3602,40 @@ export interface paths {
patch?: never; patch?: never;
trace?: never; trace?: never;
}; };
"/api/vehicles/import/sample": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Download vehicles import sample (xlsx/csv) */
get: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/vehicles/import": { "/api/vehicles/import": {
parameters: { parameters: {
query?: never; query?: never;
@ -22368,6 +22436,40 @@ export interface paths {
patch?: never; patch?: never;
trace?: never; trace?: never;
}; };
"/api/parts/import/sample": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Download parts import sample (xlsx/csv) */
get: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/parts/import": { "/api/parts/import": {
parameters: { parameters: {
query?: never; query?: never;
@ -23938,6 +24040,40 @@ export interface paths {
patch?: never; patch?: never;
trace?: never; trace?: never;
}; };
"/api/services/import/sample": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Download services import sample (xlsx/csv) */
get: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/import-services": { "/api/import-services": {
parameters: { parameters: {
query?: never; query?: never;