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

73 lines
2.1 KiB
JavaScript
Raw Normal View History

2024-05-28 23:32:10 +00:00
/**
* External dependencies
*/
2024-05-29 03:41:08 +00:00
import { getQuery } from '@woocommerce/navigation';
2024-05-30 02:28:29 +00:00
import { useEffect } 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-05 02:16:53 +00:00
import { useFullScreen } from '~/utils';
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-04 02:43:59 +00:00
const { section } = getQuery();
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-05-28 23:32:10 +00:00
if ( ! settingsData ) {
return <div>Error getting data</div>;
}
2024-05-30 04:32:57 +00:00
const sections = settingsData[ params.page ]?.sections;
2024-06-05 02:16:53 +00:00
const title = settingsData[ params.page ]?.label;
2024-05-30 04:32:57 +00:00
const contentData =
Array.isArray( sections ) && sections.length === 0
? {}
: sections[ section || '' ];
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">
<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">
<Content data={ contentData } />
</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;