From c17f336acc29d6479ac97edd7da60a01fec7d120 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Thu, 2 Feb 2023 17:47:42 +0800 Subject: [PATCH] Code refactor for Campaigns card. --- .../Campaigns/Campaigns.scss | 42 ++-- .../Campaigns/Campaigns.tsx | 205 +++++++++--------- 2 files changed, 119 insertions(+), 128 deletions(-) diff --git a/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.scss b/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.scss index 7324369f139..190849bd5d7 100644 --- a/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.scss +++ b/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.scss @@ -1,39 +1,35 @@ .woocommerce-marketing-campaigns-card { - .woocommerce-marketing-campaigns-card-body { + &__content { width: 50%; margin: auto; text-align: center; + } - svg { - background-color: $studio-gray-0; - border-radius: 28px; - margin-bottom: $gap-smallest; - } + &__content-icon { + background-color: $studio-gray-0; + border-radius: 28px; + margin-bottom: $gap-smallest; &--error { - svg { - fill: $alert-red; - } + fill: $alert-red; } &--empty { - svg { - fill: $studio-woocommerce-purple-50; - } + fill: $studio-woocommerce-purple-50; } + } - &__title { - font-size: 13px; - font-weight: 600; - line-height: 16px; - color: $gray-900; - margin-bottom: $gap-smallest; - } + &__content-title { + font-size: 13px; + font-weight: 600; + line-height: 16px; + color: $gray-900; + margin-bottom: $gap-smallest; + } - &__description { - color: $gray-700; - margin-bottom: $gap-smallest; - } + &__content-description { + color: $gray-700; + margin-bottom: $gap-smallest; } .woocommerce-marketing-campaign-logo { diff --git a/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.tsx b/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.tsx index 5f7fe7405be..57dd3893ad9 100644 --- a/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.tsx +++ b/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.tsx @@ -26,76 +26,130 @@ export const Campaigns = () => { const [ page, setPage ] = useState( 1 ); const { loading, data } = useCampaigns(); - if ( loading ) { - return ( - - - - { __( 'Campaigns', 'woocommerce' ) } - - + const getContent = () => { + if ( loading ) { + return ( - - ); - } + ); + } - if ( ! data ) { - return ( - - - - { __( 'Campaigns', 'woocommerce' ) } - - - - -
+ if ( ! data ) { + return ( + + +
{ __( 'An unexpected error occurred.', 'woocommerce' ) }
-
+
{ __( 'Please try again later. Check the logs if the problem persists. ', 'woocommerce' ) }
- - ); - } + ); + } - if ( data.length === 0 ) { - return ( - - - - { __( 'Campaigns', 'woocommerce' ) } - - - - -
+ if ( data.length === 0 ) { + return ( + + +
{ __( 'Advertise with marketing campaigns', 'woocommerce' ) }
-
+
{ __( 'Easily create and manage marketing campaigns without leaving WooCommerce.', 'woocommerce' ) }
- - ); - } + ); + } - const perPage = 5; - const total = data.length; - const start = ( page - 1 ) * perPage; - const pagedData = data.slice( start, start + perPage ); + const perPage = 5; + const total = data.length; + const start = ( page - 1 ) * perPage; + const pagedData = data.slice( start, start + perPage ); + + return ( + <> + { + return [ + { + display: ( + + + { + + + + + + { el.title } + + + { el.description && ( + + { el.description } + + ) } + + + + ), + }, + { display: el.cost }, + ]; + } ) } + /> + { total > perPage && ( + + { + setPage( newPage ); + } } + /> + + ) } + + ); + }; return ( @@ -104,66 +158,7 @@ export const Campaigns = () => { { __( 'Campaigns', 'woocommerce' ) } -
{ - return [ - { - display: ( - - - { - - - - - - { el.title } - - - { el.description && ( - - { el.description } - - ) } - - - - ), - }, - { display: el.cost }, - ]; - } ) } - /> - { total > perPage && ( - - { - setPage( newPage ); - } } - /> - - ) } + { getContent() } ); };