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
|
- Display Cloud limits - #1004 by @dominik-zeglen
|
||||||
- Add shipping method description - #1058 by @jwm0
|
- Add shipping method description - #1058 by @jwm0
|
||||||
- Fix voucher and sales sorting errors - #1063 by @orzechdev
|
- Fix voucher and sales sorting errors - #1063 by @orzechdev
|
||||||
|
- Fix custom currency formatting - #1067 by @orzechdev
|
||||||
|
|
||||||
# 2.11.1
|
# 2.11.1
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,22 @@ export interface MoneyProps {
|
||||||
money: IMoney | null;
|
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 }) =>
|
export const Money: React.FC<MoneyProps> = ({ money }) =>
|
||||||
money ? (
|
money ? (
|
||||||
<LocaleConsumer>
|
<LocaleConsumer>
|
||||||
{({ locale }) =>
|
{({ locale }) => formatMoney(money, locale)}
|
||||||
money.amount.toLocaleString(locale, {
|
|
||||||
currency: money.currency,
|
|
||||||
style: "currency"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</LocaleConsumer>
|
</LocaleConsumer>
|
||||||
) : (
|
) : (
|
||||||
<>-</>
|
<>-</>
|
||||||
|
|
|
@ -2,19 +2,13 @@ import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { LocaleConsumer } from "../Locale";
|
import { LocaleConsumer } from "../Locale";
|
||||||
import { IMoney } from "../Money";
|
import { formatMoney, IMoney } from "../Money";
|
||||||
|
|
||||||
export interface MoneyRangeProps {
|
export interface MoneyRangeProps {
|
||||||
from?: IMoney;
|
from?: IMoney;
|
||||||
to?: 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 }) => {
|
export const MoneyRange: React.FC<MoneyRangeProps> = ({ from, to }) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
ShippingPostalCodeRulesCreateInputRange
|
ShippingPostalCodeRulesCreateInputRange
|
||||||
} from "@saleor/types/globalTypes";
|
} from "@saleor/types/globalTypes";
|
||||||
import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc";
|
import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc";
|
||||||
import { diff } from "fast-array-diff";
|
import { differenceBy } from "lodash";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -178,9 +178,7 @@ export function getShippingMethodChannelVariables(
|
||||||
prevChannels?: ChannelShippingData[]
|
prevChannels?: ChannelShippingData[]
|
||||||
): ShippingMethodChannelListingUpdateVariables {
|
): ShippingMethodChannelListingUpdateVariables {
|
||||||
const removeChannels = prevChannels
|
const removeChannels = prevChannels
|
||||||
? diff(prevChannels, formChannels, (a, b) => a.id === b.id).removed?.map(
|
? differenceBy(prevChannels, formChannels, "id").map(({ id }) => id)
|
||||||
removedChannel => removedChannel.id
|
|
||||||
)
|
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue