feat: enhance import/export functionality with detailed results dialog and improved data handling
This commit is contained in:
@@ -60,7 +60,7 @@ export abstract class CrudClient<
|
||||
return this.delete<ByIdRoute>(this.byIdRoute as ByIdRoute, { params: { id } } as never) as never
|
||||
}
|
||||
|
||||
async importData(file: File): Promise<{ message?: string }> {
|
||||
async importData(file: File): Promise<ImportDataResponse> {
|
||||
const formData = new FormData()
|
||||
formData.append("file", file)
|
||||
const route = (this.importRoute ?? `${this.indexRoute}/import`) as string
|
||||
@@ -78,6 +78,26 @@ export abstract class CrudClient<
|
||||
|
||||
export type BaseCrudItem = { id: number }
|
||||
|
||||
export type ImportFailureRow = {
|
||||
row: number
|
||||
errors: {
|
||||
field: string
|
||||
label: string
|
||||
value: unknown
|
||||
message: string
|
||||
valid_examples?: string[]
|
||||
}[]
|
||||
}
|
||||
|
||||
export type ImportDataResponse = {
|
||||
message?: string
|
||||
data?: {
|
||||
imported_count: number
|
||||
failed_count: number
|
||||
failed_rows: ImportFailureRow[]
|
||||
}
|
||||
}
|
||||
|
||||
type ClientMethodReturn<C, TMethod extends PropertyKey> =
|
||||
C extends { [K in TMethod]: (...args: any[]) => infer TResult }
|
||||
? Awaited<TResult>
|
||||
|
||||
Reference in New Issue
Block a user