feat: add CSV import/export for gear collection
Some checks failed
CI / ci (pull_request) Failing after 22s
CI / e2e (pull_request) Has been skipped

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:
2026-04-03 18:12:07 +02:00
parent 8c1fe47a99
commit 15f146ee89
6 changed files with 645 additions and 2 deletions

View File

@@ -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"] });
},
});
}