/** * My Account's field groups, arranged into the two tabs `AccountSection` * renders: the signed-in area (`AccountLayoutFields`) and the signed-out * screen (`AccountLoginFields`). * * The split is by *who sees it* rather than by topic, which is the one line a * customer never crosses in a single visit — the login form and the endpoint * panel are never on screen together. It also lets each tab point the preview * at the screen it describes: the Login tab asks for a preview URL that renders * the signed-out template even though whoever is editing is signed in (see * `WooCommerce::maybe_preview_login_screen()`). * * Groups stay separately exported so a caller can reach for one on its own. */ import { __, sprintf } from '@wordpress/i18n'; import { ToggleControl, TextControl } from '@wordpress/components'; import { PanelLeft, UserRound, ListOrdered, LogIn, LayoutGrid, UserPlus, Star, Home, } from '../../../icons'; import SegmentedControl from '../../../controls/segmented-control'; import SelectField from '../../../controls/select-field'; import FieldGroup from '../../../controls/field-group'; import InfoNote from '../../../controls/info-note'; import type { WorkingSettings, SetPath } from '../../../types'; import type { WooSchema } from '../types'; import { toOptions } from '../shared'; interface BaseProps { schema: WooSchema; working: WorkingSettings; setPath: SetPath; } interface BenefitItem { icon: string; title: string; text: string; } // The slot's default glyph, matching the server's — used only until the first // save writes the list back. const DEFAULT_BENEFIT_ICONS = [ 'truck', 'lock-simple', 'heart' ]; const accountOf = ( working: WorkingSettings ) => ( ( ( working?.woocommerce ?? {} ) as Record< string, any > ).account ?? {} ) as Record< string, any >; // The signed-in account area: where the endpoint navigation sits, what it // shows, how the endpoint panel is framed, and how the lists inside it read. export function AccountLayoutFields( { schema, working, setPath }: BaseProps ) { const account = accountOf( working ); const navPosition = ( account.nav_position as string ) || 'left'; // What each blank dashboard field falls back to, from the server so the // placeholder and the rendered screen cannot drift apart. const pageCopy = { head: '', ...( schema.account_page_copy ?? {} ), }; const orders = { hero_text: '', tagline: '', ...( schema.account_orders_defaults ?? {} ), }; const dash = { hero_text: '', help_title: '', help_text: '', help_label: '', ...( schema.account_dashboard_defaults ?? {} ), }; return ( <> setPath( 'woocommerce.account.nav_position', next ) } help={ __( '“Top” runs the links as a row of chips above the panel. Narrow screens always use that row, whichever position is set here.', 'aureon' ) } /> setPath( 'woocommerce.account.nav_width', next ) } // Real, but inert while the links run across the top — // shown with the reason rather than hidden, so the setting // does not look lost. disabled={ 'top' === navPosition } help={ 'top' === navPosition ? __( 'The links run across the top, so there is no sidebar to size.', 'aureon' ) : undefined } /> setPath( 'woocommerce.account.nav_icons', value ) } /> setPath( 'woocommerce.account.avatar', value ) } /> setPath( 'woocommerce.account.panel_style', next ) } help={ __( '“Flush” drops the panel’s border and padding — for a page layout that already boxes its content.', 'aureon' ) } /> setPath( 'woocommerce.account.dashboard_hero', value ) } /> { false !== account.dashboard_hero && ( setPath( 'woocommerce.account.dashboard_hero_text', value ) } help={ __( 'Leave blank for the theme’s wording.', 'aureon' ) } /> ) } setPath( 'woocommerce.account.dashboard_links', value ) } /> setPath( 'woocommerce.account.account_head', value ) } /> { false !== account.account_head && ( setPath( 'woocommerce.account.account_head_text', value ) } help={ __( 'Leave blank for the theme’s wording.', 'aureon' ) } /> ) } setPath( 'woocommerce.account.page_banners', value ) } /> setPath( 'woocommerce.account.order_status_pills', value ) } /> setPath( 'woocommerce.account.orders_thumbs', value ) } /> setPath( 'woocommerce.account.orders_filters', value ) } /> setPath( 'woocommerce.account.orders_hero', value ) } /> { false !== account.orders_hero && ( <> setPath( 'woocommerce.account.orders_hero_text', value ) } /> setPath( 'woocommerce.account.orders_tagline', value ) } help={ __( 'Shown at the right of the banner on wide screens.', 'aureon' ) } /> ) } ); } // The signed-out screen — the login form, and the register form beside it on a // store with registration open. export function AccountLoginFields( { schema, working, setPath }: BaseProps ) { const account = accountOf( working ); // Absent (older cached schema) reads as "closed" rather than "open": a // false negative only leaves the layout control enabled with nothing to // arrange, while a false positive would claim a register form is there. const registrationOpen = true === schema.account_registration; const layout = ( account.login_layout as string ) || 'columns'; // What each blank field falls back to, from the server so the placeholder // and the rendered screen can never drift apart. The fallbacks here only // cover an older cached schema that lacks the block. const defaults = { welcome: '', welcome_single: '', perk_title: '', perk_text: '', benefits: [] as Array< { title: string; text: string } >, ...( schema.account_login_defaults ?? {} ), }; // Always three, in order — the row is a fixed-shape design. Missing slots // read as blank, which is what the server treats them as too. const benefits: BenefitItem[] = [ 0, 1, 2 ].map( ( index ) => { const item = ( account.login_benefit_items?.[ index ] ?? {} ) as Partial< BenefitItem >; return { icon: item.icon || DEFAULT_BENEFIT_ICONS[ index ], title: item.title ?? '', text: item.text ?? '', }; } ); // Written back as the whole list: a path per field would have to know how // `setPath` treats an array index, and the list is three short items. const setBenefit = ( index: number, patch: Partial< BenefitItem > ) => setPath( 'woocommerce.account.login_benefit_items', benefits.map( ( item, i ) => i === index ? { ...item, ...patch } : item ) ); const iconOptions = ( schema.account_benefit_icons ?? [] ).map( ( option ) => ( { value: option.value, label: option.label, } ) ); return ( <> { /* Registration is a store behaviour, not a presentation choice, so this reports WooCommerce's setting and says where to change it rather than offering to change it here. It is also what decides whether the layout control below has two forms to arrange, which is why it leads the tab. */ } { registrationOpen ? __( 'Customer registration is on, so a register form sits beside the login form. Change that under WooCommerce → Settings → Accounts & Privacy.', 'aureon' ) : __( 'Customer registration is off, so this screen shows the login form alone. Turn it on under WooCommerce → Settings → Accounts & Privacy.', 'aureon' ) } setPath( 'woocommerce.account.login_layout', next ) } disabled={ ! registrationOpen } help={ registrationOpen ? undefined : __( 'There is one form on this screen, so there is nothing to arrange.', 'aureon' ) } /> setPath( 'woocommerce.account.login_width', next ) } help={ __( 'The measure of a single form. Side by side and tabs set their own width.', 'aureon' ) } /> setPath( 'woocommerce.account.login_intro', value ) } /> { false !== account.login_intro && ( <> setPath( 'woocommerce.account.login_welcome', value ) } help={ __( 'Leave blank for the theme’s wording.', 'aureon' ) } /> { /* The callout is part of the side-by-side design only; the tabbed card leaves it out, so its fields would edit something that never shows. */ } { 'tabs' !== layout && ( <> setPath( 'woocommerce.account.login_perk_title', value ) } /> setPath( 'woocommerce.account.login_perk_text', value ) } /> ) } ) } setPath( 'woocommerce.account.login_benefits', value ) } /> { false !== account.login_benefits && benefits.map( ( item, index ) => (
setBenefit( index, { icon: value } ) } /> setBenefit( index, { title: value } ) } /> setBenefit( index, { text: value } ) } />
) ) }
setPath( 'woocommerce.account.login_remember', value ) } /> setPath( 'woocommerce.account.login_lost_link', value ) } /> ); }