-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
78 lines (72 loc) · 2.17 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
77
78
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { getHistory } from '@woocommerce/navigation';
import { useState } from '@wordpress/element';
import { Flex } from '@wordpress/components';
/**
* Internal dependencies
*/
import { getSettingsUrl } from '.~/utils/urls';
import { useAppDispatch } from '.~/data';
import useStoreAddress from '.~/hooks/useStoreAddress';
import FullContainer from '.~/components/full-container';
import TopBar from '.~/components/stepper/top-bar';
import HelpIconButton from '.~/components/help-icon-button';
import Section from '.~/wcdl/section';
import AppButton from '.~/components/app-button';
import ContactInformation from '.~/components/contact-information';
export default function EditContactInformation() {
const { updateGoogleMCContactInformation } = useAppDispatch();
const { data: address } = useStoreAddress();
const [ isSaving, setSaving ] = useState( false );
const [ phoneNumber, setPhoneNumber ] = useState( {
isValid: false,
isDirty: false,
} );
const handleSaveClick = () => {
const { isDirty, countryCallingCode, nationalNumber } = phoneNumber;
const args = isDirty ? [ countryCallingCode, nationalNumber ] : [];
setSaving( true );
updateGoogleMCContactInformation( ...args )
.then( () => getHistory().push( getSettingsUrl() ) )
.catch( () => setSaving( false ) );
};
const isReadyToSave =
phoneNumber.isValid &&
address.isAddressFilled &&
( phoneNumber.isDirty || address.isMCAddressDifferent );
return (
<FullContainer>
<TopBar
title={ __(
'Add contact information',
'google-listings-and-ads'
) }
helpButton={
<HelpIconButton eventContext="edit-contact-information" />
}
backHref={ getSettingsUrl() }
/>
<div className="gla-settings">
<ContactInformation
view="settings"
onPhoneNumberChange={ setPhoneNumber }
/>
<Section>
<Flex justify="flex-end">
<AppButton
isPrimary
loading={ isSaving }
disabled={ ! isReadyToSave }
onClick={ handleSaveClick }
>
{ __( 'Save details', 'google-listings-and-ads' ) }
</AppButton>
</Flex>
</Section>
</div>
</FullContainer>
);
}