woocommerce/plugins/woocommerce-admin/client/settings/index.js

85 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-05-28 23:32:10 +00:00
/**
* External dependencies
*/
2024-06-06 02:44:29 +00:00
import { getQuery, getNewPath } from '@woocommerce/navigation';
import { Button } from '@wordpress/components';
import { Icon, chevronLeft } from '@wordpress/icons';
2024-06-10 02:02:35 +00:00
import { useEffect, createContext, useState } from '@wordpress/element';
2024-05-28 23:32:10 +00:00
/**
* Internal dependencies
*/
import { Tabs } from './tabs';
2024-05-29 01:38:10 +00:00
import { SectionNav } from './section-nav';
2024-05-29 03:41:08 +00:00
import { Content } from './content';
2024-05-30 02:28:29 +00:00
import { possiblyRenderSettingsSlots } from './settings-slots';
import { registerTaxSettingsConflictErrorFill } from './conflict-error-slotfill';
import { registerPaymentsSettingsBannerFill } from '../payments/payments-settings-banner-slotfill';
import { registerSiteVisibilitySlotFill } from '../launch-your-store';
2024-06-10 02:02:35 +00:00
import { registerExampleSettingsView } from './settings-view-example';
2024-06-05 02:16:53 +00:00
import { useFullScreen } from '~/utils';
2024-06-10 02:02:35 +00:00
import { SidebarContext } from './components/side-bar';
2024-05-29 00:17:39 +00:00
import './style.scss';
2024-05-28 23:32:10 +00:00
const Settings = ( { params } ) => {
2024-06-05 02:16:53 +00:00
useFullScreen( [ 'woocommerce-settings' ] );
2024-05-28 23:32:10 +00:00
const settingsData = window.wcSettings?.admin?.settingsPages;
2024-06-10 02:02:35 +00:00
const sections = settingsData[ params.page ]?.sections;
2024-06-04 02:43:59 +00:00
const { section } = getQuery();
2024-06-10 02:02:35 +00:00
const contentData =
Array.isArray( sections ) && sections.length === 0
? {}
: sections[ section || '' ];
const [ hasSideBar, setHasSideBar ] = useState( false );
2024-05-28 23:32:10 +00:00
2024-05-30 04:32:57 +00:00
// Be sure to render Settings slots when the params change.
2024-05-30 02:28:29 +00:00
useEffect( () => {
possiblyRenderSettingsSlots();
2024-06-04 02:43:59 +00:00
}, [ params.page, section ] );
2024-05-30 02:28:29 +00:00
2024-05-30 04:32:57 +00:00
// Register the slot fills for the settings page just once.
2024-05-30 02:28:29 +00:00
useEffect( () => {
registerTaxSettingsConflictErrorFill();
registerPaymentsSettingsBannerFill();
registerSiteVisibilitySlotFill();
2024-06-10 02:02:35 +00:00
registerExampleSettingsView();
2024-05-30 02:28:29 +00:00
}, [] );
2024-05-28 23:32:10 +00:00
if ( ! settingsData ) {
return <div>Error getting data</div>;
}
2024-06-05 02:16:53 +00:00
const title = settingsData[ params.page ]?.label;
2024-05-30 04:32:57 +00:00
2024-05-28 23:32:10 +00:00
return (
<>
2024-06-05 02:16:53 +00:00
<div className="woocommerce-settings-layout">
<div className="woocommerce-settings-layout-navigation">
2024-06-06 02:44:29 +00:00
<Button href={ getNewPath( {}, '/', {} ) }>
<Icon icon={ chevronLeft } />
Settings
</Button>
2024-06-05 02:16:53 +00:00
<Tabs data={ settingsData } page={ params.page } />
</div>
<div className="woocommerce-settings-layout-content">
<div className="woocommerce-settings-layout-title">
<h1>{ title }</h1>
2024-05-29 01:49:40 +00:00
</div>
2024-06-05 02:16:53 +00:00
<SectionNav
data={ settingsData[ params.page ] }
section={ section }
>
<div className="woocommerce-settings-layout-main">
2024-06-10 02:02:35 +00:00
<SidebarContext.Provider value={ setHasSideBar }>
<Content data={ contentData } />
</SidebarContext.Provider>
2024-06-05 02:16:53 +00:00
</div>
</SectionNav>
2024-05-29 01:38:10 +00:00
</div>
2024-06-05 02:16:53 +00:00
</div>
2024-05-28 23:32:10 +00:00
</>
);
};
2024-05-28 23:32:10 +00:00
export default Settings;