feat: add Zustand store for grid state and a hook to save draft modifications

This commit is contained in:
Michael committed 2026-03-19 15:17:28 +01:00
1 parent aa69637f98
commit 7cdbe8ec21
2 files changed
+17 -1

No files matched your search

+4 -1
View File
@@ -10,7 +10,7 @@ import { GammeCode } from "@/types/grid";
* Filters changes to only include those in the provided codeins list (e.g. current supplier).
*/
export function useSaveDrafts(magasin: string, filterCodeins?: string[]) {
const { draftChanges, rows, resetDrafts, clearDrafts } = useGridStore();
const { draftChanges, rows, resetDrafts, clearDrafts, applyDraftsToRows } = useGridStore();
// Only consider changes that are in the filter list (if provided)
const activeDrafts = filterCodeins
@@ -39,6 +39,9 @@ export function useSaveDrafts(magasin: string, filterCodeins?: string[]) {
const result = await saveDraftChanges({ codeFournisseur, nomFournisseur, magasin, changes });
if (result.success) {
// Apply saved values onto row.codeGamme BEFORE clearing drafts
// so that isModified (codeGamme !== codeGammeInit) stays true
applyDraftsToRows(activeDrafts);
if (filterCodeins) {
clearDrafts(Object.keys(activeDrafts));
} else {