-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rerender country and state if visited via deep link #28404
Changes from 11 commits
5c23584
1c64c43
230bc39
7cc4535
5729e74
6f1b1c0
fe4ca57
f1f96bc
48c1939
7c03147
811deb9
c318647
237a589
1caf195
a9b6ed1
a70225e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import lodashGet from 'lodash/get'; | ||
import _ from 'underscore'; | ||
import React, {useState, useCallback, useEffect} from 'react'; | ||
import React, {useState, useCallback, useEffect, useMemo} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {View} from 'react-native'; | ||
import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST'; | ||
|
@@ -70,14 +70,13 @@ function updateAddress(values) { | |
|
||
function AddressPage({privatePersonalDetails, route}) { | ||
usePrivatePersonalDetails(); | ||
const {translate} = useLocalize(); | ||
const { translate } = useLocalize(); | ||
const address = useMemo(() => lodashGet(privatePersonalDetails, 'address') || {}, [privatePersonalDetails]); | ||
const countryFromUrl = lodashGet(route, 'params.country'); | ||
const [currentCountry, setCurrentCountry] = useState(countryFromUrl || PersonalDetails.getCountryISO(lodashGet(privatePersonalDetails, 'address.country'))); | ||
const isUSAForm = currentCountry === CONST.COUNTRY.US; | ||
const [currentCountry, setCurrentCountry] = useState(address.country); | ||
const zipSampleFormat = lodashGet(CONST.COUNTRY_ZIP_REGEX_DATA, [currentCountry, 'samples'], ''); | ||
const zipFormat = translate('common.zipCodeExampleFormat', {zipSampleFormat}); | ||
|
||
const address = lodashGet(privatePersonalDetails, 'address') || {}; | ||
const isUSAForm = currentCountry === CONST.COUNTRY.US; | ||
const isLoadingPersonalDetails = lodashGet(privatePersonalDetails, 'isLoading', true); | ||
const [street1, street2] = (address.street || '').split('\n'); | ||
const [state, setState] = useState(address.state); | ||
|
@@ -87,6 +86,11 @@ function AddressPage({privatePersonalDetails, route}) { | |
* @param {Object} values - form input values | ||
* @returns {Object} - An object containing the errors for each inputID | ||
*/ | ||
useEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the wrong place to put It should be placed after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if(!address) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
setState(address.state); | ||
setCurrentCountry(address.country); | ||
}, [address]); | ||
saranshbalyan-1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const validate = useCallback((values) => { | ||
const errors = {}; | ||
const requiredFields = ['addressLine1', 'city', 'country', 'state']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some linter errors still
![image](https://private-user-images.githubusercontent.com/9059945/271560063-7a7a148f-a34f-4e6b-a0b8-4f3a4e4e0d7f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1ODM3NjYsIm5iZiI6MTczOTU4MzQ2NiwicGF0aCI6Ii85MDU5OTQ1LzI3MTU2MDA2My03YTdhMTQ4Zi1hMzRmLTRlNmItYTBiOC00ZjNhNGU0ZTBkN2YucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMDEzNzQ2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODg3MGRkYzFiZDFkNjc2NmUwZjBmZDdjODc0ODIxMWQ2NzUyYzNkZTE1MTFlMzcxZDA2YTNlYzJjMWEyNjNjMCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.1894UAfYiEcCeDdT7F-CGzHO7FyZlIzBuT-yK24vqRs)
You can check those by running
npm run lint
(ignore the errors in /vendor/bundle/ruby)