-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/mcm-integration
- Loading branch information
Showing
40 changed files
with
819 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
assets/source/setup-guide/app/components/SyncSettings/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { sprintf, __ } from '@wordpress/i18n'; | ||
import { Spinner } from '@woocommerce/components'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { useState } from '@wordpress/element'; | ||
import { | ||
Button, | ||
Flex, | ||
__experimentalText as Text, // eslint-disable-line @wordpress/no-unsafe-wp-apis --- _experimentalText unlikely to change/disappear and also used by WC Core | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
useSettingsSelect, | ||
useSyncSettingsDispatch, | ||
useCreateNotice, | ||
} from '../../helpers/effects'; | ||
import './style.scss'; | ||
|
||
/** | ||
* Sync settings button. | ||
*/ | ||
const SyncSettings = () => { | ||
const appSettings = useSettingsSelect(); | ||
const isSyncing = useSettingsSelect( 'isSettingsSyncing' ); | ||
const syncAppSettings = useSyncSettingsDispatch(); | ||
const createNotice = useCreateNotice(); | ||
const { removeNotice } = useDispatch( 'core/notices' ); | ||
const [ triggeredSyncSettings, setTriggeredSyncSettings ] = useState( | ||
false | ||
); | ||
|
||
const syncSettings = async () => { | ||
try { | ||
await syncAppSettings(); | ||
|
||
createNotice( | ||
'success', | ||
__( | ||
'Settings successfully synced with Pinterest Ads Manager.', | ||
'pinterest-for-woocommerce' | ||
), | ||
{ | ||
id: 'pinterest-for-woocommerce-settings-synced', | ||
} | ||
); | ||
} catch ( error ) { | ||
createNotice( | ||
'error', | ||
__( | ||
'Failed to sync settings with Pinterest Ads Manager.', | ||
'pinterest-for-woocommerce' | ||
), | ||
{ | ||
actions: [ | ||
{ | ||
label: 'Retry.', | ||
onClick: syncSettings, | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'pinterest-for-woocommerce-settings-synced', | ||
} | ||
); | ||
} | ||
}; | ||
|
||
if ( ! triggeredSyncSettings ) { | ||
syncSettings(); | ||
setTriggeredSyncSettings( true ); | ||
} | ||
|
||
removeNotice( 'pinterest-for-woocommerce-settings-synced' ); | ||
|
||
const lastSyncedTime = appSettings.last_synced_settings | ||
? appSettings.last_synced_settings | ||
: '-'; | ||
|
||
const syncInfo = sprintf( | ||
'%1$s: %2$s •', | ||
__( 'Settings last updated' ), | ||
lastSyncedTime | ||
); | ||
|
||
const syncButton = isSyncing ? ( | ||
<> | ||
{ __( 'Syncing settings', 'pinterest-for-woocommerce' ) } | ||
<Spinner /> | ||
</> | ||
) : ( | ||
<Button | ||
isLink | ||
target="_blank" | ||
onClick={ syncSettings } | ||
label={ __( | ||
'Sync to get latest settings from Pinterest Ads Manager', | ||
'pinterest-for-woocommerce' | ||
) } | ||
showTooltip={ true } | ||
tooltipPosition="top center" | ||
> | ||
{ __( 'Sync', 'pinterest-for-woocommerce' ) } | ||
</Button> | ||
); | ||
|
||
return ( | ||
<Flex justify="end" className="pinterest-for-woocommerce-sync-settings"> | ||
<Text className="pinterest-for-woocommerce-sync-settings__info"> | ||
{ syncInfo } | ||
{ syncButton } | ||
</Text> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default SyncSettings; |
9 changes: 9 additions & 0 deletions
9
assets/source/setup-guide/app/components/SyncSettings/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.pinterest-for-woocommerce-sync-settings { | ||
|
||
&__info { | ||
color: #757575; | ||
display: flex; | ||
gap: 0.2rem; | ||
align-items: baseline; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,8 @@ | |
margin-left: 32px; | ||
cursor: pointer; | ||
} | ||
|
||
.components-snackbar__action { | ||
margin-left: 0.2rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.