Skip to content

Commit

Permalink
Fix accidental mutation of the expiring offers defaults object
Browse files Browse the repository at this point in the history
  • Loading branch information
paninaro committed Oct 25, 2023
1 parent 9a544c1 commit cdc146f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function SettingsExpiringOffers(props) {
<SettingsLabel>
<Trans>Offer Expiration Time</Trans>
</SettingsLabel>
<Form methods={methods} onSubmit={methods.handleSubmit(handleSubmit)}>
<Form methods={methods} onSubmit={handleSubmit}>
<Flex flexDirection="column" gap={1}>
<Flex gap={2} sx={{ width: '100%', marginTop: 2 }}>
{fields.map((field) => (
Expand Down Expand Up @@ -79,7 +79,6 @@ export default function SettingsExpiringOffers(props) {
{isOfferExpirationDefaultTimeEnabled && (
<ButtonLoading
size="small"
type="submit"
variant="outlined"
color="secondary"
onClick={handleDisable}
Expand Down
9 changes: 4 additions & 5 deletions packages/gui/src/hooks/useOfferExpirationDefaultTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ function stringPropertiesToNumbers(objWithStrings: OfferExpirationDefaultTimeInp
}

export default function useOfferExpirationDefaultTime() {
const defaultsCopy = { ...offerExpirationDefaultTimeDefaults };
const [offerExpirationDefaultTime, setOfferExpirationDefaultTimeLocal] = usePrefs<OfferExpirationDefaultTimeOutput>(
'offerExpirationDefaultTime',
offerExpirationDefaultTimeDefaults
defaultsCopy // to avoid accidentally mutating the defaults object
);

const isOfferExpirationDefaultTimeEnabled = useMemo(
() => offerExpirationDefaultTime.enabled === true,
[offerExpirationDefaultTime]
);
const isOfferExpirationDefaultTimeEnabled = offerExpirationDefaultTime.enabled === true;

const setOfferExpirationDefaultTime = useCallback(
(offerExpirationDefaultTimeInput: OfferExpirationDefaultTimeInput) => {
Expand All @@ -68,5 +66,6 @@ export default function useOfferExpirationDefaultTime() {
() => ({ offerExpirationDefaultTime, setOfferExpirationDefaultTime, isOfferExpirationDefaultTimeEnabled }),
[offerExpirationDefaultTime, setOfferExpirationDefaultTime, isOfferExpirationDefaultTimeEnabled]
);

return toReturn;
}

0 comments on commit cdc146f

Please sign in to comment.