feat(FE): add master data production standard, slicing form and index table

This commit is contained in:
randy-ar
2025-12-27 03:23:03 +07:00
parent 4ddd1dc8e3
commit 663c1dea14
16 changed files with 1684 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
'use client';
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { FormStore } from '@/types/stores';
import { createProductionStandardFormSlice } from '@/stores/form/slices/production-standard-form.slice';
export const useFormStore = create<FormStore>()(
devtools(
persist(
(...args) => ({
...createProductionStandardFormSlice(...args),
}),
{
name: 'production-standard-form-cache',
}
),
{
name: 'FormStore',
}
)
);
@@ -0,0 +1,67 @@
import { StateCreator } from 'zustand';
import { FormStore } from '@/types/stores';
export const createProductionStandardFormSlice: StateCreator<
FormStore,
[],
[],
FormStore
> = (set): FormStore => ({
formData: null,
editMode: false,
editIndex: null,
setFormData: (data) =>
set(() => ({
formData: data,
})),
setEditMode: (mode, index) =>
set(() => ({
editMode: mode,
editIndex: index,
})),
addDetail: (detail) =>
set((state) => ({
formData: state.formData
? {
...state.formData,
details: [...state.formData.details, detail],
}
: null,
})),
updateDetail: (index, detail) =>
set((state) => {
if (!state.formData) return state;
const newDetails = [...state.formData.details];
newDetails[index] = detail;
return {
formData: {
...state.formData,
details: newDetails,
},
};
}),
deleteDetail: (index) =>
set((state) => {
if (!state.formData) return state;
const newDetails = [...state.formData.details];
newDetails.splice(index, 1);
return {
formData: {
...state.formData,
details: newDetails,
},
};
}),
clearCache: () =>
set(() => ({
formData: null,
editMode: false,
editIndex: null,
})),
});