Skip to content

Commit

Permalink
pull master
Browse files Browse the repository at this point in the history
  • Loading branch information
0101oak committed Sep 11, 2024
1 parent 69e3513 commit 7e2e275
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/components/managers/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ export const Settings: FC = () => {

const debouncedHandleFieldChange = useCallback(debounce(handleFieldChange, 1000), []);

const handleCheckboxChange = (
index: number,
values: UpdateSettingsRequest,
setFieldValue: any,
) => {
const updatedCarriers = values.shipmentCarriers?.map((carrier, idx) => ({
...carrier,
allow: idx === index,
}));
setFieldValue('shipmentCarriers', updatedCarriers);
debouncedHandleFieldChange({
...values,
shipmentCarriers: updatedCarriers,
});
};

return (
<Layout>
<Formik initialValues={settings} enableReinitialize={true} onSubmit={() => {}}>
Expand Down Expand Up @@ -121,15 +137,7 @@ export const Settings: FC = () => {
<Checkbox
{...field}
checked={field.value ?? false}
onChange={(e) => {
field.onChange(e);
handleFieldChange({
...values,
shipmentCarriers: values.shipmentCarriers?.map((c, idx) =>
idx === index ? { ...c, allow: e.target.checked } : c,
),
});
}}
onChange={() => handleCheckboxChange(index, values, setFieldValue)}
/>
}
label={carrier.carrier}
Expand Down

0 comments on commit 7e2e275

Please sign in to comment.