Skip to content

Commit 598a1eb

Browse files
committed
fix: add additional comments
1 parent 555dbe1 commit 598a1eb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

core/components/subscribe/_actions/subscribe.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,21 @@ export const subscribe = async (
5757

5858
const errors = response.data.newsletter.subscribe.errors;
5959

60-
// If there are no errors or the error is that the email already exists, we want to reset the form and show the success message
61-
if (
62-
!errors.length ||
63-
errors.some(({ __typename }) => __typename === 'CreateSubscriberAlreadyExistsError')
64-
) {
60+
const subcriberAlreadyExists = errors.some(
61+
({ __typename }) => __typename === 'CreateSubscriberAlreadyExistsError',
62+
);
63+
64+
// If there are no errors or the subscriber already exists, we want to reset the form and show the success message
65+
// This is for privacy reasons, we don't want to show the error message to the user if they are already subscribed
66+
if (!errors.length || subcriberAlreadyExists) {
6567
return {
6668
lastResult: submission.reply(),
6769
successMessage: t('subscribedToNewsletter'),
6870
};
6971
}
7072

7173
if (errors.length > 0) {
74+
// If there are other errors, we want to show the error message to the user
7275
return {
7376
lastResult: submission.reply({
7477
formErrors: errors.map(({ __typename }) => {

0 commit comments

Comments
 (0)