-
Notifications
You must be signed in to change notification settings - Fork 876
Newsletter: settings on WPDS Card primitives (PR 5 / #48530) #48608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
keoshi
wants to merge
7
commits into
try/newsletter-modernization-tabs
Choose a base branch
from
try/newsletter-modernization-wpds-cards
base: try/newsletter-modernization-tabs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2dcfbb1
Newsletter: convert the settings sections to WPDS Card primitives
keoshi 46929dc
Newsletter: changelog for the WPDS Card migration
keoshi 11b2ac7
Newsletter: space the settings cards 24px apart with breathing room b…
keoshi 6f0a2c7
Newsletter: port the subscribe-placement card primitive from #48420
keoshi 52f92d9
Newsletter: render subscribe placements as cards + per-placement Tracks
keoshi 395427f
Newsletter: split off Email defaults + reorder Settings IA
keoshi 77b3ffe
Newsletter: tag every section_save with the keys that changed
keoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
projects/packages/newsletter/changelog/add-wp-build-wpds-cards
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Significance: patch | ||
| Type: changed | ||
| Comment: Settings sections on the Newsletter modernization chassis now use the WPDS Card primitives, behind the same feature flag; no user-visible change unless the flag is enabled. |
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
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
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
92 changes: 92 additions & 0 deletions
92
projects/packages/newsletter/src/settings/sections/email-defaults-section.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { isSimpleSite } from '@automattic/jetpack-script-data'; | ||
| import { ToggleControl } from '@wordpress/components'; | ||
| import { DataForm, type Field } from '@wordpress/dataviews/wp'; | ||
| import { useCallback } from '@wordpress/element'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { Card } from '@wordpress/ui'; | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import type { NewsletterSettings } from '../types'; | ||
|
|
||
| interface EmailDefaultsSectionProps { | ||
| data: NewsletterSettings; | ||
| onChange: ( updates: Partial< NewsletterSettings > ) => void; | ||
| isNewsletterEnabled: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Email Defaults Section Component. | ||
| * | ||
| * Renders the "Email new posts to subscribers by default" toggle. The | ||
| * legacy master `subscriptions` toggle that used to live here moved to | ||
| * the global Newsletter module activation control — flipping the module | ||
| * off-page disables this card via the orchestrator's `<Disabled>` wrapper. | ||
| * | ||
| * @param props - Component props. | ||
| * @param props.data - Newsletter settings data. | ||
| * @param props.onChange - Auto-save callback for setting updates. | ||
| * @param props.isNewsletterEnabled - Whether the Newsletter module is on. | ||
| * @return The email defaults section. | ||
| */ | ||
| export function EmailDefaultsSection( { | ||
| data, | ||
| onChange, | ||
| isNewsletterEnabled, | ||
| }: EmailDefaultsSectionProps ): JSX.Element { | ||
| const fields: Field< NewsletterSettings >[] = [ | ||
| { | ||
| id: 'wpcom_newsletter_send_default', | ||
| label: __( 'Email new posts to subscribers by default', 'jetpack-newsletter' ), | ||
| type: 'boolean' as const, | ||
| Edit( { field, onChange: onChangeField, data: formData } ) { | ||
| const handleToggle = useCallback( () => { | ||
| onChangeField( | ||
| field.setValue( { | ||
| item: formData, | ||
| value: ! field.getValue( { item: formData } ), | ||
| } ) | ||
| ); | ||
| }, [ onChangeField, field, formData ] ); | ||
| return ( | ||
| <ToggleControl | ||
| label={ field.label } | ||
| help={ field.description } | ||
| checked={ !! field.getValue( { item: formData } ) } | ||
| onChange={ handleToggle } | ||
| disabled={ ! isSimpleSite() && ! isNewsletterEnabled } | ||
| /> | ||
| ); | ||
| }, | ||
| description: __( | ||
| 'When on, the newsletter option will be pre-selected each time you publish. You can change it in the newsletter panel in the editor before publishing any post.', | ||
| 'jetpack-newsletter' | ||
| ), | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <Card.Root> | ||
| <Card.Header> | ||
| <Card.Title>{ __( 'Email defaults', 'jetpack-newsletter' ) }</Card.Title> | ||
| </Card.Header> | ||
| <Card.Content> | ||
| <DataForm | ||
| data={ data } | ||
| fields={ fields } | ||
| form={ { | ||
| layout: { | ||
| type: 'regular', | ||
| labelPosition: 'top', | ||
| }, | ||
| fields: [ 'wpcom_newsletter_send_default' ], | ||
| } } | ||
| onChange={ onChange } | ||
| /> | ||
| </Card.Content> | ||
| </Card.Root> | ||
| ); | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have Notice component at WP UI but you might've intentionally left it for another PR.