Skip to content

Commit

Permalink
Fix newsletter choice being sent at loading time
Browse files Browse the repository at this point in the history
  • Loading branch information
255kb committed Feb 5, 2024
1 parent 9596d46 commit 6ffaf6a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions pages/account/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const AccountNotifications: FunctionComponent = function () {
const { isAuth, user, isLoading: isAuthLoading, getIdToken } = useAuth();
const router = useRouter();
const { data: emailingData } = useCurrentUserEmailing();
const { register: registerFormField, setValue, control } = useForm();
const {
register: registerFormField,
setValue,
control,
formState: { touchedFields, isDirty }
} = useForm();
const data = useWatch({ control });

useEffect(() => {
Expand All @@ -36,9 +41,18 @@ const AccountNotifications: FunctionComponent = function () {

useEffect(() => {
if (emailingData) {
setValue('newsletter', emailingData.newsletter);
setValue('productUpdates', emailingData.productUpdates);
setValue('coursePreview', emailingData.coursePreview);
setValue('newsletter', emailingData.newsletter, {
shouldDirty: false,
shouldTouch: false
});
setValue('productUpdates', emailingData.productUpdates, {
shouldDirty: false,
shouldTouch: false
});
setValue('coursePreview', emailingData.coursePreview, {
shouldDirty: false,
shouldTouch: false
});
}
}, [emailingData]);

Expand Down Expand Up @@ -69,10 +83,11 @@ const AccountNotifications: FunctionComponent = function () {
});

useEffect(() => {
if (data) {
console.log(isDirty);
if (data && isDirty) {
updateEmailing(data as EmailingStatuses);
}
}, [data]);
}, [data, isDirty]);

return (
<Layout footerBanner='contact'>
Expand Down

0 comments on commit 6ffaf6a

Please sign in to comment.