Skip to content

Commit b45851b

Browse files
committed
fix typings after merge
1 parent 9f99e35 commit b45851b

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

src/components/AddressForm.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ type AddressFormProps = {
4444
zip?: string;
4545

4646
/** Callback which is executed when the user changes address, city or state */
47-
onAddressChanged?: (value: unknown, key: string) => void;
47+
onAddressChanged?: (value: unknown, key: unknown) => void;
4848

4949
/** Callback which is executed when the user submits his address changes */
50-
onSubmit: () => void;
50+
onSubmit: (values: FormOnyxValues<typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM | typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>) => void;
5151

5252
/** Whether or not should the form data should be saved as draft */
5353
shouldSaveDraft?: boolean;
@@ -56,7 +56,7 @@ type AddressFormProps = {
5656
submitButtonText?: string;
5757

5858
/** A unique Onyx key identifying the form */
59-
formID: typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM;
59+
formID: typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM | typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM;
6060
};
6161

6262
function AddressForm({
@@ -88,7 +88,7 @@ function AddressForm({
8888
* @returns - An object containing the errors for each inputID
8989
*/
9090

91-
const validator = useCallback((values: FormOnyxValues<typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM>): Errors => {
91+
const validator = useCallback((values: FormOnyxValues<typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM | typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>): Errors => {
9292
const errors: Errors & {
9393
zipPostCode?: string | string[];
9494
} = {};
@@ -147,7 +147,7 @@ function AddressForm({
147147
InputComponent={AddressSearch}
148148
inputID={INPUT_IDS.ADDRESS_LINE_1}
149149
label={translate('common.addressLine', {lineNumber: 1})}
150-
onValueChange={(data: unknown, key: string) => {
150+
onValueChange={(data: unknown, key: unknown) => {
151151
onAddressChanged(data, key);
152152
// This enforces the country selector to use the country from address instead of the country from URL
153153
Navigation.setParams({country: undefined});

src/components/Form/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type TextInput from '@components/TextInput';
1616
import type ValuePicker from '@components/ValuePicker';
1717
import type {MaybePhraseKey} from '@libs/Localize';
1818
import type BusinessTypePicker from '@pages/ReimbursementAccount/BusinessInfo/substeps/TypeBusiness/BusinessTypePicker';
19+
import type {Country} from '@src/CONST';
1920
import type {OnyxFormKey, OnyxValues} from '@src/ONYXKEYS';
2021
import type {BaseForm} from '@src/types/form/Form';
2122

@@ -42,11 +43,12 @@ type ValidInputs =
4243
| typeof DatePicker
4344
| typeof RadioButtons;
4445

45-
type ValueTypeKey = 'string' | 'boolean' | 'date';
46+
type ValueTypeKey = 'string' | 'boolean' | 'date' | 'country';
4647
type ValueTypeMap = {
4748
string: string;
4849
boolean: boolean;
4950
date: Date;
51+
country: Country | '';
5052
};
5153
type FormValue = ValueOf<ValueTypeMap>;
5254

src/libs/Navigation/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
} from '@react-navigation/native';
1313
import type {ValueOf} from 'type-fest';
1414
import type CONST from '@src/CONST';
15+
import type {Country} from '@src/CONST';
1516
import type NAVIGATORS from '@src/NAVIGATORS';
1617
import type {HybridAppRoute, Route as Routes} from '@src/ROUTES';
1718
import type SCREENS from '@src/SCREENS';
@@ -107,7 +108,7 @@ type SettingsNavigatorParamList = {
107108
[SCREENS.SETTINGS.PROFILE.LEGAL_NAME]: undefined;
108109
[SCREENS.SETTINGS.PROFILE.DATE_OF_BIRTH]: undefined;
109110
[SCREENS.SETTINGS.PROFILE.ADDRESS]: {
110-
country?: string;
111+
country?: Country | '';
111112
};
112113
[SCREENS.SETTINGS.PROFILE.ADDRESS_COUNTRY]: {
113114
backTo?: Routes;

src/pages/settings/Profile/PersonalDetails/AddressPage.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import useThemeStyles from '@hooks/useThemeStyles';
1212
import Navigation from '@libs/Navigation/Navigation';
1313
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
1414
import * as PersonalDetails from '@userActions/PersonalDetails';
15+
import type {FormOnyxValues} from '@src/components/Form/types';
16+
import type {Country} from '@src/CONST';
1517
import ONYXKEYS from '@src/ONYXKEYS';
1618
import type SCREENS from '@src/SCREENS';
1719
import type {PrivatePersonalDetails} from '@src/types/onyx';
@@ -28,7 +30,7 @@ type AddressPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCRE
2830
* Submit form to update user's first and last legal name
2931
* @param values - form input values
3032
*/
31-
function updateAddress(values: Address) {
33+
function updateAddress(values: FormOnyxValues<typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>) {
3234
PersonalDetails.updateAddress(
3335
values.addressLine1?.trim() ?? '',
3436
values.addressLine2?.trim() ?? '',
@@ -62,29 +64,32 @@ function AddressPage({privatePersonalDetails, route}: AddressPageProps) {
6264
setZipcode(address.zip);
6365
}, [address]);
6466

65-
const handleAddressChange = useCallback((value: string, key: keyof Address) => {
66-
if (key !== 'country' && key !== 'state' && key !== 'city' && key !== 'zipPostCode') {
67+
const handleAddressChange = useCallback((value: unknown, key: unknown) => {
68+
const countryValue = value as Country | '';
69+
const addressKey = key as keyof Address;
70+
71+
if (addressKey !== 'country' && addressKey !== 'state' && addressKey !== 'city' && addressKey !== 'zipPostCode') {
6772
return;
6873
}
69-
if (key === 'country') {
70-
setCurrentCountry(value);
74+
if (addressKey === 'country') {
75+
setCurrentCountry(countryValue);
7176
setState('');
7277
setCity('');
7378
setZipcode('');
7479
return;
7580
}
76-
if (key === 'state') {
77-
setState(value);
81+
if (addressKey === 'state') {
82+
setState(countryValue);
7883
setCity('');
7984
setZipcode('');
8085
return;
8186
}
82-
if (key === 'city') {
83-
setCity(value);
87+
if (addressKey === 'city') {
88+
setCity(countryValue);
8489
setZipcode('');
8590
return;
8691
}
87-
setZipcode(value);
92+
setZipcode(countryValue);
8893
}, []);
8994

9095
useEffect(() => {

src/types/form/HomeAddressForm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {ValueOf} from 'type-fest';
2+
import type {Country} from '@src/CONST';
23
import type Form from './Form';
34

45
const INPUT_IDS = {
@@ -17,7 +18,7 @@ type HomeAddressForm = Form<
1718
{
1819
[INPUT_IDS.ADDRESS_LINE_1]: string;
1920
[INPUT_IDS.ADDRESS_LINE_2]: string;
20-
[INPUT_IDS.COUNTRY]: string;
21+
[INPUT_IDS.COUNTRY]: Country | '';
2122
[INPUT_IDS.STATE]: string;
2223
[INPUT_IDS.CITY]: string;
2324
[INPUT_IDS.ZIP_POST_CODE]: string;

0 commit comments

Comments
 (0)