Skip to content

Commit

Permalink
refactor: enable actions buttons when zero filling options are changed
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Sep 25, 2024
1 parent 174c0a6 commit a82039b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ export default function ZeroFillingOptionsPanel(
props: ZeroFillingOptionsPanelProps,
) {
const { filter } = props;
const { control, submitHandler, register, handleCancelFilter } =
useZeroFilling(filter);
const {
control,
submitHandler,
register,
handleCancelFilter,
formState: { isDirty },
} = useZeroFilling(filter);

const { onChange: onLivePreviewFieldChange, ...livePreviewFieldOptions } =
register('livePreview');

const disabledAction = filter.value && !isDirty;
return (
<>
<StickyHeader>
Expand All @@ -40,6 +47,8 @@ export default function ZeroFillingOptionsPanel(
<FilterActionButtons
onConfirm={() => submitHandler()}
onCancel={handleCancelFilter}
disabledConfirm={disabledAction}
disabledCancel={disabledAction}
/>
</HeaderContainer>
</StickyHeader>
Expand Down
17 changes: 10 additions & 7 deletions src/component/panels/filtersPanel/Filters/hooks/useZeroFilling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ export const useZeroFilling = (

const dispatch = useDispatch();
const previousPreviewRef = useRef<boolean>(true);
const { handleSubmit, register, reset, control, getValues } = useForm({
defaultValues: {
nbPoints:
(filter?.value as BaseZeroFillingOptions)?.nbPoints || defaultNbPoints,
livePreview: true,
},
});
const { handleSubmit, register, reset, control, getValues, formState } =
useForm({
defaultValues: {
nbPoints:
(filter?.value as BaseZeroFillingOptions)?.nbPoints ||
defaultNbPoints,
livePreview: true,
},
});

function syncWatch(sharedFilterOptions) {
reset({ ...getValues(), ...sharedFilterOptions });
Expand Down Expand Up @@ -123,5 +125,6 @@ export const useZeroFilling = (
submitHandler,
handleApplyFilter,
handleCancelFilter,
formState,
};
};

0 comments on commit a82039b

Please sign in to comment.