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] Feat/44307 card system messages #46281

Merged
merged 12 commits into from
Jul 29, 2024
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,9 @@ const CONST = {
ACTIONABLE_TRACK_EXPENSE_WHISPER: 'ACTIONABLETRACKEXPENSEWHISPER',
ADD_COMMENT: 'ADDCOMMENT',
APPROVED: 'APPROVED',
CARD_MISSING_ADDRESS: 'CARDMISSINGADDRESS',
CARD_ISSUED: 'CARDISSUED',
CARD_ISSUED_VIRTUAL: 'CARDISSUEDVIRTUAL',
CHANGE_FIELD: 'CHANGEFIELD', // OldDot Action
CHANGE_POLICY: 'CHANGEPOLICY', // OldDot Action
CHANGE_TYPE: 'CHANGETYPE', // OldDot Action
Expand Down
66 changes: 66 additions & 0 deletions src/components/ReportActionItem/IssueCardMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import Button from '@components/Button';
import RenderHTML from '@components/RenderHTML';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {ReportAction} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type IssueCardMessageProps = {
action: OnyxEntry<ReportAction>;
};

function IssueCardMessage({action}: IssueCardMessageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {environmentURL} = useEnvironment();
mountiny marked this conversation as resolved.
Show resolved Hide resolved
// TODO: now mocking accountID with current user accountID instead of action.message.assigneeAccountID
const personalData = useCurrentUserPersonalDetails();
const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS);

// TODO: now mocking accountID with current user accountID instead of action.message.assigneeAccountID
const assignee = `<mention-user accountID=${personalData.accountID}></mention-user>`;
const link = `<a href='${environmentURL}/${ROUTES.SETTINGS_WALLET}'>${translate('cardPage.expensifyCard')}</a>`;
mountiny marked this conversation as resolved.
Show resolved Hide resolved

const noMailingAddress = action?.actionName === CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS && isEmptyObject(privatePersonalDetails?.address);

const getTranslation = () => {
switch (action?.actionName) {
case CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED:
return translate('workspace.expensifyCard.issuedCard', assignee);
case CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL:
return translate('workspace.expensifyCard.issuedCardVirtual', {assignee, link});
case CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS:
return translate(`workspace.expensifyCard.${noMailingAddress ? 'issuedCardNoMailingAddress' : 'addedAddress'}`, assignee);
Comment on lines +41 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug

Wrong system message for CARD_MISSING_ADDRESS it says the card will be delivered in few days instead of missing address message c.c @koko57

Screen.Recording.2024-07-29.at.4.25.24.PM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because you have your address added - if you wouldn't have it a proper message with button to add an address would be displayed. After you add the address it is displayed like this - that's why I added two additional cases to test regardless you have it added or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try to log into a new account that doesn't have address added to test it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me give it a try

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This occurs with new accounts as well:

Screen.Recording.2024-07-29.at.4.32.02.PM.mov

IMO noMailingAddress is always returning false here. can you please take a look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allgandalf fixed! I forgot that I changed action?.originalMessage.html for action?.actionName (the proper condition). I added an extra check that will be removed later

default:
return '';
}
};

return (
<>
<RenderHTML html={`<muted-text>${getTranslation()}</muted-text>`} />
{noMailingAddress && (
<Button
onPress={() => Navigation.navigate(ROUTES.SETTINGS_ADDRESS)}
success
medium
style={[styles.alignSelfStart, styles.mt3]}
text={translate('workspace.expensifyCard.addMailingAddress')}
/>
)}
</>
);
}

IssueCardMessage.displayName = 'IssueCardMessage';

export default IssueCardMessage;
6 changes: 6 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type {
GoBackMessageParams,
GoToRoomParams,
InstantSummaryParams,
IssueVirtualCardParams,
LocalTimeParams,
LoggedInAsParams,
LogSizeParams,
Expand Down Expand Up @@ -2707,6 +2708,11 @@ export default {
`If you change this card's limit type to Smart Limit, new transactions will be declined because the ${limit} unapproved limit has already been reached.`,
changeCardMonthlyLimitTypeWarning: (limit: string) =>
`If you change this card's limit type to Monthly, new transactions will be declined because the ${limit} monthly limit has already been reached.`,
addMailingAddress: 'Add mailing address',
issuedCard: (assignee: string) => `issued ${assignee} an Expensify Card! The card will arrive in 2-3 business days.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that in design doc, we mentioned the name of the admin as well, was it left out on purpose?

Screenshot 2024-07-29 at 3 18 29 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd :) If we are matching with the figma mocks, I'm okay with the current state, thanks for mentioning

issuedCardNoMailingAddress: (assignee: string) => `issued ${assignee} an Expensify Card! The card will be shipped once a mailing address is added.`,

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i ready the convo #44307 (comment), I'll mark this as resolved

issuedCardVirtual: ({assignee, link}: IssueVirtualCardParams) => `issued ${assignee} a virtual ${link}! The card can be used right away.`,

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i ready the convo #44307 (comment), I'll mark this as resolved

addedAddress: (assignee: string) => `${assignee} added the address. Expensify Card will arrive in 2-3 business days.`,

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i ready the convo #44307 (comment), I'll mark this as resolved

},
categories: {
deleteCategories: 'Delete categories',
Expand Down
6 changes: 6 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
GoBackMessageParams,
GoToRoomParams,
InstantSummaryParams,
IssueVirtualCardParams,
LocalTimeParams,
LoggedInAsParams,
LogSizeParams,
Expand Down Expand Up @@ -2759,6 +2760,11 @@ export default {
`Si cambias el tipo de límite de esta tarjeta a Límite inteligente, las nuevas transacciones serán rechazadas porque ya se ha alcanzado el límite de ${limit} no aprobado.`,
changeCardMonthlyLimitTypeWarning: (limit: string) =>
`Si cambias el tipo de límite de esta tarjeta a Mensual, las nuevas transacciones serán rechazadas porque ya se ha alcanzado el límite de ${limit} mensual.`,
addMailingAddress: 'Añadir dirección de postal',
issuedCard: (assignee: string) => `¡emitió a ${assignee} una Tarjeta Expensify! La tarjeta llegará en 2-3 días laborables.`,
issuedCardNoMailingAddress: (assignee: string) => `¡emitió a ${assignee} una Tarjeta Expensify! La tarjeta se enviará una vez que se añada una dirección postal.`,
issuedCardVirtual: ({assignee, link}: IssueVirtualCardParams) => `¡emitió a ${assignee} una ${link} virtual! La tarjeta puede utilizarse inmediatamente.`,
addedAddress: (assignee: string) => `${assignee} ha añadido la dirección. Tarjeta Expensify llegará en 2-3 días hábiles.`,
},
categories: {
deleteCategories: 'Eliminar categorías',
Expand Down
6 changes: 6 additions & 0 deletions src/languages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ type DeleteExpenseTranslationParams = {
count: number;
};

type IssueVirtualCardParams = {
assignee: string;
link: string;
};

export type {
AddressLineParams,
AdminCanceledRequestParams,
Expand Down Expand Up @@ -376,6 +381,7 @@ export type {
GoToRoomParams,
HeldRequestParams,
InstantSummaryParams,
IssueVirtualCardParams,
LocalTimeParams,
LogSizeParams,
LoggedInAsParams,
Expand Down
5 changes: 5 additions & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {ActionableItem} from '@components/ReportActionItem/ActionableItemBu
import ActionableItemButtons from '@components/ReportActionItem/ActionableItemButtons';
import ChronosOOOListActions from '@components/ReportActionItem/ChronosOOOListActions';
import ExportIntegration from '@components/ReportActionItem/ExportIntegration';
import IssueCardMessage from '@components/ReportActionItem/IssueCardMessage';
import MoneyRequestAction from '@components/ReportActionItem/MoneyRequestAction';
import RenameAction from '@components/ReportActionItem/RenameAction';
import ReportPreview from '@components/ReportActionItem/ReportPreview';
Expand Down Expand Up @@ -653,6 +654,10 @@ function ReportActionItem({
children = <ReportActionItemBasicMessage message={ReportActionsUtils.getDismissedViolationMessageText(ReportActionsUtils.getOriginalMessage(action))} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_TAG) {
children = <ReportActionItemBasicMessage message={PolicyUtils.getCleanedTagName(ReportActionsUtils.getReportActionMessage(action)?.text ?? '')} />;
} else if (
ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED, CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL, CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS)
) {
children = <IssueCardMessage action={action} />;
} else if (ReportActionsUtils.isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION)) {
children = <ExportIntegration action={action} />;
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,12 @@ type OriginalMessageMap = {
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_SETUP]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_SETUP_REQUESTED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS]: never;
/** */
[CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL]: never;
} & OldDotOriginalMessageMap & {
[T in ValueOf<typeof CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG>]: OriginalMessageChangeLog;
} & {
Expand Down
Loading