@W-19143871 Marketing Consent Footer Email Capture component with Shopper Consents hooks#3674
Conversation
…pper Consents hooks.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
…mmunications. Email capture component updated in footer section to use Shopper Consents API. [#3674]
…scription footer component
| [formatMessage] | ||
| ) | ||
|
|
||
| const handleSignUp = useCallback(async () => { |
There was a problem hiding this comment.
Can a user click on the signup button multiple times to create duplicate submissions or race conditions?
There was a problem hiding this comment.
this would be handled gracefully in the ECOM back-end, by nature of relying on the ECOM DB to persist the opt-in/opt-out preference for the user, in the order the request were received. The last one received will overwrite any prior ones.
| * Regular expression for email validation | ||
| * Validates standard email format with domain and TLD | ||
| */ | ||
| export const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*\.[a-zA-Z]{2,}$/ |
There was a problem hiding this comment.
Reuse the logic in email-utils.js?
packages/template-retail-react-app/app/utils/subscription-validators.js
Outdated
Show resolved
Hide resolved
| * @param {string} phone - The phone number to validate | ||
| * @returns {ValidationResult} Validation result with error code if invalid | ||
| */ | ||
| export const validatePhone = (phone) => { |
There was a problem hiding this comment.
Is this actually used anywhere?
There was a problem hiding this comment.
nope! But I wanted to leave tests and validations for completeness on the API, as trying to interact with various Consents APIs (even ones we don't demonstrate in the example) require a particular E164 format for phone numbers.
| {state?.feedback?.message && ( | ||
| <Alert status={state.feedback.type === 'error' ? 'error' : 'success'} mb={4}> | ||
| <AlertIcon /> | ||
| <AlertDescription>{state.feedback.message}</AlertDescription> |
There was a problem hiding this comment.
Is the UX calling for inline alert instead of toast?
There was a problem hiding this comment.
Yes. Perhaps a Toast could work, but it would show at the top of the app. I forget the UX reasons for making it inline. I can ask if they recall.
packages/template-retail-react-app/app/components/subscription/hooks/use-email-subscription.js
Show resolved
Hide resolved
…mail subscription hooks to follow react-hook-form pattern. Consolidated email and phone number validations to common util.
…D must be more than 1 character.
…or footer component size. Made a11y improvements to contrast.
…sted from client rather than server, so it doesn't need to be loaded on each page SSR.
…pper Consents hooks (#3674) - Updated Email Subscription component (in the footer section) with Shopper Consents hooks, also with updated styling and labels. - Updated commerce-sdk-react to use Shopper Consents hooks. - Fix for email validation on marketing consent capture: TLD must be more than 1 character. - Increase package max size from 90KB to 95KB, accounting for footer component size. - Check for feature enablement via Shopper Configurations API (feature=>`EnableConsentWithMarketingCloud`)
This feature is to add support for shopper subscriptions to marketing communications. An example is included as the email subscription component in the footer section.
Description
The feature uses the Shopper Consents API to opt shoppers into consent subscriptions configured by an administrator in B2C Commerce.
Requires the
EnableConsentWithMarketingCloudShopper Configurations flag is set (meaning the feature is enabled in ECOM).SLAS Client requires the scope
sfcc.shopper-consentsto read consent options, andsfcc.shopper-consents.rwto submit consent (opt-in or opt-out).As an example, the SubscribeMarketingConsent footer component uses the useMarketingConsent hook for managing consent data and mutations via useEmailSubscription to help manage email subscriptions. This example footer component will not attempt any callouts if the feature is disabled (as indicated by the
EnableConsentWithMarketingCloudShopper Configurations flag).Types of Changes
Changes
EnableConsentWithMarketingCloud)How to Test-Drive This PR
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization
Screenshots: