-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
76 lines (67 loc) · 2.37 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
70
71
72
73
74
75
76
/**
* External dependencies
*/
import { useEffect } from '@wordpress/element';
import { getQuery, getHistory } from '@woocommerce/navigation';
/**
* Internal dependencies
*/
import { API_RESPONSE_CODES } from '.~/constants';
import useMenuEffect from '.~/hooks/useMenuEffect';
import useGoogleAccount from '.~/hooks/useGoogleAccount';
import useUpdateRestAPIAuthorizeStatusByUrlQuery from '.~/hooks/useUpdateRestAPIAuthorizeStatusByUrlQuery';
import { subpaths, getReconnectAccountUrl } from '.~/utils/urls';
import { ContactInformationPreview } from '.~/components/contact-information';
import LinkedAccounts from './linked-accounts';
import ReconnectWPComAccount from './reconnect-wpcom-account';
import ReconnectGoogleAccount from './reconnect-google-account';
import EditStoreAddress from './edit-store-address';
import EditPhoneNumber from './edit-phone-number';
import EnableNewProductSyncNotice from '.~/components/enable-new-product-sync-notice';
import MainTabNav from '.~/components/main-tab-nav';
import RebrandingTour from '.~/components/tours/rebranding-tour';
import './index.scss';
const pageClassName = 'gla-settings';
const Settings = () => {
const { subpath } = getQuery();
// Make the component highlight GLA entry in the WC legacy menu.
useMenuEffect();
useUpdateRestAPIAuthorizeStatusByUrlQuery();
const { google } = useGoogleAccount();
const isReconnectGooglePage = subpath === subpaths.reconnectGoogleAccount;
// This page wouldn't get any 401 response when losing Google account access,
// so we still need to detect it here.
useEffect( () => {
if ( ! isReconnectGooglePage && google?.active === 'no' ) {
getHistory().replace(
getReconnectAccountUrl( API_RESPONSE_CODES.GOOGLE_DISCONNECTED )
);
}
}, [ isReconnectGooglePage, google ] );
// Navigate to subpath if any.
switch ( subpath ) {
case subpaths.reconnectWPComAccount:
return (
<div className={ pageClassName }>
<ReconnectWPComAccount />
</div>
);
case subpaths.reconnectGoogleAccount:
return <ReconnectGoogleAccount />;
case subpaths.editPhoneNumber:
return <EditPhoneNumber />;
case subpaths.editStoreAddress:
return <EditStoreAddress />;
default:
}
return (
<div className={ pageClassName }>
<EnableNewProductSyncNotice />
<MainTabNav />
<RebrandingTour />
<ContactInformationPreview />
<LinkedAccounts />
</div>
);
};
export default Settings;