Skip to content

Commit

Permalink
Merge pull request #703 from sebgroup/develop
Browse files Browse the repository at this point in the history
minor dynamic form fix release
  • Loading branch information
mario-subo authored Jan 26, 2022
2 parents b4a44a7 + e3c1571 commit e0f064c
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions lib/src/hooks/useDynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,44 +328,53 @@ export function useDynamicForm(sections: DynamicFormSection[]): UseDynamicForm {
return { dirty, hasIndicators, isAllTruthy };
}, [dirty, hasIndicators, isAllTruthy]);

const handlePatchState: PatchState = (section: string, key: string, value: DynamicFormInternalStateValue) => {
setState((existingState) => ({
...existingState,
[section]: {
...(existingState[section] || {}),
[key]: value,
},
}));
};
const patchState: PatchState = useCallback(
(section: string, key: string, value: DynamicFormInternalStateValue) => {
setState((existingState) => ({
...existingState,
[section]: {
...(existingState[section] || {}),
[key]: value,
},
}));
},
[setState]
);

const handleSetIndicator: SetIndicator = (section: string, key: string, indicator: Indicator) => {
setIndicators((existingState) => ({
...existingState,
[section]: {
...(existingState[section] || {}),
[key]: indicator,
},
}));
};
const setIndicator: SetIndicator = useCallback(
(section: string, key: string, indicator: Indicator | null) => {
setIndicators((existingState) => ({
...existingState,
[section]: {
...(existingState[section] || {}),
[key]: indicator,
},
}));
},
[setIndicators]
);

const handleSetHidden: SetHidden = (section: string, key: string, hidden: boolean) => {
const visible: boolean = !hidden;
const setHidden: SetHidden = useCallback(
(section: string, key: string, hidden: boolean) => {
const visible: boolean = !hidden;

setVisibility((existingState) => ({
...existingState,
[section]: {
...(existingState[section] || {}),
[key]: visible,
},
}));
};
setVisibility((existingState) => ({
...existingState,
[section]: {
...(existingState[section] || {}),
[key]: visible,
},
}));
},
[setVisibility]
);

return {
renderForm,
state,
patchState: handlePatchState,
setIndicator: handleSetIndicator,
setHidden: handleSetHidden,
patchState,
setIndicator,
setHidden,
meta,
info: formInfo,
};
Expand Down

0 comments on commit e0f064c

Please sign in to comment.