fix build

This commit is contained in:
2026-04-15 04:59:05 +03:00
parent 020ffccfd6
commit 973149e974
28 changed files with 2352 additions and 89 deletions
@@ -25,6 +25,12 @@ export type ResourceSelectorDialogProps<TClient extends ResourcePageClient> = {
crudProps: Omit<CrudResourceProps<TClient>, "render" | "tableProps">
/** Optional rowKey for selection identity. Defaults to "id" */
rowKey?: keyof ResourceItem<TClient>
/**
* Selection mode.
* - "multi" (default): checkbox multi-select + Confirm button
* - "single": row click immediately fires onConfirm with the clicked row
*/
selectionMode?: "single" | "multi"
}
export function ResourceSelectorDialog<TClient extends ResourcePageClient>({
@@ -34,6 +40,7 @@ export function ResourceSelectorDialog<TClient extends ResourcePageClient>({
onConfirm,
crudProps,
rowKey,
selectionMode = "multi",
}: ResourceSelectorDialogProps<TClient>) {
type TItem = ResourceItem<TClient>
@@ -58,6 +65,11 @@ export function ResourceSelectorDialog<TClient extends ResourcePageClient>({
onOpenChange(false)
}
const handleRowClick = (row: TItem) => {
onConfirm([row])
onOpenChange(false)
}
return (
<Dialog open={open} onOpenChange={(v) => { if (!v) handleCancel() }}>
<DialogContent className="min-w-4xl max-h-[90vh] flex flex-col">
@@ -67,26 +79,35 @@ export function ResourceSelectorDialog<TClient extends ResourcePageClient>({
<div className="flex-1 overflow-auto">
<Card className="rounded-none border-0 shadow-none">
<CardContent className="p-0">
<CrudResource<TClient>
{...crudProps}
tableProps={{
selection: {
onSelectionChange: handleSelectionChange,
...(rowKey ? { rowKey } : {}),
},
}}
/>
{selectionMode === "single" ? (
<CrudResource<TClient>
{...crudProps}
onRowClick={handleRowClick}
/>
) : (
<CrudResource<TClient>
{...crudProps}
tableProps={{
selection: {
onSelectionChange: handleSelectionChange,
...(rowKey ? { rowKey } : {}),
},
}}
/>
)}
</CardContent>
</Card>
</div>
<DialogFooter>
<Button variant="outline" onClick={handleCancel}>
Cancel
</Button>
<Button onClick={handleConfirm} disabled={count === 0}>
Confirm{count > 0 ? ` (${count})` : ""}
</Button>
</DialogFooter>
{selectionMode === "multi" && (
<DialogFooter>
<Button variant="outline" onClick={handleCancel}>
Cancel
</Button>
<Button onClick={handleConfirm} disabled={count === 0}>
Confirm{count > 0 ? ` (${count})` : ""}
</Button>
</DialogFooter>
)}
</DialogContent>
</Dialog>
)
@@ -0,0 +1,59 @@
"use client"
import { useState } from "react"
import { useAuthApi } from "../useApi"
import { toast } from "sonner"
import type { DocumentPrintMode, DocumentPrintType } from "@garage/api"
interface UseDocumentPrintOptions {
onSuccess?: (blob: Blob) => void
onError?: (error: Error) => void
}
export function useDocumentPrint(options?: UseDocumentPrintOptions) {
const api = useAuthApi()
const [isPrinting, setIsPrinting] = useState(false)
const print = async (
type: DocumentPrintType,
id: string | number,
mode: DocumentPrintMode = "print",
filename?: string,
) => {
setIsPrinting(true)
try {
const blob = await api.documentPrint.print(type, id, mode)
const url = URL.createObjectURL(blob)
if (mode === "print") {
const win = window.open(url, "_blank")
if (win) {
win.addEventListener("load", () => {
win.print()
URL.revokeObjectURL(url)
})
} else {
URL.revokeObjectURL(url)
}
} else {
const a = document.createElement("a")
a.href = url
a.download = filename ?? `${type}-${id}.pdf`
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(url)
}
options?.onSuccess?.(blob)
} catch (error) {
toast.error("Failed to print document")
options?.onError?.(error as Error)
} finally {
setIsPrinting(false)
}
}
return { print, isPrinting }
}