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

X2-8166: Correct Currency not Appearing when Viewing the Customer's Reservation in the Purchases Tab #292

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading