Skip to content
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

fix company website field missing https #39162

Merged
merged 7 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/libs/BankAccountUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Str from 'expensify-common/lib/str';
import type {OnyxEntry} from 'react-native-onyx';
import type * as OnyxTypes from '@src/types/onyx';

function getDefaultCompanyWebsite(session: OnyxEntry<OnyxTypes.Session>, user: OnyxEntry<OnyxTypes.User>): string {
return user?.isFromPublicDomain ? 'https://' : `https://www.${Str.extractEmailDomain(session?.email ?? '')}`;
}
// eslint-disable-next-line import/prefer-default-export
export {getDefaultCompanyWebsite};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import {WRITE_COMMANDS} from '@libs/API/types';
import {getDefaultCompanyWebsite} from '@libs/BankAccountUtils';
import * as PlaidDataProps from '@pages/ReimbursementAccount/plaidDataPropTypes';
import * as ReimbursementAccountProps from '@pages/ReimbursementAccount/reimbursementAccountPropTypes';
import CONST from '@src/CONST';
Expand All @@ -12,7 +13,7 @@ import type * as OnyxTypes from '@src/types/onyx';
/**
* Reset user's reimbursement account. This will delete the bank account.
*/
function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry<OnyxTypes.Session>, policyID: string) {
function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry<OnyxTypes.Session>, policyID: string, user: OnyxEntry<OnyxTypes.User>) {
if (!bankAccountID) {
throw new Error('Missing bankAccountID when attempting to reset free plan bank account');
}
Expand Down Expand Up @@ -84,7 +85,7 @@ function resetFreePlanBankAccount(bankAccountID: number, session: OnyxEntry<Onyx
[INPUT_IDS.BUSINESS_INFO_STEP.STATE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.ZIP_CODE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_PHONE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_WEBSITE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_WEBSITE]: getDefaultCompanyWebsite(session, user),
[INPUT_IDS.BUSINESS_INFO_STEP.COMPANY_TAX_ID]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.INCORPORATION_TYPE]: '',
[INPUT_IDS.BUSINESS_INFO_STEP.INCORPORATION_DATE]: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Str from 'expensify-common/lib/str';
import React, {useEffect, useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
Expand All @@ -11,6 +10,7 @@ import useLocalize from '@hooks/useLocalize';
import useReimbursementAccountStepFormSubmit from '@hooks/useReimbursementAccountStepFormSubmit';
import type {SubStepProps} from '@hooks/useSubStep/types';
import useThemeStyles from '@hooks/useThemeStyles';
import {getDefaultCompanyWebsite} from '@libs/BankAccountUtils';
import * as ValidationUtils from '@libs/ValidationUtils';
import * as BankAccounts from '@userActions/BankAccounts';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -48,10 +48,7 @@ function WebsiteBusiness({reimbursementAccount, user, session, onNext, isEditing
const {translate} = useLocalize();
const styles = useThemeStyles();

const defaultWebsiteExample = useMemo(
() => (user?.isFromPublicDomain ? 'https://' : `https://www.${Str.extractEmailDomain(session?.email ?? '')}`),
[session?.email, user?.isFromPublicDomain],
);
const defaultWebsiteExample = useMemo(() => getDefaultCompanyWebsite(session, user), [session, user]);
const defaultCompanyWebsite = reimbursementAccount?.achData?.website ?? defaultWebsiteExample;

const handleSubmit = useReimbursementAccountStepFormSubmit({
Expand Down
13 changes: 11 additions & 2 deletions src/pages/workspace/WorkspaceResetBankAccountModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ const propTypes = {
/** Currently logged in user email */
email: PropTypes.string,
}).isRequired,

/** Information about the logged in user's account */
user: PropTypes.shape({
/** Whether or not the user is on a public domain email account or not */
isFromPublicDomain: PropTypes.bool,
}).isRequired,
};

function WorkspaceResetBankAccountModal({reimbursementAccount, session}) {
function WorkspaceResetBankAccountModal({reimbursementAccount, session, user}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const achData = lodashGet(reimbursementAccount, 'achData') || {};
Expand All @@ -48,7 +54,7 @@ function WorkspaceResetBankAccountModal({reimbursementAccount, session}) {
}
danger
onCancel={BankAccounts.cancelResetFreePlanBankAccount}
onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID, session, achData.policyID)}
onConfirm={() => BankAccounts.resetFreePlanBankAccount(bankAccountID, session, achData.policyID, user)}
shouldShowCancelButton
isVisible
/>
Expand All @@ -62,4 +68,7 @@ export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
user: {
key: ONYXKEYS.USER,
},
})(WorkspaceResetBankAccountModal);
Loading