Skip to content

Commit 9b7a126

Browse files
authored
Merge pull request #346 from boxuk/cm/header-fixes
Fixes for Header layout and notifications
2 parents 8493ae8 + 656804f commit 9b7a126

File tree

7 files changed

+86
-45
lines changed

7 files changed

+86
-45
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
WORDPRESS_VERSION=6.6 #Also update this var in the GitHub repo for the automations to use the correct WP Version
2-
NODE_VERSION=$(cat .nvmrc) # Ensure .nvmrc is updated as needed
2+
NODE_VERSION=22 # Ensure .nvmrc is updated as needed

package-lock.json

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/consent-management/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"author": "",
1919
"license": "ISC",
2020
"devDependencies": {
21+
"@types/wordpress__editor": "^14.3.1",
2122
"@wordpress/block-editor": "^13.0.7",
2223
"@wordpress/blocks": "^13.0.3",
2324
"@wordpress/components": "^28.0.3",

packages/consent-management/src/admin/Main.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22

33
/* WordPress Deps */
44
import { useState } from '@wordpress/element';
5-
import { EditorNotices, EditorSnackbars } from '@wordpress/editor';
65
import { InterfaceSkeleton } from '@wordpress/interface';
76
import { useViewportMatch } from '@wordpress/compose';
87
import { useSelect } from '@wordpress/data';
@@ -80,8 +79,8 @@ export const Main = () => {
8079
dataHasLoaded && <Sidebar setCurrentTab={ setCurrentTab } />
8180
}
8281
content={ Content }
83-
notices={ <EditorSnackbars /> }
84-
editorNotices={ <EditorNotices /> }
82+
notices={ <></> }
83+
editorNotices={ <></> }
8584
/>
8685
);
8786
};
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22

33
import { useDispatch } from '@wordpress/data';
4-
import { Flex, Button } from '@wordpress/components';
5-
import { drawerRight } from '@wordpress/icons';
4+
import { Flex, Button, Spinner } from '@wordpress/components';
5+
import { drawerRight, check } from '@wordpress/icons';
66
import { __ } from '@wordpress/i18n';
77

8+
import { ReactComponent as Icon } from './icons/icon.svg';
9+
810
import { store } from '../data';
911

1012
export const Header = ( {
@@ -16,35 +18,69 @@ export const Header = ( {
1618
setShowSidebar: ( show: boolean ) => void;
1719
hasFinishedResolution?: boolean;
1820
} ) => {
21+
const [ isSaving, setIsSaving ] = useState( false );
22+
const [ hasJustSaved, setHasJustSaved ] = useState( false );
23+
1924
const { save } = useDispatch( store );
2025

26+
const onSave = () => {
27+
setIsSaving( true );
28+
save().then( () => {
29+
setIsSaving( false );
30+
setHasJustSaved( true );
31+
setTimeout( () => setHasJustSaved( false ), 3000 );
32+
} );
33+
};
34+
35+
const buttonIcon = () => {
36+
if ( hasJustSaved ) {
37+
return check;
38+
}
39+
if ( isSaving ) {
40+
return <Spinner />;
41+
}
42+
return null;
43+
};
44+
const buttonText = () => {
45+
if ( hasJustSaved ) {
46+
return __( 'Saved', 'boxuk' );
47+
}
48+
if ( isSaving ) {
49+
return __( 'Saving', 'boxuk' );
50+
}
51+
return __( 'Save', 'boxuk' );
52+
};
53+
2154
return (
22-
<div className="editor-header edit-post-header">
23-
<Flex
24-
direction="row"
25-
justify="space-between"
26-
align="center"
27-
style={ { padding: '1em' } }
28-
>
29-
<h2>{ __( 'Cookie Consent', 'boxuk' ) }</h2>
55+
<div className="editor-header">
56+
<div>
57+
<Icon style={ { padding: '1em' } } />
58+
</div>
59+
<h2>{ __( 'Cookie Consent', 'boxuk' ) }</h2>
60+
<Flex justify="end">
3061
{ hasFinishedResolution && (
31-
<Flex direction="row" justify="flex-end" gap="1em">
32-
<Button
33-
onClick={ () => setShowSidebar( ! showSidebar ) }
34-
icon={ drawerRight }
35-
label={
36-
showSidebar
37-
? __( 'Hide Settings', 'boxuk' )
38-
: __( 'Show Settings', 'boxuk' )
39-
}
40-
className={ showSidebar ? 'is-pressed' : '' }
41-
/>
42-
<Button variant="primary" onClick={ save }>
43-
{ __( 'Save', 'boxuk' ) }
44-
</Button>
45-
</Flex>
62+
<Button
63+
variant="primary"
64+
icon={ buttonIcon() }
65+
onClick={ onSave }
66+
isBusy={ isSaving }
67+
>
68+
{ buttonText() }
69+
</Button>
4670
) }
4771
</Flex>
72+
<div>
73+
<Button
74+
onClick={ () => setShowSidebar( ! showSidebar ) }
75+
icon={ drawerRight }
76+
label={
77+
showSidebar
78+
? __( 'Hide Settings', 'boxuk' )
79+
: __( 'Show Settings', 'boxuk' )
80+
}
81+
className={ showSidebar ? 'is-pressed' : '' }
82+
/>
83+
</div>
4884
</div>
4985
);
5086
};
Loading

packages/consent-management/src/admin/data/actions.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* WordPress deps */
22
import { apiFetch } from '@wordpress/data-controls';
3-
import { resolveSelect, dispatch, select } from '@wordpress/data';
4-
import { store as noticesStore } from '@wordpress/notices';
3+
import { resolveSelect, select } from '@wordpress/data';
54

65
/* Internal deps */
76
import { store } from '.';
@@ -58,11 +57,6 @@ export function* save() {
5857
body: JSON.stringify( payload ),
5958
} );
6059

61-
dispatch( noticesStore ).createSuccessNotice( 'Settings saved.', {
62-
isDismissible: true,
63-
type: 'snackbar',
64-
} );
65-
6660
return {
6761
type: SAVE_SUCCESS,
6862
data: response[ SETTINGS_KEY ],
@@ -73,14 +67,6 @@ export function* save() {
7367
}
7468

7569
console.error( { payload, error } ); // eslint-disable-line no-console -- We want to log the error
76-
dispatch( noticesStore ).createErrorNotice(
77-
'Failed to save settings. ',
78-
{
79-
isDismissible: true,
80-
type: 'snackbar',
81-
explicitDismiss: true,
82-
}
83-
);
8470

8571
return {
8672
type: SAVE_FAILURE,

0 commit comments

Comments
 (0)