|
| 1 | +--- |
| 2 | +"@bigcommerce/catalyst-core": patch |
| 3 | +--- |
| 4 | + |
| 5 | +Implement functional newsletter subscription feature with BigCommerce GraphQL API integration. |
| 6 | + |
| 7 | +## What Changed |
| 8 | + |
| 9 | +- Replaced the mock implementation in `subscribe.ts` with a real BigCommerce GraphQL API call using the `SubscribeToNewsletterMutation`. |
| 10 | +- Added comprehensive error handling for invalid emails, already-subscribed users, and unexpected errors. |
| 11 | +- Improved form error handling in `InlineEmailForm` to use `form.errors` instead of field-level errors for better error display. |
| 12 | +- Added comprehensive E2E tests and test fixtures for subscription functionality. |
| 13 | + |
| 14 | +## Migration Guide |
| 15 | + |
| 16 | +Replace the `subscribe` action in `core/components/subscribe/_actions/subscribe.ts` with the latest changes to include: |
| 17 | +- BigCommerce GraphQL mutation for newsletter subscription |
| 18 | +- Error handling for invalid emails, already-subscribed users, and unexpected errors |
| 19 | +- Proper error messages returned via Conform's `submission.reply()` |
| 20 | + |
| 21 | +Update `inline-email-form` to fix issue of not showing server-side error messages from form actions. |
| 22 | + |
| 23 | +**`core/vibes/soul/primitives/inline-email-form/index.tsx`** |
| 24 | + |
| 25 | +1. Add import for `FieldError` component: |
| 26 | +```tsx |
| 27 | +import { FieldError } from '@/vibes/soul/form/field-error'; |
| 28 | +``` |
| 29 | + |
| 30 | +2. Remove the field errors extraction: |
| 31 | +```tsx |
| 32 | +// Remove: const { errors = [] } = fields.email; |
| 33 | +``` |
| 34 | + |
| 35 | +3. Update border styling to check both form and field errors: |
| 36 | +```tsx |
| 37 | +// Changed from: |
| 38 | +errors.length ? 'border-error' : 'border-black', |
| 39 | + |
| 40 | +// Changed to: |
| 41 | +form.errors?.length || fields.email.errors?.length |
| 42 | + ? 'border-error focus-within:border-error' |
| 43 | + : 'border-black focus-within:border-primary', |
| 44 | +``` |
| 45 | + |
| 46 | +4. Update error rendering to display both field-level and form-level errors: |
| 47 | +```tsx |
| 48 | +// Changed from: |
| 49 | +{errors.map((error, index) => ( |
| 50 | + <FormStatus key={index} type="error"> |
| 51 | + {error} |
| 52 | + </FormStatus> |
| 53 | +))} |
| 54 | + |
| 55 | +// Changed to: |
| 56 | +{fields.email.errors?.map((error) => ( |
| 57 | + <FieldError key={error}>{error}</FieldError> |
| 58 | +))} |
| 59 | +{form.errors?.map((error, index) => ( |
| 60 | + <FormStatus key={index} type="error"> |
| 61 | + {error} |
| 62 | + </FormStatus> |
| 63 | +))} |
| 64 | +``` |
| 65 | + |
| 66 | +This change ensures that server-side error messages returned from form actions (like `formErrors` from Conform's `submission.reply()`) are now properly displayed to users. |
| 67 | + |
| 68 | +Add the following translation keys to your locale files (e.g., `messages/en.json`): |
| 69 | +```json |
| 70 | +{ |
| 71 | + "Components": { |
| 72 | + "Subscribe": { |
| 73 | + "title": "Sign up for our newsletter", |
| 74 | + "placeholder": "Enter your email", |
| 75 | + "description": "Stay up to date with the latest news and offers from our store.", |
| 76 | + "success": "You have been subscribed to our newsletter.", |
| 77 | + "Errors": { |
| 78 | + "subcriberAlreadyExists": "You are already subscribed to our newsletter.", |
| 79 | + "invalidEmail": "Please enter a valid email address.", |
| 80 | + "somethingWentWrong": "Something went wrong. Please try again later." |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
0 commit comments