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:
Dawid Tarasiuk 2021-04-21 11:03:57 +02:00 committed by GitHub
parent 4013105844
commit 795f9ccc4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 17 deletions

View file

@ -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

View file

@ -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>
) : (
<>-</>

View file

@ -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();

View file

@ -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 {