Skip to content

Commit

Permalink
Refactor getPrimaryAction
Browse files Browse the repository at this point in the history
  • Loading branch information
IanRamosC committed Dec 31, 2024
1 parent 318dacd commit 372f29c
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ type Actions = {
onManage: () => void;
};

const getFeaturePrimaryAction = (
detail: ProductCamelCase,
{ onActivate, onInstall, onManage }: Omit< Actions, 'onCheckout' >
) => {
switch ( detail.status ) {
case PRODUCT_STATUSES.MODULE_DISABLED:
return { label: __( 'Activate', 'jetpack-my-jetpack' ), onClick: onActivate };
case PRODUCT_STATUSES.ABSENT:
return { label: __( 'Install', 'jetpack-my-jetpack' ), onClick: onInstall };
case PRODUCT_STATUSES.USER_CONNECTION_ERROR:
return { label: __( 'Connect', 'jetpack-my-jetpack' ), href: '#/connection' };
default:
return {
label: __( 'Manage', 'jetpack-my-jetpack' ),
href: detail.manageUrl,
onClick: onManage,
};
}
};

const getPrimaryAction = (
detail: ProductCamelCase,
{ onCheckout, onActivate, onInstall, onManage }: Actions
Expand All @@ -79,21 +99,7 @@ const getPrimaryAction = (
}

if ( detail.isFeature ) {
if ( detail.status === PRODUCT_STATUSES.MODULE_DISABLED ) {
return { label: __( 'Activate', 'jetpack-my-jetpack' ), onClick: onActivate };
}
if ( detail.status === PRODUCT_STATUSES.ABSENT ) {
return { label: __( 'Install', 'jetpack-my-jetpack' ), onClick: onInstall };
}
if ( detail.status === PRODUCT_STATUSES.USER_CONNECTION_ERROR ) {
return { label: __( 'Connect', 'jetpack-my-jetpack' ), href: '#/connection' };
}

return {
label: __( 'Manage', 'jetpack-my-jetpack' ),
href: detail.manageUrl,
onClick: onManage,
};
return getFeaturePrimaryAction( detail, { onActivate, onInstall, onManage } );
}

return { label: __( 'Purchase', 'jetpack-my-jetpack' ), onClick: onCheckout };
Expand Down

0 comments on commit 372f29c

Please sign in to comment.