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

[NoQA] Integrate OpenPolicyExpensifyCardsPage API call #47064

2 changes: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5368,7 +5368,7 @@ const CONST = {
WORKSPACE_CARDS_LIST_LABEL_TYPE: {
CURRENT_BALANCE: 'currentBalance',
REMAINING_LIMIT: 'remainingLimit',
CASH_BACK: 'cashBack',
CASH_BACK: 'earnedCashback',
},

EXCLUDE_FROM_LAST_VISITED_PATH: [SCREENS.NOT_FOUND, SCREENS.SAML_SIGN_IN, SCREENS.VALIDATE_LOGIN] as string[],
Expand Down
2 changes: 1 addition & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ const ONYXKEYS = {
* Stores the card list for a given fundID and feed in the format: card_<fundID>_<bankName>
* So for example: card_12345_Expensify Card
*/
WORKSPACE_CARDS_LIST: 'card_',
WORKSPACE_CARDS_LIST: 'cards_',

/** Stores which connection is set up to use Continuous Reconciliation */
SHARED_NVP_EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION: 'sharedNVP_expensifyCard_continuousReconciliationConnection_',
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeatureList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function FeatureList({
</View>
))}
</View>
{secondaryButtonText && (
{!!secondaryButtonText && (
<Button
text={secondaryButtonText}
onPress={onSecondaryButtonPress}
Expand Down
4 changes: 2 additions & 2 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2711,8 +2711,8 @@ export default {
requestLimitIncrease: 'Request limit increase',
remainingLimitDescription:
'We consider a number of factors when calculating your remaining limit: your tenure as a customer, the business-related information you provided during signup, and the available cash in your business bank account. Your remaining limit can fluctuate on a daily basis.',
cashBack: 'Cash back',
cashBackDescription: 'Cash back balance is based on settled monthly Expensify Card spend across your workspace.',
earnedCashback: 'Cash back',
earnedCashbackDescription: 'Cash back balance is based on settled monthly Expensify Card spend across your workspace.',
issueNewCard: 'Issue new card',
finishSetup: 'Finish setup',
chooseBankAccount: 'Choose bank account',
Expand Down
4 changes: 2 additions & 2 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2761,8 +2761,8 @@ export default {
requestLimitIncrease: 'Solicitar aumento de límite',
remainingLimitDescription:
'A la hora de calcular tu límite restante, tenemos en cuenta una serie de factores: su antigüedad como cliente, la información relacionada con tu negocio que nos facilitaste al darte de alta y el efectivo disponible en tu cuenta bancaria comercial. Tu límite restante puede fluctuar a diario.',
cashBack: 'Reembolso',
cashBackDescription: 'El saldo de devolución se basa en el gasto mensual realizado con la tarjeta Expensify en tu espacio de trabajo.',
earnedCashback: 'Reembolso',
earnedCashbackDescription: 'El saldo de devolución se basa en el gasto mensual realizado con la tarjeta Expensify en tu espacio de trabajo.',
issueNewCard: 'Emitir nueva tarjeta',
finishSetup: 'Terminar configuración',
chooseBankAccount: 'Elegir cuenta bancaria',
Expand Down
38 changes: 19 additions & 19 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ function revealVirtualCardDetails(cardID: number): Promise<ExpensifyCardDetails>
});
}

function updateSettlementFrequency(policyID: string, frequency: ValueOf<typeof CONST.EXPENSIFY_CARD.FREQUENCY_SETTING>) {
function updateSettlementFrequency(workspaceAccountID: number, frequency: ValueOf<typeof CONST.EXPENSIFY_CARD.FREQUENCY_SETTING>) {
// TODO: remove this code when the API is ready
if (frequency === CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY) {
Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, {
Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, {
monthlySettlementDate: null,
});
} else {
Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, {
Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, {
monthlySettlementDate: new Date(),
});
}
Expand All @@ -222,7 +222,7 @@ function updateSettlementFrequency(policyID: string, frequency: ValueOf<typeof C
// const optimisticData: OnyxUpdate[] = [
// {
// onyxMethod: Onyx.METHOD.MERGE,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
// value: {
// monthlySettlementDate: '',
// },
Expand All @@ -232,7 +232,7 @@ function updateSettlementFrequency(policyID: string, frequency: ValueOf<typeof C
// const successData: OnyxUpdate[] = [
// {
// onyxMethod: Onyx.METHOD.MERGE,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
// value: {
// monthlySettlementDate: '',
// },
Expand All @@ -242,32 +242,32 @@ function updateSettlementFrequency(policyID: string, frequency: ValueOf<typeof C
// const failureData: OnyxUpdate[] = [
// {
// onyxMethod: Onyx.METHOD.MERGE,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
// value: {
// monthlySettlementDate: null,
// },
// },
// ];
//
// const parameters = {
// workspaceAccountID: policyID,
// workspaceAccountID,
// settlementFrequency: frequency,
// };
//
// API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY, parameters, {optimisticData, successData, failureData});
}

function updateSettlementAccount(policyID: string, accountID: number) {
function updateSettlementAccount(workspaceAccountID: string, accountID: number) {
// TODO: remove this code when the API is ready
Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`, {
Onyx.merge(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`, {
paymentBankAccountID: accountID,
});

// TODO: uncomment this code when the API is ready
// const optimisticData: OnyxUpdate[] = [
// {
// onyxMethod: Onyx.METHOD.MERGE,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
// value: {
// paymentBankAccountID: accountID,
// },
Expand All @@ -277,7 +277,7 @@ function updateSettlementAccount(policyID: string, accountID: number) {
// const successData: OnyxUpdate[] = [
// {
// onyxMethod: Onyx.METHOD.MERGE,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
// value: {
// paymentBankAccountID: accountID,
// },
Expand All @@ -287,15 +287,15 @@ function updateSettlementAccount(policyID: string, accountID: number) {
// const failureData: OnyxUpdate[] = [
// {
// onyxMethod: Onyx.METHOD.MERGE,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`,
// key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
// value: {
// paymentBankAccountID: null,
// },
// },
// ];
//
// const parameters = {
// workspaceAccountID: policyID,
// workspaceAccountID,
// settlementBankAccountID: accountID,
// };
//
Expand All @@ -313,7 +313,7 @@ function clearIssueNewCardFlow() {
});
}

function updateExpensifyCardLimit(policyID: string, cardID: number, newLimit: number, oldLimit?: number) {
function updateExpensifyCardLimit(workspaceAccountID: number, cardID: number, newLimit: number, oldLimit?: number) {
const authToken = NetworkStore.getAuthToken();

if (!authToken) {
Expand All @@ -323,11 +323,11 @@ function updateExpensifyCardLimit(policyID: string, cardID: number, newLimit: nu
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${policyID}_${CONST.EXPENSIFY_CARD.BANK}`,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`,
value: {
[cardID]: {
nameValuePairs: {
limit: newLimit,
unapprovedExpenseLimit: newLimit,
},
isLoading: true,
errors: null,
Expand All @@ -339,7 +339,7 @@ function updateExpensifyCardLimit(policyID: string, cardID: number, newLimit: nu
const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${policyID}_${CONST.EXPENSIFY_CARD.BANK}`,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`,
value: {
[cardID]: {
isLoading: false,
Expand All @@ -351,11 +351,11 @@ function updateExpensifyCardLimit(policyID: string, cardID: number, newLimit: nu
const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${policyID}_${CONST.EXPENSIFY_CARD.BANK}`,
key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`,
value: {
[cardID]: {
nameValuePairs: {
limit: oldLimit,
unapprovedExpenseLimit: oldLimit,
},
isLoading: false,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
Expand Down
34 changes: 32 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2036,15 +2036,45 @@ function openPolicyTaxesPage(policyID: string) {
API.read(READ_COMMANDS.OPEN_POLICY_TAXES_PAGE, params);
}

function openPolicyExpensifyCardsPage(policyID: string) {
function openPolicyExpensifyCardsPage(policyID: string, workspaceAccountID: number) {
const authToken = NetworkStore.getAuthToken();

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
value: {
isLoading: true,
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
value: {
isLoading: false,
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${workspaceAccountID}`,
value: {
isLoading: false,
},
},
];

const params: OpenPolicyExpensifyCardsPageParams = {
policyID,
authToken,
};

API.read(READ_COMMANDS.OPEN_POLICY_EXPENSIFY_CARDS_PAGE, params);
API.read(READ_COMMANDS.OPEN_POLICY_EXPENSIFY_CARDS_PAGE, params, {optimisticData, successData, failureData});
}

function openWorkspaceInvitePage(policyID: string, clientMemberEmails: string[]) {
Expand Down
5 changes: 1 addition & 4 deletions src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
!!policy?.connections?.xero?.config?.importTaxRates ||
!!policy?.connections?.netsuite?.options?.config?.syncOptions?.syncTax;
const policyID = policy?.id ?? '';
// @ts-expect-error a new props will be added during feed api implementation
const workspaceAccountID = (policy?.workspaceAccountID as string) ?? '';
const workspaceAccountID = policy?.workspaceAccountID ?? -1;
const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}${CONST.EXPENSIFY_CARD.BANK}`);
// Uncomment this line for testing disabled toggle feature - for c+
// const [cardsList = mockedCardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`);

const [isOrganizeWarningModalOpen, setIsOrganizeWarningModalOpen] = useState(false);
const [isIntegrateWarningModalOpen, setIsIntegrateWarningModalOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function CardReconciliationPage({policy, route}: CardReconciliationPageProps) {
const [reconciliationConnection] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_CONTINUOUS_RECONCILIATION_CONNECTION}${policy?.id}`);
const [isContinuousReconciliationOn] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_EXPENSIFY_CARD_USE_CONTINUOUS_RECONCILIATION}${policy?.id}`);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policy?.id}`);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policy?.workspaceAccountID}`);

const paymentBankAccountID = cardSettings?.paymentBankAccountID ?? -1;
const bankAccountTitle = bankAccountList?.[paymentBankAccountID]?.title ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function ReconciliationAccountSettingsPage({route}: ReconciliationAccountSetting
const {translate} = useLocalize();

const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policy?.workspaceAccountID}`);
const paymentBankAccountID = cardSettings?.paymentBankAccountID ?? '';

const selectedBankAccount = useMemo(() => bankAccountList?.[paymentBankAccountID], [paymentBankAccountID, bankAccountList]);
Expand Down
26 changes: 13 additions & 13 deletions src/pages/workspace/expensifyCard/WorkspaceCardListHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import {useRoute} from '@react-navigation/native';
import type {RouteProp} from '@react-navigation/native';
import React from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import type {FullScreenNavigatorParamList} from '@navigation/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import WorkspaceCardsListLabel from './WorkspaceCardsListLabel';

// TODO: remove when Onyx data is available
const mockedSettings = {
currentBalance: 5000,
remainingLimit: 3000,
cashBack: 2000,
};

function WorkspaceCardListHeader() {
const {shouldUseNarrowLayout, isMediumScreenWidth, isSmallScreenWidth} = useResponsiveLayout();
const styles = useThemeStyles();
const {translate} = useLocalize();
const route = useRoute<RouteProp<FullScreenNavigatorParamList, typeof SCREENS.WORKSPACE.EXPENSIFY_CARD>>();
VickyStash marked this conversation as resolved.
Show resolved Hide resolved

const policyID = route.params.policyID;
const isLessThanMediumScreen = isMediumScreenWidth || isSmallScreenWidth;

// TODO: uncomment the code line below to use cardSettings data from Onyx when it's supported
// const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`);
const cardSettings = mockedSettings;
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policy?.workspaceAccountID}`);

return (
<View style={styles.appBG}>
<View style={[isLessThanMediumScreen ? styles.flexColumn : styles.flexRow, isLessThanMediumScreen ? [styles.mt5, styles.mb3] : styles.mv5, styles.mh5, styles.ph4]}>
<View style={[styles.flexRow, styles.flex1, isLessThanMediumScreen && styles.mb5]}>
<WorkspaceCardsListLabel
type={CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.CURRENT_BALANCE}
value={cardSettings?.[CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.CURRENT_BALANCE]}
value={cardSettings?.[CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.CURRENT_BALANCE] ?? 0}
/>
<WorkspaceCardsListLabel
type={CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.REMAINING_LIMIT}
value={cardSettings?.[CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.REMAINING_LIMIT]}
value={cardSettings?.[CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.REMAINING_LIMIT] ?? 0}
/>
</View>
<WorkspaceCardsListLabel
type={CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.CASH_BACK}
value={cardSettings?.[CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.CASH_BACK]}
value={cardSettings?.[CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.CASH_BACK] ?? 0}
/>
</View>

Expand Down
6 changes: 3 additions & 3 deletions src/pages/workspace/expensifyCard/WorkspaceCardListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type WorkspacesListRowProps = {
name: string;

/** Cardholder personal details */
cardholder: PersonalDetails;
cardholder?: PersonalDetails | null;

/** Card limit */
limit: number;
Expand All @@ -38,8 +38,8 @@ function WorkspaceCardListRow({limit, cardholder, lastFourPAN, name, currency}:
<View style={[styles.flexRow, styles.gap5, styles.br3, styles.p4]}>
<View style={[styles.flexRow, styles.flex5, styles.gap3, styles.alignItemsCenter]}>
<Avatar
source={getDefaultAvatarURL(cardholder.accountID)}
avatarID={cardholder.accountID}
source={getDefaultAvatarURL(cardholder?.accountID)}
avatarID={cardholder?.accountID}
type={CONST.ICON_TYPE_AVATAR}
size={CONST.AVATAR_SIZE.DEFAULT}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function WorkspaceCardSettingsPage({route}: WorkspaceCardSettingsPageProps) {
const policyID = route.params?.policyID;

const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policyID}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [cardSettings] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_EXPENSIFY_CARD_SETTINGS}${policy?.workspaceAccountID}`);

const paymentBankAccountID = cardSettings?.paymentBankAccountID ?? '';
// const isMonthlySettlementAllowed = cardSettings?.isMonthlySettlementAllowed ?? true;
Expand Down
Loading
Loading