Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions assets/src/admin/onboarding/index.tsx

This file was deleted.

150 changes: 0 additions & 150 deletions assets/src/admin/onboarding/page.tsx

This file was deleted.

3 changes: 3 additions & 0 deletions assets/src/admin/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Notice, Snackbar } from '@wordpress/components';

Check warning on line 10 in assets/src/admin/settings/page.tsx

View workflow job for this annotation

GitHub Actions / CSS/JS Lint / JS Lint & TypeScript

Use `Notice` from `@wordpress/ui` instead
import apiFetch from '@wordpress/api-fetch';

/**
Expand All @@ -16,6 +16,7 @@
import SiteTable from '@/components/SiteTable';
import SiteModal from '@/components/SiteModal';
import SiteSettings from '@/components/SiteSettings';
import SiteTypeSettings from '@/components/SiteTypeSettings';
import { REST_NAMESPACE, SHARED_SITES, SITE_TYPE } from '@/js/constants';
import { getErrorMessage } from '@/js/utils';

Expand Down Expand Up @@ -221,6 +222,8 @@
</Notice>
) ) }

{ ! SITE_TYPE && <SiteTypeSettings /> }

{ SITE_TYPE === 'brand-site' && <SiteSettings /> }

{ SITE_TYPE === 'governing-site' && (
Expand Down
136 changes: 136 additions & 0 deletions assets/src/components/SiteTypeSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* External dependencies
*/
import { useState } from 'react';

/**
* WordPress dependencies
*/
import apiFetch from '@wordpress/api-fetch';
import { __ } from '@wordpress/i18n';
import {
Card,
CardHeader,
CardBody,
Notice,
Button,
SelectControl,
} from '@wordpress/components';

/**
* Internal dependencies
*/
import type { SiteType } from '@/types/global';

const BRAND_SITE = 'brand-site' as const;
const GOVERNING_SITE = 'governing-site' as const;

const SiteTypeSelector = ( {
value,
setSiteType,
}: {
value: SiteType;
setSiteType: ( v: SiteType ) => void;
} ) => (
<SelectControl
label={ __( 'Site Type', 'onelogs' ) }
value={ value }
help={ __(
"Choose your site's primary purpose. This setting cannot be changed later and affects available features and configurations.",
'onelogs'
) }
onChange={ ( v: SiteType ) => {
setSiteType( v );
} }
__nextHasNoMarginBottom
__next40pxDefaultSize
options={ [
{ label: __( 'Select…', 'onelogs' ), value: '' },
{ label: __( 'Brand Site', 'onelogs' ), value: BRAND_SITE },
{
label: __( 'Governing site', 'onelogs' ),
value: GOVERNING_SITE,
},
] }
/>
);

const SiteTypeSettings = () => {
const [ siteType, setSiteType ] = useState< SiteType >( '' );
const [ error, setError ] = useState( '' );
const [ isSaving, setIsSaving ] = useState( false );

const handleSiteTypeChange = async ( value: SiteType ) => {
setIsSaving( true );

try {
const settings = await apiFetch< {
onelogs_site_type?: SiteType;
} >( {
path: '/wp/v2/settings',
method: 'POST',
data: { onelogs_site_type: value },
} );

if ( ! settings?.onelogs_site_type ) {
throw new Error( 'No site type in response' );
}

// Reload so the settings screen and menu match the new site type.
window.location.reload();
} catch {
setError( __( 'Error setting site type.', 'onelogs' ) );
} finally {
setIsSaving( false );
}
};

return (
<Card>
{ !! error && (
<Notice
status="error"
isDismissible
onRemove={ () => setError( '' ) }
>
{ error }
</Notice>
) }

<CardHeader>
<h2>{ __( 'OneLogs', 'onelogs' ) }</h2>
</CardHeader>

<CardBody>
<SiteTypeSelector
value={ siteType }
setSiteType={ setSiteType }
/>
<p>
<strong>{ __( 'Governing site', 'onelogs' ) }</strong>:{ ' ' }
{ __(
'connects the brand sites and shows their activity logs.',
'onelogs'
) }
<br />
<strong>{ __( 'Brand site', 'onelogs' ) }</strong>:{ ' ' }
{ __(
'connects to a governing site, which can view its activity logs.',
'onelogs'
) }
</p>
<Button
variant="primary"
onClick={ () => handleSiteTypeChange( siteType ) }
disabled={ isSaving || ! siteType }
isBusy={ isSaving }
style={ { marginTop: '1.5rem' } }
>
{ __( 'Select Current Site Type', 'onelogs' ) }
</Button>
</CardBody>
</Card>
);
};

export default SiteTypeSettings;
23 changes: 0 additions & 23 deletions assets/src/css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,6 @@

}

[id="onelogs-site-selection-modal"] {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 10000;
min-width: 40vw;
}

body.onelogs-site-selection-modal {

&::before {
content: "";
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
}
}

[id="toplevel_page_onelogs"] {

.dashicons-admin-generic::before {
Expand Down
40 changes: 0 additions & 40 deletions assets/src/css/onboarding.scss

This file was deleted.

Loading
Loading