2022-12-09 17:37:21 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-12-13 13:36:09 +00:00
|
|
|
import { Button } from '@wordpress/components';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import GridiconCheckmarkCircle from 'gridicons/dist/checkmark-circle';
|
|
|
|
import GridiconSync from 'gridicons/dist/sync';
|
|
|
|
import GridiconNotice from 'gridicons/dist/notice';
|
|
|
|
import classnames from 'classnames';
|
2022-12-09 17:37:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-12-13 13:36:09 +00:00
|
|
|
import { PluginCardBody } from '~/marketing/components';
|
|
|
|
import { InstalledChannel, SyncStatusType } from '~/marketing/types';
|
2022-12-09 17:37:21 +00:00
|
|
|
import './InstalledChannelCardBody.scss';
|
|
|
|
|
|
|
|
type InstalledChannelCardBodyProps = {
|
|
|
|
installedChannel: InstalledChannel;
|
|
|
|
};
|
|
|
|
|
2022-12-13 13:36:09 +00:00
|
|
|
type SyncStatusPropsType = {
|
|
|
|
status: SyncStatusType;
|
|
|
|
};
|
|
|
|
|
|
|
|
const iconSize = 18;
|
|
|
|
const className = 'woocommerce-marketing-sync-status';
|
|
|
|
|
|
|
|
const SyncStatus: React.FC< SyncStatusPropsType > = ( { status } ) => {
|
|
|
|
if ( status === 'failed' ) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={ classnames( className, `${ className }__failed` ) }
|
|
|
|
>
|
|
|
|
<GridiconNotice size={ iconSize } />
|
|
|
|
{ __( 'Sync failed', 'woocommerce' ) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( status === 'syncing' ) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={ classnames( className, `${ className }__syncing` ) }
|
|
|
|
>
|
|
|
|
<GridiconSync size={ iconSize } />
|
|
|
|
{ __( 'Syncing', 'woocommerce' ) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={ classnames( className, `${ className }__synced` ) }>
|
|
|
|
<GridiconCheckmarkCircle size={ iconSize } />
|
|
|
|
{ __( 'Synced', 'woocommerce' ) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-12-13 14:47:16 +00:00
|
|
|
type IssueStatusPropsType = {
|
|
|
|
installedChannel: InstalledChannel;
|
|
|
|
};
|
|
|
|
|
|
|
|
const issueStatusClassName = 'woocommerce-marketing-issue-status';
|
|
|
|
|
|
|
|
const IssueStatus: React.FC< IssueStatusPropsType > = ( {
|
|
|
|
installedChannel,
|
|
|
|
} ) => {
|
|
|
|
if ( installedChannel.issueType === 'error' ) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={ classnames(
|
|
|
|
issueStatusClassName,
|
|
|
|
`${ issueStatusClassName }__error`
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<GridiconNotice size={ iconSize } />
|
|
|
|
{ installedChannel.issueText }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( installedChannel.issueType === 'warning' ) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={ classnames(
|
|
|
|
issueStatusClassName,
|
|
|
|
`${ issueStatusClassName }__warning`
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<GridiconNotice size={ iconSize } />
|
|
|
|
{ installedChannel.issueText }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={ issueStatusClassName }>
|
|
|
|
{ installedChannel.issueText }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-12-09 17:37:21 +00:00
|
|
|
export const InstalledChannelCardBody: React.FC<
|
|
|
|
InstalledChannelCardBodyProps
|
|
|
|
> = ( { installedChannel } ) => {
|
2022-12-13 15:23:13 +00:00
|
|
|
/**
|
|
|
|
* The description section in the channel card.
|
|
|
|
*
|
|
|
|
* If setup is not completed, this would be the channel description.
|
|
|
|
*
|
|
|
|
* If setup is completed, this would be an element with sync status and issue status.
|
|
|
|
*/
|
|
|
|
const description = ! installedChannel.isSetupCompleted ? (
|
|
|
|
installedChannel.description
|
|
|
|
) : (
|
|
|
|
<div className="woocommerce-marketing-installed-channel-description">
|
2023-01-18 17:32:38 +00:00
|
|
|
{ installedChannel.syncStatus && (
|
|
|
|
<>
|
|
|
|
<SyncStatus status={ installedChannel.syncStatus } />
|
|
|
|
<div className="woocommerce-marketing-installed-channel-description__separator" />
|
|
|
|
</>
|
|
|
|
) }
|
2022-12-13 15:23:13 +00:00
|
|
|
<IssueStatus installedChannel={ installedChannel } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The action button in the channel card.
|
|
|
|
*
|
|
|
|
* If setup is not completed, this would be a "Finish setup" primary button.
|
|
|
|
*
|
|
|
|
* If setup is completed, this would be a "Manage" secondary button.
|
|
|
|
*/
|
|
|
|
const button = ! installedChannel.isSetupCompleted ? (
|
|
|
|
<Button variant="primary" href={ installedChannel.setupUrl }>
|
|
|
|
{ __( 'Finish setup', 'woocommerce' ) }
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<Button variant="secondary" href={ installedChannel.manageUrl }>
|
|
|
|
{ __( 'Manage', 'woocommerce' ) }
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
|
2022-12-09 17:37:21 +00:00
|
|
|
return (
|
2022-12-13 13:36:09 +00:00
|
|
|
<PluginCardBody
|
|
|
|
className="woocommerce-marketing-installed-channel-card-body"
|
|
|
|
icon={
|
|
|
|
<img
|
|
|
|
src={ installedChannel.icon }
|
|
|
|
alt={ installedChannel.title }
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
name={ installedChannel.title }
|
2022-12-13 15:23:13 +00:00
|
|
|
description={ description }
|
|
|
|
button={ button }
|
2022-12-13 13:36:09 +00:00
|
|
|
/>
|
2022-12-09 17:37:21 +00:00
|
|
|
);
|
|
|
|
};
|