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: delete money request if failed to create chat #44142

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dcc9ac9
fix: delete money request if failed to create chat
dominictb Jun 21, 2024
ed0b37e
fix: add function to swap err message for local translation
dominictb Jun 21, 2024
caae66e
Merge remote-tracking branch 'origin/main' into fix/42950-clean-dist-…
dominictb Jun 22, 2024
7936055
fix: lint and prettier
dominictb Jun 22, 2024
68c4ca7
fix: check optimistic report before cleaning up money request
dominictb Jun 24, 2024
083c790
chore: add translation
dominictb Jun 24, 2024
5951c38
fix: lint
dominictb Jun 24, 2024
7a9c89b
Merge remote-tracking branch 'origin/main' into fix/42950-clean-dist-…
dominictb Jun 26, 2024
b383383
fix: improve translation key swapping logic
dominictb Jun 26, 2024
65bd81d
fix: comment
dominictb Jun 28, 2024
9b67b44
Merge remote-tracking branch 'origin/main' into fix/42950-clean-dist-…
dominictb Jul 4, 2024
041bed4
fix: set errors and IOUTransactionID to null
dominictb Jul 4, 2024
41768f4
fix: typescript issue
dominictb Jul 4, 2024
bd32dd9
Merge remote-tracking branch 'origin/main' into fix/42950-clean-dist-…
dominictb Jul 9, 2024
0590632
fix: resolve typescript issues
dominictb Jul 10, 2024
21eafea
fix: prettier
dominictb Jul 10, 2024
3730797
fix: update comments and clean up implementation
dominictb Jul 12, 2024
83c0c3f
Merge remote-tracking branch 'origin/main' into fix/42950-clean-dist-…
dominictb Jul 12, 2024
51b8106
Merge remote-tracking branch 'origin/main' into fix/42950-clean-dist-…
dominictb Jul 16, 2024
4b79f38
fix: revert "swapForTranslation" change
dominictb Jul 16, 2024
313b1ca
Merge remote-tracking branch 'origin/main' into fix/42950-clean-dist-…
dominictb Jul 17, 2024
6ea8fc6
Remove en translation messsage
dominictb Jul 17, 2024
d71f595
Remove es translation message
dominictb Jul 17, 2024
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
8 changes: 7 additions & 1 deletion src/components/LocaleContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type LocaleContextProps = {
/** Returns translated string for given locale and phrase */
translate: <TKey extends TranslationPaths>(phraseKey: TKey, ...phraseParameters: Localize.PhraseParameters<Localize.Phrase<TKey>>) => string;

swapForTranslation: (message: string) => string;

/** Formats number formatted according to locale and options */
numberFormat: (number: number, options?: Intl.NumberFormatOptions) => string;

Expand Down Expand Up @@ -69,6 +71,7 @@ const LocaleContext = createContext<LocaleContextProps>({
toLocaleDigit: () => '',
toLocaleOrdinal: () => '',
fromLocaleDigit: () => '',
swapForTranslation: () => '',
preferredLocale: CONST.LOCALES.DEFAULT,
});

Expand Down Expand Up @@ -105,9 +108,12 @@ function LocaleContextProvider({preferredLocale, currentUserPersonalDetails, chi

const fromLocaleDigit = useMemo<LocaleContextProps['fromLocaleDigit']>(() => (localeDigit) => LocaleDigitUtils.fromLocaleDigit(locale, localeDigit), [locale]);

const swapForTranslation = useMemo<LocaleContextProps['swapForTranslation']>(() => (message) => Localize.swapForTranslation(locale, message), [locale]);

const contextValue = useMemo<LocaleContextProps>(
() => ({
translate,
swapForTranslation,
numberFormat,
datetimeToRelative,
datetimeToCalendarTime,
Expand All @@ -118,7 +124,7 @@ function LocaleContextProvider({preferredLocale, currentUserPersonalDetails, chi
fromLocaleDigit,
preferredLocale: locale,
}),
[translate, numberFormat, datetimeToRelative, datetimeToCalendarTime, updateLocale, formatPhoneNumber, toLocaleDigit, toLocaleOrdinal, fromLocaleDigit, locale],
[translate, swapForTranslation, numberFormat, datetimeToRelative, datetimeToCalendarTime, updateLocale, formatPhoneNumber, toLocaleDigit, toLocaleOrdinal, fromLocaleDigit, locale],
);

return <LocaleContext.Provider value={contextValue}>{children}</LocaleContext.Provider>;
Expand Down
25 changes: 20 additions & 5 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function MoneyRequestView({
const styles = useThemeStyles();
const session = useSession();
const {isOffline} = useNetwork();
const {translate, toLocaleDigit} = useLocalize();
const {translate, toLocaleDigit, swapForTranslation} = useLocalize();
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);

const parentReportAction = parentReportActions?.[report.parentReportActionID ?? '-1'];
Expand Down Expand Up @@ -349,10 +349,18 @@ function MoneyRequestView({
const shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report);
const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt);

const errors = {
...(transaction?.errorFields?.route ?? transaction?.errors),
...parentReportAction?.errors,
};
const errors = useMemo(() => {
const combinedErrors = {
...(transaction?.errorFields?.route ?? transaction?.errors),
...parentReportAction?.errors,
};
return Object.fromEntries(
Object.entries(combinedErrors).map(([key, value]) =>
// swap for translation for each error message
[key, swapForTranslation(value as string)],
),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is kind of a new pattern, so I want to check with the team first to see if everyone is cool with it, as recommended by our checklist.

I don't really like that we're doing the swapping within the component. Ideally the swapping would be done when saving an Onyx update from the network or pusher. Let's pause this work until we hear what the team thinks. Sorry for the delay, but if we build this right it will be useful in the future instead of a headache.

Copy link
Contributor

Choose a reason for hiding this comment

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

The approval conversation is here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, do you mean we should pause this PR or I should revert all the swapForTranslation change in this PR (in case the team is indecisive for a long time)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally the swapping would be done when saving an Onyx update from the network or pusher

It's not easy to do that since usually the error message returned from the BE is in the BE onyxData, which we don't have much control.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dominictb yeah, please revert the swapForTranslation changes. I think we'll just deal with the slightly strange non-translated error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@neil-marcellini reverted

}, [transaction?.errorFields?.route, transaction?.errors, parentReportAction?.errors, swapForTranslation]);

const tagList = policyTagLists.map(({name, orderWeight}, index) => {
const tagError = getErrorForField(
Expand Down Expand Up @@ -404,6 +412,13 @@ function MoneyRequestView({
if (!transaction?.transactionID) {
return;
}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if ((!!report?.errorFields?.createChat || !!report.isOptimisticReport) && parentReportAction) {
dominictb marked this conversation as resolved.
Show resolved Hide resolved
const urlToNavigateBack = IOU.cleanUpMoneyRequest(transaction.transactionID, parentReportAction, true);
Navigation.goBack(urlToNavigateBack);
Comment on lines +416 to +417
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, this caused the following issue: #50022
Details can be found in this proposal: #50022 (comment)
PR: #51940

return;
}

if (
transaction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD &&
Object.values(transaction?.errors ?? {})?.find((error) => ErrorUtils.isReceiptError(error))
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ export default {
atLeastTwoDifferentWaypoints: 'Please enter at least two different addresses.',
splitExpenseMultipleParticipantsErrorMessage: 'An expense cannot be split between a workspace and other members. Please update your selection.',
invalidMerchant: 'Please enter a correct merchant.',
workspaceNotAccessible: 'The workspace you selected is no longer accessible, possibly because it has been deleted or you no longer have access to it.',
dominictb marked this conversation as resolved.
Show resolved Hide resolved
},
waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up. Payment is on hold until ${submitterDisplayName} enables their wallet.`,
enableWallet: 'Enable wallet',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ export default {
atLeastTwoDifferentWaypoints: 'Por favor, introduce al menos dos direcciones diferentes.',
splitExpenseMultipleParticipantsErrorMessage: 'Solo puedes dividir un gasto entre un único espacio de trabajo o con miembros individuales. Por favor, actualiza tu selección.',
invalidMerchant: 'Por favor, introduce un comerciante correcto.',
workspaceNotAccessible: 'El espacio de trabajo que seleccionaste ya no está accesible, posiblemente porque ha sido eliminado o ya no tienes acceso a él.',
dominictb marked this conversation as resolved.
Show resolved Hide resolved
},
waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inició el pago, pero no se procesará hasta que ${submitterDisplayName} active su billetera`,
enableWallet: 'Habilitar billetera',
Expand Down
8 changes: 8 additions & 0 deletions src/languages/msgTranslationKeySwapMapping.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we put these in CONST.ts instead, and use constants for the keys and values? I think we wouldn't have to eslint disable then and it would fit with our existing code patterns a little better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but I'll wait for the team to decide on the swapForTranslation pattern before fixing this

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const mapping: Record<string, string> = {
// eslint-disable-next-line @typescript-eslint/naming-convention
'The workspace is no longer accessible. Please try again on a different workspace.': 'iou.error.workspaceNotAccessible',
// eslint-disable-next-line @typescript-eslint/naming-convention
'Unexpected error submitting this expense. Please try again later.': 'iou.error.genericCreateFailureMessage',
};

export default mapping;
17 changes: 16 additions & 1 deletion src/libs/Localize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Log from '@libs/Log';
import type {MessageElementBase, MessageTextElement} from '@libs/MessageElement';
import Config from '@src/CONFIG';
import CONST from '@src/CONST';
import msgTranslationKeySwapMapping from '@src/languages/msgTranslationKeySwapMapping';
import translations from '@src/languages/translations';
import type {TranslationFlatObject, TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -225,5 +226,19 @@ function getDevicePreferredLocale(): Locale {
return RNLocalize.findBestAvailableLanguage([CONST.LOCALES.EN, CONST.LOCALES.ES])?.languageTag ?? CONST.LOCALES.DEFAULT;
}

export {translate, translateLocal, formatList, formatMessageElementList, getDevicePreferredLocale};
/**
* This function match the message in the translation mapping and return the translation.
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
* @param locale - The locale to translate the message to.
* @param message - The message to translate.
* @returns - translation of the message or the original message if no translation found
*/
function swapForTranslation(locale: Locale, message: string): string {
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
const translationKey: string | undefined = msgTranslationKeySwapMapping[message];
if (translationKey) {
return translate(locale, translationKey as TranslationPaths);
}
return message;
}

export {translate, translateLocal, formatList, formatMessageElementList, getDevicePreferredLocale, swapForTranslation};
export type {PhraseParameters, Phrase};
Loading
Loading