Skip to content

Commit

Permalink
update UI as per figma
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Nov 20, 2024
1 parent cb8973c commit 0be9b0b
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 35 deletions.
25 changes: 14 additions & 11 deletions src/js/settings/components/classifai-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {
HashRouter,
useParams,
NavLink,
useNavigate,
} from 'react-router-dom';

/**
* WordPress dependencies
*/
import { useDispatch } from '@wordpress/data';
import { SlotFillProvider } from '@wordpress/components';
import { SlotFillProvider, Button, Icon } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { useEffect } from '@wordpress/element';
import apiFetch from '@wordpress/api-fetch';
Expand Down Expand Up @@ -62,13 +63,20 @@ const DefaultFeatureSettings = () => {
const FeatureSettingsWrapper = () => {
const { service, feature } = useParams();
const serviceFeatures = Object.keys( features[ service ] || {} );
const navigate = useNavigate();

if ( ! serviceFeatures.includes( feature ) ) {
return <Navigate to={ serviceFeatures[ 0 ] } replace />;
}

return (
<FeatureContext.Provider value={ { featureName: feature } }>
<Button
icon={ <Icon icon="arrow-left-alt2" /> }
onClick={ () => navigate( -1 ) }
>
{ __( 'Back to dashboard', 'classifai' ) }
</Button>
<FeatureSettings />
</FeatureContext.Provider>
);
Expand Down Expand Up @@ -199,16 +207,11 @@ export const ClassifAISettings = () => {
<Route
path=":service"
element={ <ServiceSettingsWrapper /> }
>
<Route
index
element={ <DefaultFeatureSettings /> }
/>
<Route
path=":feature"
element={ <FeatureSettingsWrapper /> }
/>
</Route>
/>
<Route
path=":service/:feature"
element={ <FeatureSettingsWrapper /> }
/>
<Route
path="classifai_setup"
element={ <ClassifAIOnboarding /> }
Expand Down
129 changes: 105 additions & 24 deletions src/js/settings/components/service-settings/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
/**
* External dependencies
*/
import { NavLink, Outlet, useParams } from 'react-router-dom';
import { NavLink, useParams } from 'react-router-dom';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import {
Flex,
FlexItem,
FlexBlock,
ToggleControl,
Button,
Panel,
PanelBody,
} from '@wordpress/components';
import { useEffect, useRef } from '@wordpress/element';
import apiFetch from '@wordpress/api-fetch';

/**
* Internal dependencies
Expand All @@ -22,34 +32,105 @@ const { features } = window.classifAISettings;
* @return {Object} The ServiceSettings component.
*/
export const ServiceSettings = () => {
const { setCurrentService } = useDispatch( STORE_NAME );
const {

Check failure on line 35 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

Replace `⏎↹↹setCurrentService,⏎↹↹setIsSaving,⏎↹↹setSettings⏎↹}·=·` with `·setCurrentService,·setIsSaving,·setSettings·}·=⏎↹↹`
setCurrentService,
setIsSaving,
setSettings
} = useDispatch( STORE_NAME );

const { service } = useParams();
const isInitialPageLoad = useRef( true );

const { settings, getFeatureSettings } = useSelect( ( select ) => {
const store = select( STORE_NAME );

return {
settings: store.getSettings(),
getFeatureSettings: ( key, featureName ) => store.getFeatureSettings( key, featureName ),

Check failure on line 49 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

Replace `·` with `⏎↹↹↹↹`
}

Check failure on line 50 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

Insert `;`
} );

useEffect( () => {
setCurrentService( service );
}, [ service, setCurrentService ] );

const serviceFeatures = features[ service ] || {};

const saveSettings = () => {
setIsSaving( true );
apiFetch( {
path: '/classifai/v1/settings/',
method: 'POST',
data: {
settings,
is_setup: true,
step: 'enable_features',
},
} ).then( ( res ) => {
if ( res.errors && res.errors.length ) {
res.errors.forEach( ( error ) => {
createErrorNotice( error.message, {

Check failure on line 72 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

'createErrorNotice' is not defined
id: `error-${ featureName }`,

Check failure on line 73 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

'featureName' is not defined
} );
} );
setSettings( res.settings );
setIsSaving( false );
return;
}

setSettings( res.settings );
setIsSaving( false );
} )

Check failure on line 83 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

Insert `;`
};

const statuses = Object.keys( settings ).map( ( key ) => settings[ key ].status ).join( '' );

Check failure on line 86 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

Replace `.map(·(·key·)·=>·settings[·key·].status·)` with `⏎↹↹.map(·(·key·)·=>·settings[·key·].status·)⏎↹↹`

useEffect( () => {
if ( isInitialPageLoad.current ) {
isInitialPageLoad.current = false;
return;
}
saveSettings()

Check failure on line 93 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

Insert `;`
}, [ statuses ] );

Check warning on line 94 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

React Hook useEffect has a missing dependency: 'saveSettings'. Either include it or remove the dependency array

return (
<div className="service-settings-wrapper">
<div className="classifai-tabs" aria-orientation="vertical">
{ Object.keys( serviceFeatures ).map( ( feature ) => (
<NavLink
to={ feature }
key={ feature }
className={ ( { isActive } ) =>
isActive
? 'active-tab classifai-tabs-item'
: 'classifai-tabs-item'
}
>
{ serviceFeatures[ feature ]?.label ||
__( 'Feature', 'classifai' ) }
</NavLink>
) ) }
</div>
<div className="feature-settings-wrapper">
<Outlet />
</div>
<div className="classifai-settings-dashboard">
{ Object.keys( serviceFeatures ).map( ( feature ) => (
<Panel>

Check failure on line 99 in src/js/settings/components/service-settings/index.js

View workflow job for this annotation

GitHub Actions / eslint

Missing "key" prop for element in iterator
<PanelBody>
<Flex gap={ 8 } align='top'>
<FlexItem style={ { marginTop: '4px' } }>
<Flex gap={ 2 }>
<ToggleControl
className="classifai-feature-status"
checked={ '1' === getFeatureSettings( 'status', feature ) }
onChange={ ( value ) => wp.data.dispatch( STORE_NAME ).setFeatureSettings( { status: value ? '1' : '0' }, feature ) }
/>
</Flex>
</FlexItem>
<FlexBlock>
<strong>{ serviceFeatures[ feature ]?.label }</strong>
<div dangerouslySetInnerHTML={ { __html: serviceFeatures[ feature ]?.enable_description } } />
</FlexBlock>
<FlexItem>
<NavLink
to={ feature }
key={ feature }
>
<Button
variant="secondary"
size="small"
disabled={ '0' === getFeatureSettings( 'status', feature ) }
>
{ __( 'Edit', 'classifai' ) }
</Button>
</NavLink>
</FlexItem>
</Flex>
<h1></h1>
</PanelBody>
</Panel>
) ) }
</div>
);
};
13 changes: 13 additions & 0 deletions src/scss/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,16 @@
margin: 0 auto;
top: 1rem;
}

.classifai-settings-dashboard {
margin-top: 36px;
max-width: 700px;
}

.classifai-feature-status {
margin-bottom: 0 !important;

.components-flex {
gap: 0 !important;
}
}

0 comments on commit 0be9b0b

Please sign in to comment.