woocommerce/plugins/woocommerce-admin/client/core-profiler/pages/Loader.tsx

75 lines
1.9 KiB
TypeScript
Raw Normal View History

Add Business Location page to the core profiler (#38019) * Add core profiler - welcome to woo page * Update checkbox styles * Add tracks * Update default tracking value * Update copies * using invoked promise instead of useState - take advantage of xstate's built ins for side effects instead of useEffect/hooks - discovered that error result wasn't really handled in original useEffect - use text labels instead of inline functions so that we can decouple the implementation from the machine model - todo: can move the invoked function out elsewhere and also tests if needed (not necessary here because it's a simple call) * add: core profiler scaffolding using xstate * Add navigation and progress-bar components * fix css lint error * Update plugins/woocommerce-admin/client/core-profiler/components/navigation/woologo.tsx Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com> * Update plugins/woocommerce-admin/client/core-profiler/components/progress-bar/progress-bar.tsx Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com> * Update plugins/woocommerce-admin/client/core-profiler/components/navigation/navigation.tsx Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com> * Remove var from __ function * Use woocommerce prefix for classnames * Fix css lint error * Fix broken tests * Add business location page * Remove unwanted changes from rebase * Remove unwanted changes from rebase * Redirect to Woo Home on exit * Add tracks * Fix js lint error * Add loader page * Support meta value from nested states * Use navigateTo * Add tests for getCountryStateOptions * Use Country type from navigation package * Rename useStages to getLoaderStageMeta * Add changelog * Move progress from 20 to 80 * Fix xstate warning * Fix broken pnpm lock * Fix eslint errors * Update plugins/woocommerce-admin/client/core-profiler/services/country.ts Co-authored-by: RJ <27843274+rjchow@users.noreply.github.com> * Update plugins/woocommerce-admin/client/core-profiler/index.tsx Co-authored-by: RJ <27843274+rjchow@users.noreply.github.com> * Save country to option * Fix jslint error * Update plugins/woocommerce-admin/client/core-profiler/services/country.ts Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com> * Update plugins/woocommerce-admin/client/core-profiler/style.scss Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com> * Fix eslint error * Use decodeEntities directly * Update comment for artificial 3 seconds wait * Disable Go to my store button when country is empty * Style for mobile devices * Style updates for the country dropdown * Fix js lint error * Update country dropdown border color * Style the loader * Fix css lint --------- Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com> Co-authored-by: rjchow <me@rjchow.com> Co-authored-by: RJ <27843274+rjchow@users.noreply.github.com>
2023-05-14 20:56:47 +00:00
/**
* External dependencies
*/
import classNames from 'classnames';
import { useState, useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import { CoreProfilerStateMachineContext } from '..';
import ProgressBar from '../components/progress-bar/progress-bar';
import { getLoaderStageMeta } from '../get-loader-stage-meta';
export type Stage = {
title: string;
image?: string | JSX.Element;
paragraphs: Array< {
label: string;
text: string;
duration?: number;
} >;
};
export type Stages = Array< Stage >;
export const Loader = ( {
context,
}: {
context: CoreProfilerStateMachineContext;
} ) => {
const stages = getLoaderStageMeta( context.loader.useStages ?? 'default' );
const currentStage = stages[ context.loader.stageIndex ?? 0 ];
const [ currentParagraph, setCurrentParagraph ] = useState( 0 );
useEffect( () => {
const interval = setInterval( () => {
setCurrentParagraph( ( _currentParagraph ) =>
currentStage.paragraphs[ _currentParagraph + 1 ]
? _currentParagraph + 1
: 0
);
}, currentStage.paragraphs[ currentParagraph ]?.duration ?? 3000 );
return () => clearInterval( interval );
}, [ currentParagraph, currentStage.paragraphs ] );
return (
<div
className={ classNames(
'woocommerce-profiler-loader',
context.loader.className
) }
>
<div className="woocommerce-profiler-loader-wrapper">
{ currentStage.image && currentStage.image }
<h1 className="woocommerce-profiler-loader__title">
{ currentStage.title }
</h1>
<ProgressBar
className={ 'progress-bar' }
percent={ context.loader.progress ?? 0 }
color={ 'var(--wp-admin-theme-color)' }
bgcolor={ '#E0E0E0' }
/>
<p className="woocommerce-profiler-loader__paragraph">
<b>
{ currentStage.paragraphs[ currentParagraph ]?.label }{ ' ' }
</b>
{ currentStage.paragraphs[ currentParagraph ]?.text }
</p>
</div>
</div>
);
};