SALEOR-1903 - Fix custom currency formatting (#1067)
* Fix custom money formatting * Update changelog * Fix adding channels to shipping rates Co-authored-by: Magdalena Markusik <magdalena.markusik@mirumee.com>
This commit is contained in:
parent
4013105844
commit
795f9ccc4b
4 changed files with 17 additions and 17 deletions
|
@ -35,6 +35,7 @@ All notable, unreleased changes to this project will be documented in this file.
|
|||
- Display Cloud limits - #1004 by @dominik-zeglen
|
||||
- Add shipping method description - #1058 by @jwm0
|
||||
- Fix voucher and sales sorting errors - #1063 by @orzechdev
|
||||
- Fix custom currency formatting - #1067 by @orzechdev
|
||||
|
||||
# 2.11.1
|
||||
|
||||
|
|
|
@ -10,15 +10,22 @@ export interface MoneyProps {
|
|||
money: IMoney | null;
|
||||
}
|
||||
|
||||
export const formatMoney = (money: IMoney, locale: string) => {
|
||||
try {
|
||||
const formattedMoney = money.amount.toLocaleString(locale, {
|
||||
currency: money.currency,
|
||||
style: "currency"
|
||||
});
|
||||
return formattedMoney;
|
||||
} catch (error) {
|
||||
return `${money.amount} ${money.currency}`;
|
||||
}
|
||||
};
|
||||
|
||||
export const Money: React.FC<MoneyProps> = ({ money }) =>
|
||||
money ? (
|
||||
<LocaleConsumer>
|
||||
{({ locale }) =>
|
||||
money.amount.toLocaleString(locale, {
|
||||
currency: money.currency,
|
||||
style: "currency"
|
||||
})
|
||||
}
|
||||
{({ locale }) => formatMoney(money, locale)}
|
||||
</LocaleConsumer>
|
||||
) : (
|
||||
<>-</>
|
||||
|
|
|
@ -2,19 +2,13 @@ import React from "react";
|
|||
import { useIntl } from "react-intl";
|
||||
|
||||
import { LocaleConsumer } from "../Locale";
|
||||
import { IMoney } from "../Money";
|
||||
import { formatMoney, IMoney } from "../Money";
|
||||
|
||||
export interface MoneyRangeProps {
|
||||
from?: IMoney;
|
||||
to?: IMoney;
|
||||
}
|
||||
|
||||
const formatMoney = (money: IMoney, locale: string) =>
|
||||
money.amount.toLocaleString(locale, {
|
||||
currency: money.currency,
|
||||
style: "currency"
|
||||
});
|
||||
|
||||
export const MoneyRange: React.FC<MoneyRangeProps> = ({ from, to }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
ShippingPostalCodeRulesCreateInputRange
|
||||
} from "@saleor/types/globalTypes";
|
||||
import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc";
|
||||
import { diff } from "fast-array-diff";
|
||||
import { differenceBy } from "lodash";
|
||||
import { useIntl } from "react-intl";
|
||||
|
||||
import {
|
||||
|
@ -178,9 +178,7 @@ export function getShippingMethodChannelVariables(
|
|||
prevChannels?: ChannelShippingData[]
|
||||
): ShippingMethodChannelListingUpdateVariables {
|
||||
const removeChannels = prevChannels
|
||||
? diff(prevChannels, formChannels, (a, b) => a.id === b.id).removed?.map(
|
||||
removedChannel => removedChannel.id
|
||||
)
|
||||
? differenceBy(prevChannels, formChannels, "id").map(({ id }) => id)
|
||||
: [];
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue