Skip to content

Commit e3e02c9

Browse files
authored
Merge pull request #5576 from Expensify/cmartins-autoFillDomain
Auto-fill company website in VBA flow
2 parents cfb28ce + bfaa72a commit e3e02c9

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/CONST.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ const CONST = {
426426
INDUSTRY_CODE: /^[0-9]{6}$/,
427427
SSN_LAST_FOUR: /[0-9]{4}/,
428428
NUMBER: /^[0-9]+$/,
429+
430+
// Adapted from: https://gist.github.com/dperini/729294
431+
// eslint-disable-next-line max-len
432+
HYPERLINK: /^(?:(?:(?:https?|ftp):\/\/)?)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i,
433+
429434
// eslint-disable-next-line max-len, no-misleading-character-class
430435
EMOJIS: /(?:\uD83D(?:\uDC41\u200D\uD83D\uDDE8|\uDC68\u200D\uD83D[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uDC69\u200D\uD83D\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|[\ud83c\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|[\ud83c\ude32-\ude3a]|[\ud83c\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/g,
431436
},

src/libs/ValidationUtils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ function isValidAge(date) {
6969
return moment().diff(moment(date), 'years') >= 18;
7070
}
7171

72+
/**
73+
*
74+
* @param {String} url
75+
* @returns {Boolean}
76+
*/
77+
function isValidURL(url) {
78+
return CONST.REGEX.HYPERLINK.test(url);
79+
}
80+
7281
/**
7382
* @param {Object} identity
7483
* @returns {Boolean}
@@ -125,4 +134,5 @@ export {
125134
isValidIdentity,
126135
isValidZipCode,
127136
isRequiredFulfilled,
137+
isValidURL,
128138
};

src/pages/ReimbursementAccount/CompanyStep.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _ from 'underscore';
2+
import lodashGet from 'lodash/get';
23
import React from 'react';
34
import {View} from 'react-native';
45
import Str from 'expensify-common/lib/str';
@@ -22,7 +23,7 @@ import TextLink from '../../components/TextLink';
2223
import StatePicker from '../../components/StatePicker';
2324
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
2425
import {
25-
isValidAddress, isValidDate, isValidZipCode, isRequiredFulfilled,
26+
isValidAddress, isValidDate, isValidZipCode, isRequiredFulfilled, isValidURL,
2627
} from '../../libs/ValidationUtils';
2728
import compose from '../../libs/compose';
2829
import ONYXKEYS from '../../ONYXKEYS';
@@ -45,14 +46,18 @@ class CompanyStep extends React.Component {
4546

4647
this.submit = this.submit.bind(this);
4748

49+
this.defaultWebsite = lodashGet(props, 'user.isFromPublicDomain', false)
50+
? 'https://'
51+
: `https://www.${Str.extractEmailDomain(props.session.email, '')}`;
52+
4853
this.state = {
4954
companyName: ReimbursementAccountUtils.getDefaultStateForField(props, 'companyName'),
5055
addressStreet: ReimbursementAccountUtils.getDefaultStateForField(props, 'addressStreet'),
5156
addressCity: ReimbursementAccountUtils.getDefaultStateForField(props, 'addressCity'),
5257
addressState: ReimbursementAccountUtils.getDefaultStateForField(props, 'addressState'),
5358
addressZipCode: ReimbursementAccountUtils.getDefaultStateForField(props, 'addressZipCode'),
5459
companyPhone: ReimbursementAccountUtils.getDefaultStateForField(props, 'companyPhone'),
55-
website: ReimbursementAccountUtils.getDefaultStateForField(props, 'website', 'https://'),
60+
website: ReimbursementAccountUtils.getDefaultStateForField(props, 'website', this.defaultWebsite),
5661
companyTaxID: ReimbursementAccountUtils.getDefaultStateForField(props, 'companyTaxID'),
5762
incorporationType: ReimbursementAccountUtils.getDefaultStateForField(props, 'incorporationType'),
5863
incorporationDate: ReimbursementAccountUtils.getDefaultStateForField(props, 'incorporationDate'),
@@ -130,7 +135,7 @@ class CompanyStep extends React.Component {
130135
errors.addressZipCode = true;
131136
}
132137

133-
if (!Str.isValidURL(this.state.website)) {
138+
if (!isValidURL(this.state.website)) {
134139
errors.website = true;
135140
}
136141

@@ -334,5 +339,11 @@ export default compose(
334339
reimbursementAccountDraft: {
335340
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT,
336341
},
342+
session: {
343+
key: ONYXKEYS.SESSION,
344+
},
345+
user: {
346+
key: ONYXKEYS.USER,
347+
},
337348
}),
338349
)(CompanyStep);

0 commit comments

Comments
 (0)