Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extract utils
dominik-zeglen58ec23d1217c
diff --git a/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx b/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsxindex cdb7c35c73..3146e7a211 100644--- a/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx+++ b/saleor/static/dashboard-next/customers/components/CustomerOrders/CustomerOrders.tsx@@ -14,8 +14,7 @@ import Money from "../../../components/Money";import Skeleton from "../../../components/Skeleton";import StatusLabel from "../../../components/StatusLabel";import i18n from "../../../i18n";-import { maybe, renderCollection } from "../../../misc";-import { transformPaymentStatus } from "../../../orders";+import { maybe, renderCollection, transformPaymentStatus } from "../../../misc";import { CustomerDetails_user_orders_edges_node } from "../../types/CustomerDetails";export interface CustomerOrdersProps {diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.tsindex ad2bcf6860..aa2469d3f6 100644--- a/saleor/static/dashboard-next/misc.ts+++ b/saleor/static/dashboard-next/misc.ts@@ -1,5 +1,11 @@+import { AddressType } from "./customers/types";import i18n from "./i18n";-import { AuthorizationKeyType, TaxRateType } from "./types/globalTypes";+import {+ AuthorizationKeyType,+ OrderStatus,+ PaymentChargeStatusEnum,+ TaxRateType+} from "./types/globalTypes";export function renderCollection<T>(collection: T[],@@ -26,6 +32,50 @@ export function decimal(value: string) {export const removeDoubleSlashes = (url: string) =>url.replace(/([^:]\/)\/+/g, "$1");+export const transformPaymentStatus = (status: string) => {+ switch (status) {+ case PaymentChargeStatusEnum.CHARGED:+ return { localized: i18n.t("Paid"), status: "success" };+ case PaymentChargeStatusEnum.FULLY_REFUNDED:+ return { localized: i18n.t("Refunded"), status: "success" };+ default:+ return { localized: i18n.t("Unpaid"), status: "error" };+ }+};++export const transformOrderStatus = (status: string) => {+ switch (status) {+ case OrderStatus.FULFILLED:+ return { localized: i18n.t("Fulfilled"), status: "success" };+ case OrderStatus.PARTIALLY_FULFILLED:+ return { localized: i18n.t("Partially fulfilled"), status: "neutral" };+ case OrderStatus.UNFULFILLED:+ return { localized: i18n.t("Unfulfilled"), status: "error" };+ case OrderStatus.CANCELED:+ return { localized: i18n.t("Cancelled"), status: "error" };+ case OrderStatus.DRAFT:+ return { localized: i18n.t("Draft"), status: "error" };+ }+ return {+ localized: status,+ status: "error"+ };+};++export const transformAddressToForm = (data: AddressType) => ({+ city: maybe(() => data.city, ""),+ cityArea: maybe(() => data.cityArea, ""),+ companyName: maybe(() => data.companyName, ""),+ country: maybe(() => data.country.code, ""),+ countryArea: maybe(() => data.countryArea, ""),+ firstName: maybe(() => data.firstName, ""),+ lastName: maybe(() => data.lastName, ""),+ phone: maybe(() => data.phone, ""),+ postalCode: maybe(() => data.postalCode, ""),+ streetAddress1: maybe(() => data.streetAddress1, ""),+ streetAddress2: maybe(() => data.streetAddress2, "")+});+export const translatedTaxRates = () => ({[TaxRateType.ACCOMMODATION]: i18n.t("Accommodation"),[TaxRateType.ADMISSION_TO_CULTURAL_EVENTS]: i18n.t(diff --git a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsxindex e4376f965c..847f3c66ff 100644--- a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx@@ -3,7 +3,6 @@ import { withStyles, WithStyles } from "@material-ui/core/styles";import Typography from "@material-ui/core/Typography";import * as React from "react";-import { transformAddressToForm } from "../..";import { UserError } from "../../..";import ActionDialog from "../../../components/ActionDialog";import { CardMenu } from "../../../components/CardMenu/CardMenu";@@ -16,7 +15,7 @@ import Skeleton from "../../../components/Skeleton";import Toggle from "../../../components/Toggle";import { AddressTypeInput } from "../../../customers/types";import i18n from "../../../i18n";-import { maybe, renderCollection } from "../../../misc";+import { maybe, renderCollection, transformAddressToForm } from "../../../misc";import { OrderStatus } from "../../../types/globalTypes";import { OrderDetails_order } from "../../types/OrderDetails";import OrderAddressEditDialog from "../OrderAddressEditDialog";diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsxindex 5422f98e28..95486f8f14 100644--- a/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderDraftPage/OrderDraftPage.tsx@@ -3,7 +3,6 @@ import { withStyles, WithStyles } from "@material-ui/core/styles";import Typography from "@material-ui/core/Typography";import * as React from "react";-import { transformAddressToForm } from "../..";import { UserError } from "../../..";import ActionDialog from "../../../components/ActionDialog";import { CardMenu } from "../../../components/CardMenu/CardMenu";@@ -15,7 +14,7 @@ import SaveButtonBar from "../../../components/SaveButtonBar";import Skeleton from "../../../components/Skeleton";import { AddressTypeInput } from "../../../customers/types";import i18n from "../../../i18n";-import { maybe } from "../../../misc";+import { maybe, transformAddressToForm } from "../../../misc";import { DraftOrderInput } from "../../../types/globalTypes";import { OrderDetails_order } from "../../types/OrderDetails";import { UserSearch_customers_edges_node } from "../../types/UserSearch";diff --git a/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx b/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsxindex 9734b26b61..0956ba51d0 100644--- a/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderList/OrderList.tsx@@ -8,7 +8,6 @@ import TableHead from "@material-ui/core/TableHead";import TableRow from "@material-ui/core/TableRow";import * as React from "react";-import { transformOrderStatus, transformPaymentStatus } from "../..";import { ListProps } from "../../..";import DateFormatter from "../../../components/DateFormatter";import Money from "../../../components/Money";@@ -16,7 +15,12 @@ import Skeleton from "../../../components/Skeleton";import StatusLabel from "../../../components/StatusLabel";import TablePagination from "../../../components/TablePagination";import i18n from "../../../i18n";-import { maybe, renderCollection } from "../../../misc";+import {+ maybe,+ renderCollection,+ transformOrderStatus,+ transformPaymentStatus+} from "../../../misc";import { OrderList_orders_edges_node } from "../../types/OrderList";interface OrderListProps extends ListProps {diff --git a/saleor/static/dashboard-next/orders/components/OrderPayment/OrderPayment.tsx b/saleor/static/dashboard-next/orders/components/OrderPayment/OrderPayment.tsxindex eec9ee9ac4..a78a7574f9 100644--- a/saleor/static/dashboard-next/orders/components/OrderPayment/OrderPayment.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderPayment/OrderPayment.tsx@@ -5,14 +5,13 @@ import CardContent from "@material-ui/core/CardContent";import { withStyles } from "@material-ui/core/styles";import * as React from "react";-import { transformPaymentStatus } from "../..";import CardTitle from "../../../components/CardTitle";import { Hr } from "../../../components/Hr";import Money from "../../../components/Money";import Skeleton from "../../../components/Skeleton";import StatusLabel from "../../../components/StatusLabel";import i18n from "../../../i18n";-import { maybe } from "../../../misc";+import { maybe, transformPaymentStatus } from "../../../misc";import { OrderAction, OrderStatus } from "../../../types/globalTypes";import { OrderDetails_order } from "../../types/OrderDetails";diff --git a/saleor/static/dashboard-next/orders/fixtures.ts b/saleor/static/dashboard-next/orders/fixtures.tsindex 6811d6077e..45b7ba2e3c 100644--- a/saleor/static/dashboard-next/orders/fixtures.ts+++ b/saleor/static/dashboard-next/orders/fixtures.ts@@ -1,3 +1,4 @@+import { transformOrderStatus, transformPaymentStatus } from "../misc";import {FulfillmentStatus,OrderAction,@@ -5,7 +6,6 @@ import {OrderStatus,PaymentChargeStatusEnum} from "../types/globalTypes";-import { transformOrderStatus, transformPaymentStatus } from "./";import { OrderDetails_order } from "./types/OrderDetails";import { OrderList_orders_edges_node } from "./types/OrderList";import { UserSearch_customers_edges_node } from "./types/UserSearch";diff --git a/saleor/static/dashboard-next/storybook/stories/components/AddressEdit.tsx b/saleor/static/dashboard-next/storybook/stories/components/AddressEdit.tsxindex 164833ea5f..7b193a56b1 100644--- a/saleor/static/dashboard-next/storybook/stories/components/AddressEdit.tsx+++ b/saleor/static/dashboard-next/storybook/stories/components/AddressEdit.tsx@@ -4,7 +4,7 @@ import * as React from "react";import AddressEdit from "../../../components/AddressEdit";import { Container } from "../../../components/Container";import { customer } from "../../../customers/fixtures";-import { transformAddressToForm } from "../../../orders";+import { transformAddressToForm } from "../../../misc";import { countries } from "../../../orders/fixtures";import Decorator from "../../Decorator";diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderAddressEditDialog.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderAddressEditDialog.tsxindex fc64c123aa..e985620d45 100644--- a/saleor/static/dashboard-next/storybook/stories/orders/OrderAddressEditDialog.tsx+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderAddressEditDialog.tsx@@ -1,7 +1,7 @@import { storiesOf } from "@storybook/react";import * as React from "react";-import { transformAddressToForm } from "../../../orders";+import { transformAddressToForm } from "../../../misc";import OrderAddressEditDialog from "../../../orders/components/OrderAddressEditDialog";import { countries, order as orderFixture } from "../../../orders/fixtures";import Decorator from "../../Decorator";