feat(web): scope email editor 'Preview as' to the campaign's segment#394
Open
hanamizuki wants to merge 1 commit into
Open
feat(web): scope email editor 'Preview as' to the campaign's segment#394hanamizuki wants to merge 1 commit into
hanamizuki wants to merge 1 commit into
Conversation
Contributor
Author
|
Heads-up on CI: Lint & Type Check passes. The single Test Suite failure is |
The 'Preview as' dropdown in the campaign email editor previously listed the first 50 contacts of the entire project, regardless of who the campaign actually targets. For SEGMENT-audience campaigns this is misleading -- you'd preview rendered variables against contacts that will never receive the email. Scope the dropdown to the selected segment's members when the campaign uses CampaignAudienceType.SEGMENT, falling back to all contacts for ALL audiences (and templates, which pass no segmentId -- behaviour unchanged). - add useSegmentContacts() hook backed by the existing GET /segments/:id/contacts endpoint (handles both STATIC and DYNAMIC segments, page=1 pageSize=50) - EmailEditor gains an optional segmentId prop and switches its contact source accordingly; clears the preview selection when the chosen contact leaves the list (e.g. the segment changed) - campaigns/[id] and campaigns/create pass segmentId only when the audience is SEGMENT
3b34716 to
1f6b407
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In the campaign email editor, the Preview as: dropdown lists the first 50 contacts of the entire project, regardless of who the campaign actually targets. For campaigns that target a segment, this is misleading — you end up previewing rendered variables against contacts who will never receive the email.
This PR scopes the dropdown to the selected segment's members when the campaign's audience type is
SEGMENT. ForALL-audience campaigns (and templates, which target everyone) the behaviour is unchanged.How
useSegmentContacts()(apps/web/src/lib/hooks/useContacts.ts), backed by the existingGET /segments/:id/contactsendpoint. That endpoint already resolves bothSTATIC(viaSegmentMembership) andDYNAMIC(via condition) segments and returns aPaginatedResponse<Contact>. No backend changes. WhensegmentIdis empty the SWR key isnull, so no request is fired.EmailEditorgains an optionalsegmentIdprop and switches its preview contact source accordingly. When the currently-selected preview contact is no longer in the list (e.g. the segment changed), the selection is cleared so the preview doesn't stay stuck on a now-unlisted contact.campaigns/[id].tsxandcampaigns/create.tsxpasssegmentIdonly when the audience isCampaignAudienceType.SEGMENT.Scope / notes
SEGMENTaudiences are scoped.ALLkeeps listing all contacts.FILTERED(an ad-hoc, unsavedaudienceCondition) is intentionally not covered — there is no existing endpoint to resolve an unsaved condition to a contact list, and adding one is out of scope here.segmentId, so their editor behaviour is fully backward-compatible.useContactsis only consumed byEmailEditor.page=1&pageSize=50, consistent with the previous 50-contact preview cap and within the endpoint'spageSizelimit.