diff --git a/src/shared/stores/entry-form-store.js b/src/shared/stores/entry-form-store.js index 7cf4d976cb..5d9939ca72 100644 --- a/src/shared/stores/entry-form-store.js +++ b/src/shared/stores/entry-form-store.js @@ -1,26 +1,26 @@ import { setIn, getIn } from 'final-form' import create from 'zustand' -import { devtools } from 'zustand/middleware' + const inititalState = { errors: {}, warnings: {}, } -export const useEntryFormStore = create( - devtools((set, get) => ({ - ...inititalState, - setErrors: (errors) => set({ errors: errors ?? {} }), - getErrors: () => get().errors, - getNumberOfErrors: () => countLeaves(get().getErrors()), - getWarnings: () => get().warnings, - getWarning: (fieldname) => getIn(get().getWarnings(), fieldname), - setWarning: (fieldname, warning) => { - const warnings = get().getWarnings() || {} - const newWarnings = setIn(warnings, fieldname, warning) - set({ warnings: newWarnings }) - }, - })) -) +export const useEntryFormStore = create((set, get) => ({ + ...inititalState, + setErrors: (errors) => set({ errors: errors ?? {} }), + getErrors: () => get().errors, + getNumberOfErrors: () => countLeaves(get().getErrors()), + getWarnings: () => get().warnings, + getWarning: (fieldname) => getIn(get().getWarnings(), fieldname), + setWarning: (fieldname, warning) => { + const warnings = get().getWarnings() + // setIn from final-form is used to create the same structure as errors + const newWarnings = setIn(warnings, fieldname, warning) + set({ warnings: newWarnings }) + }, + // could add getNumberOfWarnings if needed +})) // errors object is the same shape as form-Values // eg. { [dataElementId] : {