@servicetitan/onboarding-ui 2.0.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/company-profile/components/state-and-province-dropdown-input.d.ts.map +1 -1
- package/dist/company-profile/components/state-and-province-dropdown-input.js +7 -12
- package/dist/company-profile/components/state-and-province-dropdown-input.js.map +1 -1
- package/dist/company-profile/stores/__mocks__/company-profile-form-mock-data.d.ts +1 -0
- package/dist/company-profile/stores/__mocks__/company-profile-form-mock-data.d.ts.map +1 -1
- package/dist/company-profile/stores/__mocks__/company-profile-form-mock-data.js +11 -1
- package/dist/company-profile/stores/__mocks__/company-profile-form-mock-data.js.map +1 -1
- package/dist/company-profile/stores/company-profile-form.store.d.ts +2 -3
- package/dist/company-profile/stores/company-profile-form.store.d.ts.map +1 -1
- package/dist/company-profile/stores/company-profile-form.store.js +9 -29
- package/dist/company-profile/stores/company-profile-form.store.js.map +1 -1
- package/dist/company-profile/utils/country-config.d.ts +18 -0
- package/dist/company-profile/utils/country-config.d.ts.map +1 -0
- package/dist/company-profile/utils/country-config.js +84 -0
- package/dist/company-profile/utils/country-config.js.map +1 -0
- package/package.json +2 -2
- package/src/company-profile/components/state-and-province-dropdown-input.tsx +8 -13
- package/src/company-profile/stores/__mocks__/company-profile-form-mock-data.ts +12 -1
- package/src/company-profile/stores/__tests__/company-profile-form.store.test.ts +13 -1
- package/src/company-profile/stores/company-profile-form.store.ts +11 -28
- package/src/company-profile/utils/country-config.ts +79 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-and-province-dropdown-input.d.ts","sourceRoot":"","sources":["../../../src/company-profile/components/state-and-province-dropdown-input.tsx"],"names":[],"mappings":";AACA,OAAO,EAAQ,iBAAiB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAkB,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"state-and-province-dropdown-input.d.ts","sourceRoot":"","sources":["../../../src/company-profile/components/state-and-province-dropdown-input.tsx"],"names":[],"mappings":";AACA,OAAO,EAAQ,iBAAiB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAkB,MAAM,sCAAsC,CAAC;AAG1F,UAAU,kCAAmC,SAAQ,iBAAiB;IAClE,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACvC,oBAAoB,EAAE,kBAAkB,EAAE,CAAC;IAC3C,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,cAAc,CAAC;CAC1B;AAKD,eAAO,MAAM,6BAA6B,UAC9B,kCAAkC,gBAyD7C,CAAC"}
|
|
@@ -13,6 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
import { useEffect } from 'react';
|
|
14
14
|
import { Form } from '@servicetitan/design-system';
|
|
15
15
|
import { observer } from 'mobx-react';
|
|
16
|
+
import { CountryConfig } from '../utils/country-config';
|
|
16
17
|
const toTitleCase = (str) => str.replace(/\w\S*/g, txt => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
|
|
17
18
|
export const StateAndProvinceDropdownInput = observer((props) => {
|
|
18
19
|
const { fieldState, regionNameToCodeMap, countryAndRegionData, countryCode, width, placeholder } = props, rest = __rest(props, ["fieldState", "regionNameToCodeMap", "countryAndRegionData", "countryCode", "width", "placeholder"]);
|
|
@@ -31,25 +32,19 @@ export const StateAndProvinceDropdownInput = observer((props) => {
|
|
|
31
32
|
onChange((_a = regionNameToCodeMap.get(toTitleCase(value))) !== null && _a !== void 0 ? _a : ' ');
|
|
32
33
|
}
|
|
33
34
|
}, [onChange, regionNameToCodeMap, value]);
|
|
34
|
-
|
|
35
|
-
let canadianRegionalData;
|
|
35
|
+
const regionalDataMap = new Map();
|
|
36
36
|
countryAndRegionData.forEach((countryOption) => {
|
|
37
37
|
const data = countryOption.Regions.map((option) => ({
|
|
38
38
|
key: option.Code,
|
|
39
39
|
value: option.Code,
|
|
40
40
|
text: option.Name,
|
|
41
41
|
}));
|
|
42
|
-
|
|
43
|
-
americanRegionalData = data;
|
|
44
|
-
}
|
|
45
|
-
if (countryOption.Country === 'CA') {
|
|
46
|
-
canadianRegionalData = data;
|
|
47
|
-
}
|
|
42
|
+
regionalDataMap.set(CountryConfig.getCountryCode(countryOption.Country), data);
|
|
48
43
|
});
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const options =
|
|
44
|
+
const formattedCountryCode = CountryConfig.getCountryCode(countryCode);
|
|
45
|
+
const countryConfig = CountryConfig.getCountryConfig(formattedCountryCode);
|
|
46
|
+
const regionType = countryConfig.regionType;
|
|
47
|
+
const options = regionalDataMap.get(formattedCountryCode);
|
|
53
48
|
return (_jsx(Form.Select, Object.assign({ search: true, fluid: true, width: width !== null && width !== void 0 ? width : '12', label: regionType, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : regionType, value: value, onChange: onChangeHandler, options: options }, rest)));
|
|
54
49
|
});
|
|
55
50
|
//# sourceMappingURL=state-and-province-dropdown-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-and-province-dropdown-input.js","sourceRoot":"","sources":["../../../src/company-profile/components/state-and-province-dropdown-input.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,IAAI,EAAqC,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"state-and-province-dropdown-input.js","sourceRoot":"","sources":["../../../src/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AAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAsB,EAAE,EAAE,CAAC,CAAC;YAChE,GAAG,EAAE,MAAM,CAAC,IAAI;YAChB,KAAK,EAAE,MAAM,CAAC,IAAI;YAClB,IAAI,EAAE,MAAM,CAAC,IAAI;SACpB,CAAC,CAAC,CAAC;QAEJ,eAAe,CAAC,GAAG,CAAC,aAAa,CAAC,cAAc,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;IAEH,MAAM,oBAAoB,GAAG,aAAa,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IACvE,MAAM,aAAa,GAAG,aAAa,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;IAC3E,MAAM,UAAU,GAAG,aAAc,CAAC,UAAU,CAAC;IAC7C,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAE1D,OAAO,CACH,KAAC,IAAI,CAAC,MAAM,kBACR,MAAM,QACN,KAAK,QACL,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,EACpB,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,UAAU,EACtC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,OAAQ,IACb,IAAI,EACV,CACL,CAAC;AACN,CAAC,CACJ,CAAC"}
|
|
@@ -2,4 +2,5 @@ import { ProfileModel } from '../company-profile-form.store';
|
|
|
2
2
|
export declare const CompanyProfileFormCorrect: ProfileModel;
|
|
3
3
|
export declare const CompanyProfileFormEmptyValues: ProfileModel;
|
|
4
4
|
export declare const CompanyProfileFormCanadian: ProfileModel;
|
|
5
|
+
export declare const CompanyProfileFormAustralian: ProfileModel;
|
|
5
6
|
//# sourceMappingURL=company-profile-form-mock-data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"company-profile-form-mock-data.d.ts","sourceRoot":"","sources":["../../../../src/company-profile/stores/__mocks__/company-profile-form-mock-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,eAAO,MAAM,yBAAyB,EAAE,YASvC,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,YAQ3C,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,YAQxC,CAAC"}
|
|
1
|
+
{"version":3,"file":"company-profile-form-mock-data.d.ts","sourceRoot":"","sources":["../../../../src/company-profile/stores/__mocks__/company-profile-form-mock-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,eAAO,MAAM,yBAAyB,EAAE,YASvC,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,YAQ3C,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,YAQxC,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,YAS1C,CAAC"}
|
|
@@ -24,6 +24,16 @@ export const CompanyProfileFormCanadian = {
|
|
|
24
24
|
companyCountry: 'ca',
|
|
25
25
|
companyStateCode: 'CA',
|
|
26
26
|
companyCity: 'Glendale',
|
|
27
|
-
companyZipCode: '
|
|
27
|
+
companyZipCode: '123456',
|
|
28
|
+
};
|
|
29
|
+
export const CompanyProfileFormAustralian = {
|
|
30
|
+
companyName: 'Wyatt Works',
|
|
31
|
+
adminPhone: '(310) 855-8585',
|
|
32
|
+
companyStreetAddress: '123 Main St.',
|
|
33
|
+
companyCountry: 'Australia',
|
|
34
|
+
companyStateCode: 'CA',
|
|
35
|
+
companyCity: 'Glendale',
|
|
36
|
+
companyZipCode: '1234',
|
|
37
|
+
einOrBn: '',
|
|
28
38
|
};
|
|
29
39
|
//# sourceMappingURL=company-profile-form-mock-data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"company-profile-form-mock-data.js","sourceRoot":"","sources":["../../../../src/company-profile/stores/__mocks__/company-profile-form-mock-data.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,yBAAyB,GAAiB;IACnD,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,gBAAgB;IAC5B,oBAAoB,EAAE,cAAc;IACpC,cAAc,EAAE,KAAK;IACrB,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,OAAO;IACvB,OAAO,EAAE,EAAE;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAiB;IACvD,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,EAAE;IACd,oBAAoB,EAAE,EAAE;IACxB,cAAc,EAAE,EAAE;IAClB,gBAAgB,EAAE,EAAE;IACpB,WAAW,EAAE,EAAE;IACf,cAAc,EAAE,EAAE;CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAiB;IACpD,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,gBAAgB;IAC5B,oBAAoB,EAAE,cAAc;IACpC,cAAc,EAAE,IAAI;IACpB,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"company-profile-form-mock-data.js","sourceRoot":"","sources":["../../../../src/company-profile/stores/__mocks__/company-profile-form-mock-data.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,yBAAyB,GAAiB;IACnD,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,gBAAgB;IAC5B,oBAAoB,EAAE,cAAc;IACpC,cAAc,EAAE,KAAK;IACrB,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,OAAO;IACvB,OAAO,EAAE,EAAE;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAiB;IACvD,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,EAAE;IACd,oBAAoB,EAAE,EAAE;IACxB,cAAc,EAAE,EAAE;IAClB,gBAAgB,EAAE,EAAE;IACpB,WAAW,EAAE,EAAE;IACf,cAAc,EAAE,EAAE;CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAiB;IACpD,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,gBAAgB;IAC5B,oBAAoB,EAAE,cAAc;IACpC,cAAc,EAAE,IAAI;IACpB,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,QAAQ;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAiB;IACtD,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,gBAAgB;IAC5B,oBAAoB,EAAE,cAAc;IACpC,cAAc,EAAE,WAAW;IAC3B,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,MAAM;IACtB,OAAO,EAAE,EAAE;CACd,CAAC"}
|
|
@@ -51,9 +51,8 @@ export declare class CompanyProfileFormStore implements ICompanyProfileFormStore
|
|
|
51
51
|
form: FormState<ICompanyProfileFormType>;
|
|
52
52
|
constructor();
|
|
53
53
|
setFormErrorCheck: (value: boolean) => void;
|
|
54
|
-
|
|
55
|
-
get
|
|
56
|
-
get einOrBnMask(): "999999999" | "99-9999999";
|
|
54
|
+
get zipCodeMask(): string;
|
|
55
|
+
get einOrBnMask(): string;
|
|
57
56
|
get einOrBnInputProps(): {
|
|
58
57
|
label: string;
|
|
59
58
|
placeholder: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"company-profile-form.store.d.ts","sourceRoot":"","sources":["../../../src/company-profile/stores/company-profile-form.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EACH,eAAe,EACf,kBAAkB,EAGrB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"company-profile-form.store.d.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AAC,CAAC;IACxC,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,wBAAwB;IACrC,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,EAAE,SAAS,CAAC,uBAAuB,CAAC,CAAC;CAC5C;AAED,UAAU,yBAAyB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,oBAAoB,EAAE,kBAAkB,EAAE,CAAC;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED,qBACa,uBAAwB,YAAW,wBAAwB;IACxD,aAAa,UAAS;IACtB,cAAc,UAAS;IACvB,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,oBAAoB,EAAE,kBAAkB,EAAE,CAAM;IAChD,SAAS,SAAM;IACf,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAE7D,IAAI,EAAE,SAAS,CAAC,uBAAuB,CAAC,CASrC;;IAsBH,iBAAiB,UAAW,OAAO,UAEjC;IAEF,IACI,WAAW,WAEd;IAED,IACI,WAAW,WAEd;IAED,IACI,iBAAiB;;;MAEpB;IAGD,QAAQ,aAAc,YAAY,WAAW,yBAAyB,UAYpE;IAGF,UAAU,aAAoC;CACjD"}
|
|
@@ -12,11 +12,8 @@ import { InputFieldState, DropdownFieldState, commitFormState, setFormStateValue
|
|
|
12
12
|
import { injectable } from '@servicetitan/react-ioc';
|
|
13
13
|
import { PhoneValidator } from '../utils/validators';
|
|
14
14
|
import { computed, action, observable, makeObservable } from 'mobx';
|
|
15
|
+
import { CountryConfig } from '../utils/country-config';
|
|
15
16
|
const required = (value) => (!value || value.length === 0) && 'cannot be empty string';
|
|
16
|
-
const usZipMask = '99999';
|
|
17
|
-
const canadaZipMask = '*** ***';
|
|
18
|
-
const canadaBNMask = '999999999';
|
|
19
|
-
const usEinMask = '99-9999999';
|
|
20
17
|
let CompanyProfileFormStore = class CompanyProfileFormStore {
|
|
21
18
|
constructor() {
|
|
22
19
|
Object.defineProperty(this, "showFormError", {
|
|
@@ -78,15 +75,6 @@ let CompanyProfileFormStore = class CompanyProfileFormStore {
|
|
|
78
75
|
this.showFormError = value;
|
|
79
76
|
}
|
|
80
77
|
});
|
|
81
|
-
Object.defineProperty(this, "isCanada", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
value: (country) => {
|
|
86
|
-
const lowerCountry = country === null || country === void 0 ? void 0 : country.toLowerCase();
|
|
87
|
-
return lowerCountry === 'ca' || lowerCountry === 'canada';
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
78
|
Object.defineProperty(this, "initForm", {
|
|
91
79
|
enumerable: true,
|
|
92
80
|
configurable: true,
|
|
@@ -116,31 +104,23 @@ let CompanyProfileFormStore = class CompanyProfileFormStore {
|
|
|
116
104
|
this.form.$.companyZipCode.validators(($) => {
|
|
117
105
|
const country = this.form.$.companyCountry.value;
|
|
118
106
|
const zip = ($ || '').toLowerCase().replace(/ /g, '');
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
: !/^\d{5}$/.test(zip) && 'Invalid Zip Code';
|
|
107
|
+
return (!CountryConfig.getCountryConfig(country).zipValidationRegexp.test(zip) &&
|
|
108
|
+
'Invalid Zip Code');
|
|
122
109
|
});
|
|
123
110
|
this.form.$.einOrBn.validators(($) => {
|
|
124
|
-
const
|
|
125
|
-
|
|
111
|
+
const countryConfig = CountryConfig.getCountryConfig(this.form.$.companyCountry.value);
|
|
112
|
+
const errorMessage = `Invalid ${countryConfig.bizsIdInputProps.label}`;
|
|
113
|
+
return $ && !countryConfig.bizsIdValidationRegexp.test($) && errorMessage;
|
|
126
114
|
});
|
|
127
115
|
}
|
|
128
116
|
get zipCodeMask() {
|
|
129
|
-
return
|
|
117
|
+
return CountryConfig.getCountryConfig(this.form.$.companyCountry.$).zipCodeMask;
|
|
130
118
|
}
|
|
131
119
|
get einOrBnMask() {
|
|
132
|
-
return
|
|
120
|
+
return CountryConfig.getCountryConfig(this.form.$.companyCountry.$).bizsIdMask;
|
|
133
121
|
}
|
|
134
122
|
get einOrBnInputProps() {
|
|
135
|
-
return
|
|
136
|
-
? {
|
|
137
|
-
label: 'BN Number',
|
|
138
|
-
placeholder: 'XXXXXXXXX',
|
|
139
|
-
}
|
|
140
|
-
: {
|
|
141
|
-
label: 'EIN Number',
|
|
142
|
-
placeholder: 'XX-XXXXXXX',
|
|
143
|
-
};
|
|
123
|
+
return CountryConfig.getCountryConfig(this.form.$.companyCountry.$).bizsIdInputProps;
|
|
144
124
|
}
|
|
145
125
|
};
|
|
146
126
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"company-profile-form.store.js","sourceRoot":"","sources":["../../../src/company-profile/stores/company-profile-form.store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,kBAAkB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"company-profile-form.store.js","sourceRoot":"","sources":["../../../src/company-profile/stores/company-profile-form.store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,kBAAkB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,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;0DAAgB;AACf;IAAX,UAAU;8BAAkB,GAAG;gEAA6B;AAiC7D;IADC,MAAM;;kEAGL;AAGF;IADC,QAAQ;;;0DAGR;AAGD;IADC,QAAQ;;;0DAGR;AAGD;IADC,QAAQ;;;gEAGR;AAGD;IADC,MAAM;;yDAaL;AAGF;IADC,MAAM;;2DACuC;AA1ErC,uBAAuB;IADnC,UAAU,EAAE;;GACA,uBAAuB,CA2EnC;SA3EY,uBAAuB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare type CountryCode = 'us' | 'ca' | 'au';
|
|
2
|
+
export declare abstract class CountryConfig {
|
|
3
|
+
private static countryConfigMap;
|
|
4
|
+
static getCountryCode: (country: string) => CountryCode;
|
|
5
|
+
static getCountryConfig: (country: string) => ICountryConfig;
|
|
6
|
+
}
|
|
7
|
+
export interface ICountryConfig {
|
|
8
|
+
zipCodeMask: string;
|
|
9
|
+
zipValidationRegexp: RegExp;
|
|
10
|
+
bizsIdValidationRegexp: RegExp;
|
|
11
|
+
bizsIdMask: string;
|
|
12
|
+
bizsIdInputProps: {
|
|
13
|
+
label: string;
|
|
14
|
+
placeholder: string;
|
|
15
|
+
};
|
|
16
|
+
regionType: string;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=country-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"country-config.d.ts","sourceRoot":"","sources":["../../../src/company-profile/utils/country-config.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE7C,8BAAsB,aAAa;IAC/B,OAAO,CAAC,MAAM,CAAC,gBAAgB,CA2C5B;IAEH,MAAM,CAAC,cAAc,YAAa,MAAM,KAAG,WAAW,CAgBpD;IAEF,MAAM,CAAC,gBAAgB,YAAa,MAAM,oBAExC;CACL;AAED,MAAM,WAAW,cAAc;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,UAAU,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
export class CountryConfig {
|
|
3
|
+
}
|
|
4
|
+
_a = CountryConfig;
|
|
5
|
+
Object.defineProperty(CountryConfig, "countryConfigMap", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: new Map([
|
|
10
|
+
[
|
|
11
|
+
'us',
|
|
12
|
+
{
|
|
13
|
+
zipCodeMask: '99999',
|
|
14
|
+
zipValidationRegexp: /^\d{5}$/,
|
|
15
|
+
bizsIdMask: '99-9999999',
|
|
16
|
+
bizsIdValidationRegexp: /^\d{9}$/,
|
|
17
|
+
bizsIdInputProps: {
|
|
18
|
+
label: 'EIN Number',
|
|
19
|
+
placeholder: 'XX-XXXXXXX',
|
|
20
|
+
},
|
|
21
|
+
regionType: 'State',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
'ca',
|
|
26
|
+
{
|
|
27
|
+
zipCodeMask: '*** ***',
|
|
28
|
+
zipValidationRegexp: /^[0-9A-Za-z]{6}$/,
|
|
29
|
+
bizsIdValidationRegexp: /^\d{9}$/,
|
|
30
|
+
bizsIdMask: '999999999',
|
|
31
|
+
bizsIdInputProps: {
|
|
32
|
+
label: 'BN Number',
|
|
33
|
+
placeholder: 'XXXXXXXXX',
|
|
34
|
+
},
|
|
35
|
+
regionType: 'Province',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
'au',
|
|
40
|
+
{
|
|
41
|
+
zipCodeMask: '9999',
|
|
42
|
+
zipValidationRegexp: /^\d{4}$/,
|
|
43
|
+
bizsIdValidationRegexp: /^\d{11}$/,
|
|
44
|
+
bizsIdMask: '99 999 999 999',
|
|
45
|
+
bizsIdInputProps: {
|
|
46
|
+
label: 'ABN Number',
|
|
47
|
+
placeholder: 'XX XXX XXX XXX',
|
|
48
|
+
},
|
|
49
|
+
regionType: 'State',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
])
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(CountryConfig, "getCountryCode", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: true,
|
|
57
|
+
writable: true,
|
|
58
|
+
value: (country) => {
|
|
59
|
+
const lowerCountry = country === null || country === void 0 ? void 0 : country.toLowerCase();
|
|
60
|
+
switch (lowerCountry) {
|
|
61
|
+
case 'us':
|
|
62
|
+
case 'usa':
|
|
63
|
+
case 'united states':
|
|
64
|
+
return 'us';
|
|
65
|
+
case 'ca':
|
|
66
|
+
case 'canada':
|
|
67
|
+
return 'ca';
|
|
68
|
+
case 'au':
|
|
69
|
+
case 'australia':
|
|
70
|
+
return 'au';
|
|
71
|
+
default:
|
|
72
|
+
return 'us';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(CountryConfig, "getCountryConfig", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: (country) => {
|
|
81
|
+
return _a.countryConfigMap.get(_a.getCountryCode(country));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=country-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"country-config.js","sourceRoot":"","sources":["../../../src/company-profile/utils/country-config.ts"],"names":[],"mappings":";AAEA,MAAM,OAAgB,aAAa;;;AAC/B;;;;WAAoE,IAAI,GAAG,CAAC;QACxE;YACI,IAAI;YACJ;gBACI,WAAW,EAAE,OAAO;gBACpB,mBAAmB,EAAE,SAAS;gBAC9B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C,CAAE,CAAC;IACpE,CAAC;EAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/onboarding-ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Shared components between servicetitan monolith and Onboarding",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"less": true,
|
|
71
71
|
"webpack": false
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "4e7f2e0a806cc50556dfc81138dfb7b9146be4f2"
|
|
74
74
|
}
|
|
@@ -3,6 +3,7 @@ import { Form, FormDropdownProps, SemanticWIDTHS } from '@servicetitan/design-sy
|
|
|
3
3
|
import { observer } from 'mobx-react';
|
|
4
4
|
import { DropdownFieldState } from '@servicetitan/form';
|
|
5
5
|
import { CountryWithRegions, DropdownRegion } from '../stores/company-profile-form.store';
|
|
6
|
+
import { CountryConfig } from '../utils/country-config';
|
|
6
7
|
|
|
7
8
|
interface StateAndProvinceDropdownInputProps extends FormDropdownProps {
|
|
8
9
|
countryCode: string;
|
|
@@ -42,8 +43,7 @@ export const StateAndProvinceDropdownInput = observer(
|
|
|
42
43
|
}
|
|
43
44
|
}, [onChange, regionNameToCodeMap, value]);
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
let canadianRegionalData;
|
|
46
|
+
const regionalDataMap = new Map();
|
|
47
47
|
|
|
48
48
|
countryAndRegionData.forEach((countryOption: CountryWithRegions) => {
|
|
49
49
|
const data = countryOption.Regions.map((option: DropdownRegion) => ({
|
|
@@ -51,19 +51,14 @@ export const StateAndProvinceDropdownInput = observer(
|
|
|
51
51
|
value: option.Code,
|
|
52
52
|
text: option.Name,
|
|
53
53
|
}));
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
if (countryOption.Country === 'CA') {
|
|
58
|
-
canadianRegionalData = data;
|
|
59
|
-
}
|
|
54
|
+
|
|
55
|
+
regionalDataMap.set(CountryConfig.getCountryCode(countryOption.Country), data);
|
|
60
56
|
});
|
|
61
57
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const options = regionType === 'Province' ? canadianRegionalData : americanRegionalData;
|
|
58
|
+
const formattedCountryCode = CountryConfig.getCountryCode(countryCode);
|
|
59
|
+
const countryConfig = CountryConfig.getCountryConfig(formattedCountryCode);
|
|
60
|
+
const regionType = countryConfig!.regionType;
|
|
61
|
+
const options = regionalDataMap.get(formattedCountryCode);
|
|
67
62
|
|
|
68
63
|
return (
|
|
69
64
|
<Form.Select
|
|
@@ -28,5 +28,16 @@ export const CompanyProfileFormCanadian: ProfileModel = {
|
|
|
28
28
|
companyCountry: 'ca',
|
|
29
29
|
companyStateCode: 'CA',
|
|
30
30
|
companyCity: 'Glendale',
|
|
31
|
-
companyZipCode: '
|
|
31
|
+
companyZipCode: '123456',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const CompanyProfileFormAustralian: ProfileModel = {
|
|
35
|
+
companyName: 'Wyatt Works',
|
|
36
|
+
adminPhone: '(310) 855-8585',
|
|
37
|
+
companyStreetAddress: '123 Main St.',
|
|
38
|
+
companyCountry: 'Australia',
|
|
39
|
+
companyStateCode: 'CA',
|
|
40
|
+
companyCity: 'Glendale',
|
|
41
|
+
companyZipCode: '1234',
|
|
42
|
+
einOrBn: '',
|
|
32
43
|
};
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
CompanyProfileFormCorrect,
|
|
5
5
|
CompanyProfileFormEmptyValues,
|
|
6
6
|
CompanyProfileFormCanadian,
|
|
7
|
+
CompanyProfileFormAustralian,
|
|
7
8
|
} from '../__mocks__/company-profile-form-mock-data';
|
|
8
9
|
|
|
9
10
|
const rootContainer = new Container();
|
|
@@ -32,10 +33,21 @@ describe('Company Profile Form Store [View Functionality] Tests', () => {
|
|
|
32
33
|
expect(store.form.hasError).toBeTruthy();
|
|
33
34
|
});
|
|
34
35
|
|
|
35
|
-
test('Expect forms initialized with CompanyCountry set to Canada show correct phone masking', () => {
|
|
36
|
+
test('Expect forms initialized with CompanyCountry set to Canada show correct phone masking', async () => {
|
|
36
37
|
const container = initContainer();
|
|
37
38
|
const store = container.get(CompanyProfileFormStore);
|
|
38
39
|
store.initForm(CompanyProfileFormCanadian, { phonePattern: /(.*)/ } as any);
|
|
40
|
+
await store.form.validate();
|
|
41
|
+
expect(store.form.hasError).toBeFalsy();
|
|
39
42
|
expect(store.zipCodeMask).toBe('*** ***');
|
|
40
43
|
});
|
|
44
|
+
|
|
45
|
+
test('Expect forms initialized with CompanyCountry set to Australia show correct phone masking', async () => {
|
|
46
|
+
const container = initContainer();
|
|
47
|
+
const store = container.get(CompanyProfileFormStore);
|
|
48
|
+
store.initForm(CompanyProfileFormAustralian, { phonePattern: /(.*)/ } as any);
|
|
49
|
+
await store.form.validate();
|
|
50
|
+
expect(store.form.hasError).toBeFalsy();
|
|
51
|
+
expect(store.zipCodeMask).toBe('9999');
|
|
52
|
+
});
|
|
41
53
|
});
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { injectable } from '@servicetitan/react-ioc';
|
|
9
9
|
import { PhoneValidator } from '../utils/validators';
|
|
10
10
|
import { computed, action, observable, makeObservable } from 'mobx';
|
|
11
|
+
import { CountryConfig } from '../utils/country-config';
|
|
11
12
|
|
|
12
13
|
const required = (value: string) => (!value || value.length === 0) && 'cannot be empty string';
|
|
13
14
|
|
|
@@ -32,11 +33,6 @@ export interface ProfileModel {
|
|
|
32
33
|
einOrBn?: string | undefined;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
const usZipMask = '99999';
|
|
36
|
-
const canadaZipMask = '*** ***';
|
|
37
|
-
const canadaBNMask = '999999999';
|
|
38
|
-
const usEinMask = '99-9999999';
|
|
39
|
-
|
|
40
36
|
export interface ICompanyProfileFormType {
|
|
41
37
|
[key: string]: FieldState<any>;
|
|
42
38
|
companyName: InputFieldState<string>;
|
|
@@ -89,16 +85,16 @@ export class CompanyProfileFormStore implements ICompanyProfileFormStore {
|
|
|
89
85
|
this.form.$.companyZipCode.validators(($: string) => {
|
|
90
86
|
const country = this.form.$.companyCountry.value;
|
|
91
87
|
const zip = ($ || '').toLowerCase().replace(/ /g, '');
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
return (
|
|
89
|
+
!CountryConfig.getCountryConfig(country)!.zipValidationRegexp.test(zip) &&
|
|
90
|
+
'Invalid Zip Code'
|
|
91
|
+
);
|
|
95
92
|
});
|
|
96
93
|
|
|
97
94
|
this.form.$.einOrBn.validators(($: string) => {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return $ && $.length !== 9 && errorMessage;
|
|
95
|
+
const countryConfig = CountryConfig.getCountryConfig(this.form.$.companyCountry.value)!;
|
|
96
|
+
const errorMessage = `Invalid ${countryConfig.bizsIdInputProps.label}`;
|
|
97
|
+
return $ && !countryConfig.bizsIdValidationRegexp.test($) && errorMessage;
|
|
102
98
|
});
|
|
103
99
|
}
|
|
104
100
|
|
|
@@ -107,32 +103,19 @@ export class CompanyProfileFormStore implements ICompanyProfileFormStore {
|
|
|
107
103
|
this.showFormError = value;
|
|
108
104
|
};
|
|
109
105
|
|
|
110
|
-
isCanada = (country: string) => {
|
|
111
|
-
const lowerCountry = country?.toLowerCase();
|
|
112
|
-
return lowerCountry === 'ca' || lowerCountry === 'canada';
|
|
113
|
-
};
|
|
114
|
-
|
|
115
106
|
@computed
|
|
116
107
|
get zipCodeMask() {
|
|
117
|
-
return
|
|
108
|
+
return CountryConfig.getCountryConfig(this.form.$.companyCountry.$)!.zipCodeMask;
|
|
118
109
|
}
|
|
119
110
|
|
|
120
111
|
@computed
|
|
121
112
|
get einOrBnMask() {
|
|
122
|
-
return
|
|
113
|
+
return CountryConfig.getCountryConfig(this.form.$.companyCountry.$)!.bizsIdMask;
|
|
123
114
|
}
|
|
124
115
|
|
|
125
116
|
@computed
|
|
126
117
|
get einOrBnInputProps() {
|
|
127
|
-
return
|
|
128
|
-
? {
|
|
129
|
-
label: 'BN Number',
|
|
130
|
-
placeholder: 'XXXXXXXXX',
|
|
131
|
-
}
|
|
132
|
-
: {
|
|
133
|
-
label: 'EIN Number',
|
|
134
|
-
placeholder: 'XX-XXXXXXX',
|
|
135
|
-
};
|
|
118
|
+
return CountryConfig.getCountryConfig(this.form.$.companyCountry.$)!.bizsIdInputProps;
|
|
136
119
|
}
|
|
137
120
|
|
|
138
121
|
@action
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export type CountryCode = 'us' | 'ca' | 'au';
|
|
2
|
+
|
|
3
|
+
export abstract class CountryConfig {
|
|
4
|
+
private static countryConfigMap: Map<CountryCode, ICountryConfig> = new Map([
|
|
5
|
+
[
|
|
6
|
+
'us',
|
|
7
|
+
{
|
|
8
|
+
zipCodeMask: '99999',
|
|
9
|
+
zipValidationRegexp: /^\d{5}$/,
|
|
10
|
+
bizsIdMask: '99-9999999',
|
|
11
|
+
bizsIdValidationRegexp: /^\d{9}$/,
|
|
12
|
+
bizsIdInputProps: {
|
|
13
|
+
label: 'EIN Number',
|
|
14
|
+
placeholder: 'XX-XXXXXXX',
|
|
15
|
+
},
|
|
16
|
+
regionType: 'State',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
'ca',
|
|
21
|
+
{
|
|
22
|
+
zipCodeMask: '*** ***',
|
|
23
|
+
zipValidationRegexp: /^[0-9A-Za-z]{6}$/,
|
|
24
|
+
bizsIdValidationRegexp: /^\d{9}$/,
|
|
25
|
+
bizsIdMask: '999999999',
|
|
26
|
+
bizsIdInputProps: {
|
|
27
|
+
label: 'BN Number',
|
|
28
|
+
placeholder: 'XXXXXXXXX',
|
|
29
|
+
},
|
|
30
|
+
regionType: 'Province',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
'au',
|
|
35
|
+
{
|
|
36
|
+
zipCodeMask: '9999',
|
|
37
|
+
zipValidationRegexp: /^\d{4}$/,
|
|
38
|
+
bizsIdValidationRegexp: /^\d{11}$/,
|
|
39
|
+
bizsIdMask: '99 999 999 999',
|
|
40
|
+
bizsIdInputProps: {
|
|
41
|
+
label: 'ABN Number',
|
|
42
|
+
placeholder: 'XX XXX XXX XXX',
|
|
43
|
+
},
|
|
44
|
+
regionType: 'State',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
static getCountryCode = (country: string): CountryCode => {
|
|
50
|
+
const lowerCountry = country?.toLowerCase();
|
|
51
|
+
switch (lowerCountry) {
|
|
52
|
+
case 'us':
|
|
53
|
+
case 'usa':
|
|
54
|
+
case 'united states':
|
|
55
|
+
return 'us';
|
|
56
|
+
case 'ca':
|
|
57
|
+
case 'canada':
|
|
58
|
+
return 'ca';
|
|
59
|
+
case 'au':
|
|
60
|
+
case 'australia':
|
|
61
|
+
return 'au';
|
|
62
|
+
default:
|
|
63
|
+
return 'us';
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
static getCountryConfig = (country: string) => {
|
|
68
|
+
return this.countryConfigMap.get(this.getCountryCode(country))!;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ICountryConfig {
|
|
73
|
+
zipCodeMask: string;
|
|
74
|
+
zipValidationRegexp: RegExp;
|
|
75
|
+
bizsIdValidationRegexp: RegExp;
|
|
76
|
+
bizsIdMask: string;
|
|
77
|
+
bizsIdInputProps: { label: string; placeholder: string };
|
|
78
|
+
regionType: string;
|
|
79
|
+
}
|