feat: add CSV import/export for gear collection
Adds export (GET /api/items/export) and import (POST /api/items/import) routes backed by a pure csv.service with no external deps, plus useExportItems/useImportItems hooks and an Import/Export section in the Settings page. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { CreateItem } from "../../shared/types";
|
||||
import { apiDelete, apiGet, apiPost, apiPut } from "../lib/api";
|
||||
import { apiDelete, apiGet, apiPost, apiPut, apiUpload } from "../lib/api";
|
||||
|
||||
interface Item {
|
||||
id: number;
|
||||
@@ -96,3 +96,27 @@ export function useDuplicateItem() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useExportItems() {
|
||||
return function exportItems() {
|
||||
window.location.href = "/api/items/export";
|
||||
};
|
||||
}
|
||||
|
||||
interface ImportResult {
|
||||
imported: number;
|
||||
createdCategories: string[];
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
export function useImportItems() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (file: File) =>
|
||||
apiUpload<ImportResult>("/api/items/import", file),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["items"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["totals"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user