Skip to content

Commit

Permalink
X2-8166 Correct Currency not Appearing when Viewing the Customer's Re…
Browse files Browse the repository at this point in the history
…servation in the Purchases Tab (#296)

* Fix for CAD with Canadian locale

* Add locale prop to Breakdown component

* Fix currency display issue in BreakdownItem component

---------

Co-authored-by: Oleksandr Khomyakov <[email protected]>
  • Loading branch information
khomyakov and khomyakov authored Dec 22, 2023
1 parent 9fac181 commit c999830
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/components/Breakdown.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import clsx from "clsx";
import PropTypes from "prop-types";
import React, { createContext, useContext } from "react";
import React, { createContext, useContext, useMemo } from "react";
import { isNumber } from "lodash";
import { Currency } from "./Utilities/Currency";

Expand All @@ -17,9 +17,10 @@ const colors = {

const CurrencyContext = createContext();

export const Breakdown = ({ children, className, currency, ...rest }) => {
export const Breakdown = ({ children, className, currency, locale, ...rest }) => {
const value = useMemo(() => ({ currency, locale }), [currency, locale]);
return (
<CurrencyContext.Provider value={currency}>
<CurrencyContext.Provider value={value}>
<table className={clsx("ui-breakdown", "w-full", className)} {...rest}>
<tbody>{children}</tbody>
</table>
Expand All @@ -31,10 +32,11 @@ Breakdown.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
currency: PropTypes.string.isRequired,
locale: PropTypes.string,
};

const BreakdownItem = ({ children, info, methodIcon, secondary, value, className, color = "default", ...rest }) => {
const currency = useContext(CurrencyContext);
const { currency, locale } = useContext(CurrencyContext);

return (
<tr className={clsx("ui-breakdown-item", colors[color], className)} {...rest}>
Expand All @@ -51,7 +53,7 @@ const BreakdownItem = ({ children, info, methodIcon, secondary, value, className

<td className="w-[1%] whitespace-nowrap pl-4 text-right">
{isNumber(value) ? (
<Currency shouldRemoveTrailingZeroes={false} currency={currency}>
<Currency shouldRemoveTrailingZeroes={false} currency={currency} locale={locale}>
{value}
</Currency>
) : (
Expand All @@ -76,15 +78,15 @@ Breakdown.Item = BreakdownItem;
Breakdown.Item.displayName = "Breakdown.Item";

const BreakdownSubtotalItem = ({ children, info, value, className, color = "black", ...rest }) => {
const currency = useContext(CurrencyContext);
const { currency, locale } = useContext(CurrencyContext);

return (
<tr className={clsx("ui-breakdown-subtotal-item", "font-bold", colors[color], className)} {...rest}>
<td className="pt-1 pb-4 text-left">{children}</td>
<td className="whitespace-nowrap pt-1 pb-4 text-right">{info}</td>

<td className="w-[1%] whitespace-nowrap pt-1 pb-4 pl-4 text-right">
<Currency shouldRemoveTrailingZeroes={false} currency={currency}>
<Currency shouldRemoveTrailingZeroes={false} currency={currency} locale={locale}>
{value}
</Currency>
</td>
Expand Down
1 change: 1 addition & 0 deletions src/helpers/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const numberFormat = (
const style = currency ? "currency" : "decimal";

const params = { style, minimumFractionDigits: maximumFractionDigits, maximumFractionDigits };

if (currency) {
params.currency = currency;
params.currencyDisplay = isNarrowSymbolForm ? "narrowSymbol" : "symbol";
Expand Down
2 changes: 1 addition & 1 deletion src/stories/DataDisplay/Currency.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CurrencyStories = {
description: "A locale string",
type: { required: true },
control: { type: "select" },
options: ["en-IN", "en-US", "fr-FR", "ja-JP", "de-DE", "ar-AE"],
options: ["en-IN", "en-US", "fr-FR", "ja-JP", "de-DE", "ar-AE", "en-CA", "fr-CA"],
table: {
type: { summary: null },
defaultValue: { summary: "Auto-detected based on browser settings" },
Expand Down

0 comments on commit c999830

Please sign in to comment.