Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Improve code readability

dominik-zeglenc6e8d7198ad5
diff --git a/saleor/static/dashboard-next/components/Money/Money.tsx b/saleor/static/dashboard-next/components/Money/Money.tsx
index e0fc85313d..2cdde4af0c 100644
--- a/saleor/static/dashboard-next/components/Money/Money.tsx
+++ b/saleor/static/dashboard-next/components/Money/Money.tsx
@@ -1,36 +1,22 @@
-import Typography, { TypographyProps } from "@material-ui/core/Typography";
import * as React from "react";
import { LocaleConsumer } from "../Locale";
-export interface MoneyProp {
+export interface Money {
amount: number;
currency: string;
}
-interface MoneyProps {
- moneyDetalis: MoneyProp;
- typographyProps?: TypographyProps;
- inline?;
+export interface MoneyProps {
+ money: Money;
}
-export const Money: React.StatelessComponent<MoneyProps> = ({
- moneyDetalis,
- typographyProps,
- inline
-}) => (
+export const Money: React.StatelessComponent<MoneyProps> = ({ money }) => (
<LocaleConsumer>
{locale => {
- const money = moneyDetalis.amount.toLocaleString(locale, {
- currency: moneyDetalis.currency,
+ return money.amount.toLocaleString(locale, {
+ currency: money.currency,
style: "currency"
});
- if (typographyProps) {
- return <Typography {...typographyProps}>{money}</Typography>;
- }
- if (inline) {
- return <span>{money}</span>;
- }
- return <>{money}</>;
}}
</LocaleConsumer>
);
diff --git a/saleor/static/dashboard-next/components/Money/index.ts b/saleor/static/dashboard-next/components/Money/index.ts
index 3c9e8c2077..ace2118caa 100644
--- a/saleor/static/dashboard-next/components/Money/index.ts
+++ b/saleor/static/dashboard-next/components/Money/index.ts
@@ -1,3 +1,2 @@
export { default } from "./Money";
export * from "./Money";
-export { MoneyProp } from "./Money";
diff --git a/saleor/static/dashboard-next/components/Percent/Percent.tsx b/saleor/static/dashboard-next/components/Percent/Percent.tsx
index 2d269b3972..dc34ff8a96 100644
--- a/saleor/static/dashboard-next/components/Percent/Percent.tsx
+++ b/saleor/static/dashboard-next/components/Percent/Percent.tsx
@@ -1,27 +1,18 @@
-import Typography, { TypographyProps } from "@material-ui/core/Typography";
import * as React from "react";
import { LocaleConsumer } from "../Locale";
interface PercentProps {
amount: number;
- typographyProps?: TypographyProps;
}
-const Percent: React.StatelessComponent<PercentProps> = ({
- amount,
- typographyProps
-}) => (
+const Percent: React.StatelessComponent<PercentProps> = ({ amount }) => (
<LocaleConsumer>
{locale => {
- const formattedAmount = (amount / 100).toLocaleString(locale, {
+ return (amount / 100).toLocaleString(locale, {
maximumFractionDigits: 2,
style: "percent"
});
- if (typographyProps) {
- return <Typography {...typographyProps}>{formattedAmount}</Typography>;
- }
- return <>{formattedAmount}</>;
}}
</LocaleConsumer>
);
diff --git a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
index 0da792f223..116ca95323 100644
--- a/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
+++ b/saleor/static/dashboard-next/components/ProductList/ProductList.tsx
@@ -119,7 +119,7 @@ export const ProductList = decorate<ProductListProps>(
product.price &&
product.price.amount !== undefined &&
product.price.currency !== undefined ? (
- <Money moneyDetalis={product.price} />
+ <Money money={product.price} />
) : (
<Skeleton />
)}
diff --git a/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx b/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
index 1f15c37ae7..cdb7c35c73 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx
@@ -109,7 +109,7 @@ const CustomerOrders = decorate<CustomerOrdersProps>(
</TableCell>
<TableCell className={classes.textRight} padding="dense">
{maybe(() => order.total.gross) ? (
- <Money moneyDetalis={order.total.gross} />
+ <Money money={order.total.gross} />
) : (
<Skeleton />
)}
diff --git a/saleor/static/dashboard-next/home/components/HomePage/HomePage.tsx b/saleor/static/dashboard-next/home/components/HomePage/HomePage.tsx
index 2a5a94a4b9..66126c0a0c 100644
--- a/saleor/static/dashboard-next/home/components/HomePage/HomePage.tsx
+++ b/saleor/static/dashboard-next/home/components/HomePage/HomePage.tsx
@@ -7,7 +7,6 @@ import CardSpacer from "../../../components/CardSpacer";
import Container from "../../../components/Container";
import Money from "../../../components/Money";
import Skeleton from "../../../components/Skeleton";
-import { maybe } from "../../../misc";
import {
Home_activities_edges_node,
Home_productTopToday_edges_node,
@@ -85,10 +84,9 @@ const HomePage = decorate<HomePageProps>(
title={"Sales"}
icon={<AttachMoney fontSize={"inherit"} />}
>
- {maybe(
- () => (
- <Money moneyDetalis={sales} />
- ),
+ {sales ? (
+ <Money money={sales} />
+ ) : (
<Skeleton style={{ width: "5em" }} />
)}
</HomeAnalyticsCard>
diff --git a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx
index 12b82fd653..e0fc3f71de 100644
--- a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx
+++ b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx
@@ -76,8 +76,8 @@ export const HomeProductList = decorate<HomeProductListProps>(
{maybe(() =>
variant.attributes
.map(attribute => attribute.value)
- .sort(
- (a, b) => (a.sortOrder > b.sortOrder ? 1 : -1)
+ .sort((a, b) =>
+ a.sortOrder > b.sortOrder ? 1 : -1
)
.map(attribute => attribute.name)
.join(" / ")
@@ -98,7 +98,7 @@ export const HomeProductList = decorate<HomeProductListProps>(
<Typography align={"right"}>
{maybe(
() => (
- <Money moneyDetalis={variant.revenue.gross} />
+ <Money money={variant.revenue.gross} />
),
<Skeleton />
)}
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/OrderDraftDetailsProducts.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/OrderDraftDetailsProducts.tsx
index 17f7696c37..fed362d4da 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/OrderDraftDetailsProducts.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/OrderDraftDetailsProducts.tsx
@@ -120,7 +120,7 @@ const OrderDraftDetailsProducts = decorate<OrderDraftDetailsProductsProps>(
</TableCell>
<TableCell className={classes.textRight}>
{maybe(() => line.unitPrice.net) ? (
- <Money moneyDetalis={line.unitPrice.net} />
+ <Money money={line.unitPrice.net} />
) : (
<Skeleton />
)}
@@ -128,7 +128,7 @@ const OrderDraftDetailsProducts = decorate<OrderDraftDetailsProductsProps>(
<TableCell className={classes.textRight}>
{maybe(() => line.unitPrice.net && line.quantity) ? (
<Money
- moneyDetalis={{
+ money={{
amount: line.unitPrice.net.amount * line.quantity,
currency: line.unitPrice.net.currency
}}
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/OrderDraftDetailsSummary.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/OrderDraftDetailsSummary.tsx
index acf5a7c036..29606205a2 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/OrderDraftDetailsSummary.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/OrderDraftDetailsSummary.tsx
@@ -32,7 +32,7 @@ const OrderDraftDetailsSummary = decorate<OrderDraftDetailsSummaryProps>(
<>
<td>{i18n.t("Subtotal")}</td>
<td className={classes.textRight}>
- <Money moneyDetalis={order.subtotal.gross} />
+ <Money money={order.subtotal.gross} />
</td>
</>
) : (
@@ -53,7 +53,7 @@ const OrderDraftDetailsSummary = decorate<OrderDraftDetailsSummaryProps>(
</td>
<td className={classes.textRight}>
{maybe(() => order.shippingPrice) ? (
- <Money moneyDetalis={order.shippingPrice.gross} />
+ <Money money={order.shippingPrice.gross} />
) : (
"---"
)}
@@ -70,7 +70,7 @@ const OrderDraftDetailsSummary = decorate<OrderDraftDetailsSummaryProps>(
<>
<td>{i18n.t("Taxes (VAT included)")}</td>
<td className={classes.textRight}>
- <Money moneyDetalis={order.total.tax} />
+ <Money money={order.total.tax} />
</td>
</>
) : (
@@ -84,7 +84,7 @@ const OrderDraftDetailsSummary = decorate<OrderDraftDetailsSummaryProps>(
<>
<td>{i18n.t("Total")}</td>
<td className={classes.textRight}>
- <Money moneyDetalis={order.total.gross} />
+ <Money money={order.total.gross} />
</td>
</>
) : (
diff --git a/saleor/static/dashboard-next/orders/components/OrderFulfillment/OrderFulfillment.tsx b/saleor/static/dashboard-next/orders/components/OrderFulfillment/OrderFulfillment.tsx
index 281a340f4c..16c847f8c6 100644
--- a/saleor/static/dashboard-next/orders/components/OrderFulfillment/OrderFulfillment.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderFulfillment/OrderFulfillment.tsx
@@ -146,7 +146,7 @@ const OrderFulfillment = decorate<OrderFulfillmentProps>(
</TableCell>
<TableCell className={classes.textRight}>
{maybe(() => line.orderLine.unitPrice.gross) ? (
- <Money moneyDetalis={line.orderLine.unitPrice.gross} />
+ <Money money={line.orderLine.unitPrice.gross} />
) : (
<Skeleton />
)}
@@ -156,7 +156,7 @@ const OrderFulfillment = decorate<OrderFulfillmentProps>(
() => line.quantity * line.orderLine.unitPrice.gross.amount
) ? (
<Money
- moneyDetalis={{
+ money={{
amount:
line.quantity * line.orderLine.unitPrice.gross.amount,
currency: line.orderLine.unitPrice.gross.currency
diff --git a/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx b/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
index a682aded4f..1d9d346dca 100644
--- a/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx
@@ -152,7 +152,7 @@ export const OrderList = decorate<OrderListProps>(
</TableCell>
<TableCell className={classes.textRight} padding="dense">
{maybe(() => order.total.gross) ? (
- <Money moneyDetalis={order.total.gross} />
+ <Money money={order.total.gross} />
) : (
<Skeleton />
)}
diff --git a/saleor/static/dashboard-next/orders/components/OrderPayment/OrderPayment.tsx b/saleor/static/dashboard-next/orders/components/OrderPayment/OrderPayment.tsx
index 34044c8f3a..eec9ee9ac4 100644
--- a/saleor/static/dashboard-next/orders/components/OrderPayment/OrderPayment.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderPayment/OrderPayment.tsx
@@ -81,7 +81,7 @@ const OrderPayment = decorate<OrderPaymentProps>(
{maybe(() => order.subtotal.gross) === undefined ? (
<Skeleton />
) : (
- <Money moneyDetalis={order.subtotal.gross} />
+ <Money money={order.subtotal.gross} />
)}
</td>
</tr>
@@ -100,7 +100,7 @@ const OrderPayment = decorate<OrderPaymentProps>(
{maybe(() => order.total.tax) === undefined ? (
<Skeleton />
) : (
- <Money moneyDetalis={order.total.tax} />
+ <Money money={order.total.tax} />
)}
</td>
</tr>
@@ -120,7 +120,7 @@ const OrderPayment = decorate<OrderPaymentProps>(
{maybe(() => order.shippingPrice.gross) === undefined ? (
<Skeleton />
) : (
- <Money moneyDetalis={order.shippingPrice.gross} />
+ <Money money={order.shippingPrice.gross} />
)}
</td>
</tr>
@@ -131,7 +131,7 @@ const OrderPayment = decorate<OrderPaymentProps>(
{maybe(() => order.total.gross) === undefined ? (
<Skeleton />
) : (
- <Money moneyDetalis={order.total.gross} />
+ <Money money={order.total.gross} />
)}
</td>
</tr>
diff --git a/saleor/static/dashboard-next/orders/components/OrderShippingMethodEditDialog/OrderShippingMethodEditDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderShippingMethodEditDialog/OrderShippingMethodEditDialog.tsx
index 70746a5143..2ad837dcce 100644
--- a/saleor/static/dashboard-next/orders/components/OrderShippingMethodEditDialog/OrderShippingMethodEditDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderShippingMethodEditDialog/OrderShippingMethodEditDialog.tsx
@@ -55,7 +55,7 @@ const OrderShippingMethodEditDialog = decorate<
<span className={classes.shippingMethodName}>{s.name}</span>
&nbsp;
<span>
- <Money moneyDetalis={s.price} />
+ <Money money={s.price} />
</span>
</div>
),
diff --git a/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx b/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx
index 4d15f1cf0c..1c8496e846 100644
--- a/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx
@@ -88,7 +88,7 @@ const OrderUnfulfilledItems = decorate<OrderUnfulfilledItemsProps>(
</TableCell>
<TableCell className={classes.textRight}>
{maybe(() => line.unitPrice.gross) ? (
- <Money moneyDetalis={line.unitPrice.gross} />
+ <Money money={line.unitPrice.gross} />
) : (
<Skeleton />
)}
@@ -100,7 +100,7 @@ const OrderUnfulfilledItems = decorate<OrderUnfulfilledItemsProps>(
line.unitPrice.gross.amount
) ? (
<Money
- moneyDetalis={{
+ money={{
amount:
(line.quantity - line.quantityFulfilled) *
line.unitPrice.gross.amount,
diff --git a/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx b/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
index 6ea506ce84..705a8d082c 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariants/ProductVariants.tsx
@@ -131,9 +131,9 @@ export const ProductVariants = decorate<ProductVariantsProps>(
<TableCell className={classes.textRight}>
{variant ? (
variant.priceOverride ? (
- <Money moneyDetalis={variant.priceOverride} />
+ <Money money={variant.priceOverride} />
) : fallbackPrice ? (
- <Money moneyDetalis={fallbackPrice} />
+ <Money money={fallbackPrice} />
) : (
<Skeleton />
)
diff --git a/saleor/static/dashboard-next/storybook/stories/components/Money.tsx b/saleor/static/dashboard-next/storybook/stories/components/Money.tsx
index b72e3b7bac..12a1ac679e 100644
--- a/saleor/static/dashboard-next/storybook/stories/components/Money.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/components/Money.tsx
@@ -1,14 +1,16 @@
import { storiesOf } from "@storybook/react";
import * as React from "react";
-import Money, { MoneyProp } from "../../../components/Money";
+import Money, { MoneyProps } from "../../../components/Money";
import Decorator from "../../Decorator";
-const moneyDetalis: MoneyProp = {
- amount: 12,
- currency: "EUR"
+const props: MoneyProps = {
+ money: {
+ amount: 14,
+ currency: "EUR"
+ }
};
storiesOf("Generics / Money formatting", module)
.addDecorator(Decorator)
- .add("default", () => <Money moneyDetalis={moneyDetalis} />);
+ .add("default", () => <Money {...props} />);
diff --git a/saleor/static/dashboard-next/vouchers/components/VoucherList/VoucherList.tsx b/saleor/static/dashboard-next/vouchers/components/VoucherList/VoucherList.tsx
index f686d539d5..20873e80a4 100644
--- a/saleor/static/dashboard-next/vouchers/components/VoucherList/VoucherList.tsx
+++ b/saleor/static/dashboard-next/vouchers/components/VoucherList/VoucherList.tsx
@@ -11,7 +11,7 @@ import * as React from "react";
import { createVoucherName, VoucherType } from "../..";
import { ListProps } from "../../..";
import DateFormatter from "../../../components/DateFormatter";
-import Money, { MoneyProp } from "../../../components/Money";
+import Money from "../../../components/Money";
import Percent from "../../../components/Percent";
import Skeleton from "../../../components/Skeleton";
import TablePagination from "../../../components/TablePagination";
@@ -28,7 +28,10 @@ interface VoucherListProps extends ListProps {
endDate: string | null;
discountValueType: "PERCENTAGE" | "FIXED" | string;
discountValue: number;
- limit: MoneyProp | null;
+ limit: {
+ amount: number;
+ currency: string;
+ } | null;
product: {
name: string;
} | null;
@@ -39,9 +42,9 @@ interface VoucherListProps extends ListProps {
}
const decorate = withStyles(theme => ({
- link: { color: theme.palette.secondary.main, cursor: "pointer" as "pointer" },
- tableCellFont: {
- fontSize: "0.8125rem"
+ link: {
+ color: theme.palette.secondary.main,
+ cursor: "pointer" as "pointer"
},
textRight: { textAlign: "right" as "right" }
}));
@@ -138,17 +141,13 @@ const VoucherList = decorate<VoucherListProps>(
voucher.discountValueType &&
voucher.discountValue ? (
voucher.discountValueType === "PERCENTAGE" ? (
- <Percent
- amount={voucher.discountValue}
- typographyProps={{ className: classes.tableCellFont }}
- />
+ <Percent amount={voucher.discountValue} />
) : (
<Money
- moneyDetalis={{
+ money={{
amount: voucher.discountValue,
currency
}}
- typographyProps={{ className: classes.tableCellFont }}
/>
)
) : (
@@ -158,10 +157,7 @@ const VoucherList = decorate<VoucherListProps>(
<TableCell className={classes.textRight}>
{voucher ? (
voucher.limit !== null ? (
- <Money
- moneyDetalis={voucher.limit}
- typographyProps={{ className: classes.tableCellFont }}
- />
+ <Money money={voucher.limit} />
) : (
"-"
)