Skip to content

Commit

Permalink
feat: update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Sep 19, 2024
1 parent db04b2f commit a70cf52
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ public static function get_media_kit_page_id() {
* Get Media Kit page.
*/
public function get_media_kit_page_edit_url() {
return get_edit_post_link( $this->get_media_kit_page_id(), '' );
$raw_url = get_edit_post_link( $this->get_media_kit_page_id(), '' );
$parsed_url = wp_parse_url( $raw_url );
return $parsed_url['path'] . '?' . $parsed_url['query'];
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/components/src/action-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ActionCard extends Component {
hasWhiteHeader,
isPending,
expandable = false,
isButtonEnabled = false
} = this.props;

const { expanded } = this.state;
Expand Down Expand Up @@ -173,7 +174,7 @@ class ActionCard extends Component {
</Handoff>
) : onClick || hasInternalLink ? (
<Button
disabled={ disabled }
disabled={ disabled && ! isButtonEnabled }
isLink
href={ href }
onClick={ onClick }
Expand Down
13 changes: 9 additions & 4 deletions src/wizards/advertising/components/add-ons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ const MediaKitToggle = () => {
newspack_ads_wizard.media_kit_page_status
);

const isPagePublished = pageStatus === 'publish';

const toggleMediaKit = () => {
setInFlight( true );
apiFetch( {
path: '/newspack/v1/wizard/billboard/media-kit',
method: pageStatus === 'publish' ? 'DELETE' : 'POST',
method: isPagePublished ? 'DELETE' : 'POST',
} )
.then( ( { edit_url, page_status } ) => {
setEditURL( edit_url );
Expand All @@ -41,12 +43,14 @@ const MediaKitToggle = () => {
const props = editURL
? {
href: editURL,
actionText: __( 'Edit Media Kit page', 'newspack-plugin' ),
actionText: isPagePublished
? __( 'Edit Media Kit page', 'newspack-plugin' )
: __( 'Review draft page', 'newspack-plugin' ),
}
: {};

let description = __(
'Media Kit page is not published. Click the link to edit and publish it.',
'Media kit page is created but unpublished, click the link to review and publish.',
'newspack-plugin'
);
let toggleEnabled = false;
Expand All @@ -70,10 +74,11 @@ const MediaKitToggle = () => {
return (
<ActionCard
disabled={ isInFlight || ! toggleEnabled }
isButtonEnabled={ true }
title={ __( 'Media Kit', 'newspack-plugin' ) }
description={ description }
toggle
toggleChecked={ Boolean( editURL ) }
toggleChecked={ Boolean( editURL ) && isPagePublished }
toggleOnChange={ toggleMediaKit }
{ ...props }
/>
Expand Down

0 comments on commit a70cf52

Please sign in to comment.