-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
69 lines (56 loc) · 1.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* External dependencies
*/
import { getHistory, getNewPath } from '@woocommerce/navigation';
/**
* Internal dependencies
*/
import AppSpinner from '.~/components/app-spinner';
import SavedSetupStepper from './saved-setup-stepper';
import useMCSetup from '.~/hooks/useMCSetup';
import useStoreAddress from '.~/hooks/useStoreAddress';
import useGoogleMCPhoneNumber from '.~/hooks/useGoogleMCPhoneNumber';
import stepNameKeyMap from './stepNameKeyMap';
const SetupStepper = () => {
const { hasFinishedResolution, data: mcSetup } = useMCSetup();
const { data: address, loaded: addressLoaded } = useStoreAddress();
const { data: phone, loaded: phoneLoaded } = useGoogleMCPhoneNumber();
const hasValidPhoneNumber =
phoneLoaded && phone?.isValid && phone?.isVerified;
const hasValidAddress =
addressLoaded &&
address?.isAddressFilled &&
! address?.isMCAddressDifferent;
const hasConfirmedStoreRequirements =
hasValidPhoneNumber && hasValidAddress;
const hasLoaded =
hasFinishedResolution && mcSetup && addressLoaded && phoneLoaded;
if ( hasFinishedResolution && ! mcSetup ) {
// this means error occurred, we just need to return null here,
// wp-data actions will display an error snackbar at the bottom of the page.
return null;
}
if ( ! hasLoaded ) {
return <AppSpinner />;
}
const { status } = mcSetup;
const { step } = mcSetup;
// If the user has already completed the store requirements, but is currently still on the
// store requirements step, we should skip the store requirements step and go to the paid ads step.
// else they will get stuck on a non-existent step #3
const currentStep =
step === 'store_requirements' && hasConfirmedStoreRequirements
? 'paid_ads'
: step;
if ( status === 'complete' ) {
getHistory().replace( getNewPath( {}, '/google/dashboard' ) );
return null;
}
return (
<SavedSetupStepper
savedStep={ stepNameKeyMap[ currentStep ] }
hasConfirmedStoreRequirements={ hasConfirmedStoreRequirements }
/>
);
};
export default SetupStepper;