-
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
[VIP-Travel] Workspace address page and section in workspace profile #38381
Merged
twisterdotcom
merged 22 commits into
Expensify:main
from
software-mansion-labs:travel/workspace-profile-address
May 1, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
42b22e0
Initial config to workspace address page
smelaa c001a15
Create workspace address page and section in workspace profile
smelaa 572411c
Merge branch 'main' into travel/workspace-profile-address
smelaa 5478015
Merge branch 'main' into travel/workspace-profile-address
smelaa c2dd7fb
Merge branch 'main' into travel/workspace-profile-address
smelaa 90bdc7e
Change workspace address page route & add beta visibility
smelaa 49797a7
Merge branch 'main' into travel/workspace-profile-address
smelaa 28c66fc
Fix workspace address page routing
smelaa 4fdbaba
Fix diff in routes to address page and checking beta
WojtekBoman 99eb0c7
Merge branch 'main' into travel/workspace-profile-address
smelaa e4ecae4
Merge branch 'main' into travel/workspace-profile-address
smelaa 352478c
Go back after submitting address form
smelaa 9218e43
Merge branch 'main' into travel/workspace-profile-address
smelaa 7d25e4d
Change translations
smelaa fb5c648
Merge branch 'main' into travel/workspace-profile-address
smelaa 2bbf2d5
First tries to call API
smelaa 63eefbc
Comunicate frontend with backend
smelaa d9ed6fc
Street address line fix
smelaa b8975cb
Merge branch 'main' into travel/workspace-profile-address
smelaa 8d2fd83
Fix typecheck errors
smelaa 40b9a28
Merge branch 'main' into travel/workspace-profile-address
smelaa f7da8c4
Fix small bugs & address review comments
smelaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// TODO: Change API endpoint parameters format to make it possible to follow naming-convention | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
type UpdatePolicyAddressParams = { | ||
policyID: string; | ||
'data[addressStreet]': string; | ||
'data[city]': string; | ||
'data[country]': string; | ||
'data[state]': string; | ||
'data[zipCode]': string; | ||
}; | ||
|
||
export default UpdatePolicyAddressParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import type {StackScreenProps} from '@react-navigation/stack'; | ||
import React, {useCallback, useEffect, useMemo, useState} from 'react'; | ||
import AddressForm from '@components/AddressForm'; | ||
import type {FormOnyxValues} from '@components/Form/types'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; | ||
import {updateAddress} from '@userActions/Policy'; | ||
import type {Country} from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type {CompanyAddress} from '@src/types/onyx/Policy'; | ||
import type {WithPolicyProps} from './withPolicy'; | ||
import withPolicy from './withPolicy'; | ||
|
||
type WorkspaceProfileAddressPagePolicyProps = WithPolicyProps; | ||
|
||
type WorkspaceProfileAddressPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.ADDRESS> & WorkspaceProfileAddressPagePolicyProps; | ||
|
||
function WorkspaceProfileAddressPage({policy}: WorkspaceProfileAddressPageProps) { | ||
const {translate} = useLocalize(); | ||
const address = useMemo(() => policy?.address, [policy]); | ||
const [currentCountry, setCurrentCountry] = useState(address?.country); | ||
const [[street1, street2], setStreets] = useState((address?.addressStreet ?? '').split('\n')); | ||
const [state, setState] = useState(address?.state); | ||
const [city, setCity] = useState(address?.city); | ||
const [zipcode, setZipcode] = useState(address?.zipCode); | ||
|
||
smelaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const updatePolicyAddress = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>) => { | ||
if (!policy) { | ||
return; | ||
} | ||
updateAddress(policy?.id, { | ||
addressStreet: `${values.addressLine1?.trim() ?? ''}\n${values.addressLine2?.trim() ?? ''}`, | ||
city: values.city.trim(), | ||
state: values.state.trim(), | ||
zipCode: values?.zipPostCode?.trim().toUpperCase() ?? '', | ||
country: values.country, | ||
}); | ||
Navigation.goBack(); | ||
}; | ||
|
||
const handleAddressChange = useCallback((value: unknown, key: unknown) => { | ||
const countryValue = value as Country | ''; | ||
const addressKey = key as keyof CompanyAddress; | ||
|
||
if (addressKey !== 'country' && addressKey !== 'state' && addressKey !== 'city' && addressKey !== 'zipCode') { | ||
return; | ||
} | ||
if (addressKey === 'country') { | ||
setCurrentCountry(countryValue); | ||
setState(''); | ||
setCity(''); | ||
setZipcode(''); | ||
return; | ||
} | ||
if (addressKey === 'state') { | ||
setState(countryValue); | ||
setCity(''); | ||
setZipcode(''); | ||
return; | ||
} | ||
if (addressKey === 'city') { | ||
setCity(countryValue); | ||
setZipcode(''); | ||
return; | ||
} | ||
setZipcode(countryValue); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!address) { | ||
return; | ||
} | ||
setStreets((address?.addressStreet ?? '').split('\n')); | ||
setState(address.state); | ||
setCurrentCountry(address.country); | ||
setCity(address.city); | ||
setZipcode(address.zipCode); | ||
}, [address]); | ||
|
||
return ( | ||
<ScreenWrapper | ||
includeSafeAreaPaddingBottom={false} | ||
testID={WorkspaceProfileAddressPage.displayName} | ||
> | ||
<HeaderWithBackButton | ||
title={translate('common.companyAddress')} | ||
shouldShowBackButton | ||
onBackButtonPress={() => Navigation.goBack()} | ||
/> | ||
<AddressForm | ||
formID={ONYXKEYS.FORMS.HOME_ADDRESS_FORM} | ||
onSubmit={updatePolicyAddress} | ||
submitButtonText={translate('common.save')} | ||
city={city} | ||
country={currentCountry} | ||
onAddressChanged={handleAddressChange} | ||
state={state} | ||
street1={street1} | ||
street2={street2} | ||
zip={zipcode} | ||
Comment on lines
+98
to
+104
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. afterwards, you can pass form data as a whole, or include it inside of AddressForm 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. Same as here. |
||
/> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
WorkspaceProfileAddressPage.displayName = 'WorkspaceProfileAddressPage'; | ||
|
||
export default withPolicy(WorkspaceProfileAddressPage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Has an issue been created for it?
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.
cc @danieldoglas
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.
@deetergp is working on it here: https://github.com/Expensify/Web-Expensify/pull/41840