-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ads): marketplace settings wizard (#2628)
Co-authored-by: dkoo <[email protected]> Co-authored-by: Derrick Koo <[email protected]>
- Loading branch information
1 parent
d97b8ed
commit b6a5b37
Showing
8 changed files
with
137 additions
and
16 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
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
104 changes: 104 additions & 0 deletions
104
assets/wizards/advertising/views/marketplace/settings/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,104 @@ | ||
/* globals newspack_ads_wizard */ | ||
/** | ||
* Ad Unit Management Screens. | ||
*/ | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { useEffect, useState } from '@wordpress/element'; | ||
import { TextControl, CheckboxControl, Spinner, Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Grid, Card, Notice } from '../../../../../components/src'; | ||
|
||
/** | ||
* Advertising Marketplace Products Screen. | ||
*/ | ||
export default function MarketplaceSettings( { wizardApiFetch } ) { | ||
const [ settings, setSettings ] = useState( {} ); | ||
const [ inFlight, setInFlight ] = useState( false ); | ||
const [ error, setError ] = useState( null ); | ||
useEffect( () => { | ||
setInFlight( true ); | ||
setError( null ); | ||
if ( ! wizardApiFetch ) return; | ||
wizardApiFetch( { | ||
path: `/newspack-ads/v1/marketplace/settings`, | ||
quiet: true, | ||
} ) | ||
.then( data => { | ||
setSettings( data ); | ||
} ) | ||
.catch( err => { | ||
setError( err ); | ||
} ) | ||
.finally( () => setInFlight( false ) ); | ||
}, [] ); | ||
const save = () => { | ||
setInFlight( true ); | ||
setError( null ); | ||
apiFetch( { | ||
path: `/newspack-ads/v1/marketplace/settings`, | ||
method: 'POST', | ||
data: settings, | ||
} ) | ||
.then( data => { | ||
setSettings( data ); | ||
} ) | ||
.catch( err => { | ||
setError( err ); | ||
} ) | ||
.finally( () => setInFlight( false ) ); | ||
}; | ||
if ( inFlight && ! Object.keys( settings ).length ) { | ||
return <Spinner />; | ||
} | ||
return ( | ||
<> | ||
<h2>{ __( 'Marketplace Settings', 'newspack' ) }</h2> | ||
<Grid columns={ 1 } gutter={ 32 }> | ||
{ error && <Notice isError noticeText={ error.message } /> } | ||
<CheckboxControl | ||
label={ __( 'Send email notification', 'newspack' ) } | ||
help={ __( | ||
'Whether to send an email notification on every new marketplace order placed.', | ||
'newspack' | ||
) } | ||
disabled={ inFlight } | ||
checked={ settings.enable_email_notification } | ||
onChange={ enable_email_notification => { | ||
setSettings( { ...settings, enable_email_notification } ); | ||
} } | ||
/> | ||
<p> | ||
{ __( | ||
'Make sure you also have email notifications enabled for new orders on WooCommerce settings:', | ||
'newspack' | ||
) }{ ' ' } | ||
<a href={ newspack_ads_wizard.wc_email_settings_url } target="_blank" rel="noreferrer"> | ||
{ __( 'WooCommerce > Settings > Emails', 'newspack' ) } | ||
</a> | ||
</p> | ||
<TextControl | ||
label={ __( 'Email address for notifications', 'newspack' ) } | ||
help={ __( 'Email address to send notifications to.', 'newspack' ) } | ||
disabled={ inFlight } | ||
value={ settings.notification_email_address } | ||
onChange={ notification_email_address => { | ||
setSettings( { ...settings, notification_email_address } ); | ||
} } | ||
/> | ||
</Grid> | ||
<Card buttonsCard noBorder className="justify-end"> | ||
<Button isPrimary onClick={ save } disabled={ inFlight }> | ||
{ __( 'Save Changes', 'newspack' ) } | ||
</Button> | ||
</Card> | ||
</> | ||
); | ||
} |
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