Skip to content

Commit

Permalink
Merge pull request #40083 from software-mansion-labs/@kosmydel/polish…
Browse files Browse the repository at this point in the history
…-taxes

[Taxes] Display tax rate value in the list
  • Loading branch information
neil-marcellini authored Apr 12, 2024
2 parents 9853832 + 4a4bc88 commit 91fa85d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4313,6 +4313,9 @@ const CONST = {
SESSION_STORAGE_KEYS: {
INITIAL_URL: 'INITIAL_URL',
},

DOT_SEPARATOR: '•',

DEFAULT_TAX: {
defaultExternalID: 'id_TAX_EXEMPT',
defaultValue: '0%',
Expand Down
2 changes: 1 addition & 1 deletion src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function MoneyRequestConfirmationList({
const formattedTaxAmount = CurrencyUtils.convertToDisplayString(transaction?.taxAmount, iouCurrencyCode);

const defaultTaxKey = taxRates?.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) ${translate('common.default')}`) ?? '';
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) ${CONST.DOT_SEPARATOR} ${translate('common.default')}`) ?? '';
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- nullish coalescing is not working when a left hand side value is ''
const taxRateTitle = transaction?.taxRate?.text || defaultTaxName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ function MoneyRequestPreviewContent({
if (isCardTransaction) {
message = translate('iou.card');
if (TransactionUtils.isPending(transaction)) {
message += ` ${translate('iou.pending')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('iou.pending')}`;
return message;
}
}

if (isSettled && !iouReport?.isCancelledIOU && !isPartialHold) {
message += ` ${getSettledMessage()}`;
message += ` ${CONST.DOT_SEPARATOR} ${getSettledMessage()}`;
return message;
}

Expand All @@ -164,28 +164,28 @@ function MoneyRequestPreviewContent({
const isTooLong = violationsCount > 1 || violationMessage.length > 15;
const hasViolationsAndFieldErrors = violationsCount > 0 && hasFieldErrors;

return `${message} ${isTooLong || hasViolationsAndFieldErrors ? translate('violations.reviewRequired') : violationMessage}`;
return `${message} ${CONST.DOT_SEPARATOR} ${isTooLong || hasViolationsAndFieldErrors ? translate('violations.reviewRequired') : violationMessage}`;
}

const isMerchantMissing = TransactionUtils.isMerchantMissing(transaction);
const isAmountMissing = TransactionUtils.isAmountMissing(transaction);
if (isAmountMissing && isMerchantMissing) {
message += ` ${translate('violations.reviewRequired')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('violations.reviewRequired')}`;
} else if (isAmountMissing) {
message += ` ${translate('iou.missingAmount')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('iou.missingAmount')}`;
} else if (isMerchantMissing) {
message += ` ${translate('iou.missingMerchant')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('iou.missingMerchant')}`;
} else if (!(isSettled && !isSettlementOrApprovalPartial) && isOnHold) {
message += ` ${translate('iou.hold')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('iou.hold')}`;
}
} else if (ReportUtils.isPaidGroupPolicyExpenseReport(iouReport) && ReportUtils.isReportApproved(iouReport) && !ReportUtils.isSettled(iouReport?.reportID) && !isPartialHold) {
message += ` ${translate('iou.approved')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('iou.approved')}`;
} else if (iouReport?.isWaitingOnBankAccount) {
message += ` ${translate('iou.pending')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('iou.pending')}`;
} else if (iouReport?.isCancelledIOU) {
message += ` ${translate('iou.canceled')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('iou.canceled')}`;
} else if (!(isSettled && !isSettlementOrApprovalPartial) && isOnHold) {
message += ` ${translate('iou.hold')}`;
message += ` ${CONST.DOT_SEPARATOR} ${translate('iou.hold')}`;
}
return message;
};
Expand Down
16 changes: 8 additions & 8 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,26 @@ function MoneyRequestView({

if (isCardTransaction) {
if (formattedOriginalAmount) {
amountDescription += ` ${translate('iou.original')} ${formattedOriginalAmount}`;
amountDescription += ` ${CONST.DOT_SEPARATOR} ${translate('iou.original')} ${formattedOriginalAmount}`;
}
if (TransactionUtils.isPending(transaction)) {
amountDescription += ` ${translate('iou.pending')}`;
amountDescription += ` ${CONST.DOT_SEPARATOR} ${translate('iou.pending')}`;
}
if (isCancelled) {
amountDescription += ` ${translate('iou.canceled')}`;
amountDescription += ` ${CONST.DOT_SEPARATOR} ${translate('iou.canceled')}`;
}
} else {
if (!isDistanceRequest) {
amountDescription += ` ${translate('iou.cash')}`;
amountDescription += ` ${CONST.DOT_SEPARATOR} ${translate('iou.cash')}`;
}
if (isApproved) {
amountDescription += ` ${translate('iou.approved')}`;
amountDescription += ` ${CONST.DOT_SEPARATOR} ${translate('iou.approved')}`;
} else if (isCancelled) {
amountDescription += ` ${translate('iou.canceled')}`;
amountDescription += ` ${CONST.DOT_SEPARATOR} ${translate('iou.canceled')}`;
} else if (isSettled) {
amountDescription += ` ${translate('iou.settledExpensify')}`;
amountDescription += ` ${CONST.DOT_SEPARATOR} ${translate('iou.settledExpensify')}`;
} else if (report.isWaitingOnBankAccount) {
amountDescription += ` ${translate('iou.pending')}`;
amountDescription += ` ${CONST.DOT_SEPARATOR} ${translate('iou.pending')}`;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,8 @@ function getReportFieldOptionsSection(options: string[], recentlyUsedOptions: st
*/
function transformedTaxRates(taxRates: TaxRatesWithDefault | undefined): Record<string, TaxRate> {
const defaultTaxKey = taxRates?.defaultExternalID;
const getModifiedName = (data: TaxRate, code: string) => `${data.name} (${data.value})${defaultTaxKey === code ? ` • ${Localize.translateLocal('common.default')}` : ''}`;
const getModifiedName = (data: TaxRate, code: string) =>
`${data.name} (${data.value})${defaultTaxKey === code ? ` ${CONST.DOT_SEPARATOR} ${Localize.translateLocal('common.default')}` : ''}`;
const taxes = Object.fromEntries(Object.entries(taxRates?.taxes ?? {}).map(([code, data]) => [code, {...data, code, modifiedName: getModifiedName(data, code), name: data.name}]));
return taxes;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ function getMoneyRequestReportName(report: OnyxEntry<Report>, policy: OnyxEntry<
}

if (report?.isWaitingOnBankAccount) {
return `${payerPaidAmountMessage} ${Localize.translateLocal('iou.pending')}`;
return `${payerPaidAmountMessage} ${CONST.DOT_SEPARATOR} ${Localize.translateLocal('iou.pending')}`;
}

if (!isSettled(report?.reportID) && hasNonReimbursableTransactions(report?.reportID)) {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ function getEnabledTaxRateCount(options: TaxRates) {
*/
function getDefaultTaxName(taxRates: TaxRatesWithDefault, transaction?: Transaction) {
const defaultTaxKey = taxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey]?.name} (${taxRates.taxes[defaultTaxKey]?.value}) • ${Localize.translateLocal('common.default')}`) || '';
const defaultTaxName =
(defaultTaxKey && `${taxRates.taxes[defaultTaxKey]?.name} (${taxRates.taxes[defaultTaxKey]?.value}) ${CONST.DOT_SEPARATOR} ${Localize.translateLocal('common.default')}`) || '';
return transaction?.taxRate?.text ?? defaultTaxName;
}

Expand Down
21 changes: 12 additions & 9 deletions src/pages/workspace/taxes/WorkspaceTaxesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPol
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {TaxRate} from '@src/types/onyx';

type WorkspaceTaxesPageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps<WorkspacesCentralPaneNavigatorParamList, typeof SCREENS.WORKSPACE.TAXES>;

Expand Down Expand Up @@ -67,17 +68,19 @@ function WorkspaceTaxesPage({
);

const textForDefault = useCallback(
(taxID: string): string => {
(taxID: string, taxRate: TaxRate): string => {
let suffix;
if (taxID === defaultExternalID && taxID === foreignTaxDefault) {
return translate('common.default');
suffix = translate('common.default');
} else if (taxID === defaultExternalID) {
suffix = translate('workspace.taxes.workspaceDefault');
} else if (taxID === foreignTaxDefault) {
suffix = translate('workspace.taxes.foreignDefault');
}
if (taxID === defaultExternalID) {
return translate('workspace.taxes.workspaceDefault');
if (suffix) {
return `${taxRate.value} ${CONST.DOT_SEPARATOR} ${suffix}`;
}
if (taxID === foreignTaxDefault) {
return translate('workspace.taxes.foreignDefault');
}
return '';
return `${taxRate.value}`;
},
[defaultExternalID, foreignTaxDefault, translate],
);
Expand All @@ -89,7 +92,7 @@ function WorkspaceTaxesPage({
return Object.entries(policy.taxRates?.taxes ?? {})
.map(([key, value]) => ({
text: value.name,
alternateText: textForDefault(key),
alternateText: textForDefault(key, value),
keyForList: key,
isSelected: !!selectedTaxesIDs.includes(key),
isDisabledCheckbox: !PolicyUtils.canEditTaxRate(policy, key),
Expand Down

0 comments on commit 91fa85d

Please sign in to comment.