Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor code
dominik-zeglen768008c145cc
diff --git a/saleor/static/dashboard-next/discounts/components/SaleInfo/SaleInfo.tsx b/saleor/static/dashboard-next/discounts/components/SaleInfo/SaleInfo.tsxindex 41473b7d11..59a7144f0f 100644--- a/saleor/static/dashboard-next/discounts/components/SaleInfo/SaleInfo.tsx+++ b/saleor/static/dashboard-next/discounts/components/SaleInfo/SaleInfo.tsx@@ -9,7 +9,6 @@ import {import TextField from "@material-ui/core/TextField";import * as React from "react";-import { errors } from "../../../categories/fixtures";import CardTitle from "../../../components/CardTitle";import i18n from "../../../i18n";import { FormData } from "../SaleDetailsPage";diff --git a/saleor/static/dashboard-next/discounts/components/VoucherSummary/VoucherSummary.tsx b/saleor/static/dashboard-next/discounts/components/VoucherSummary/VoucherSummary.tsxindex 49aea657c0..70fe5c7163 100644--- a/saleor/static/dashboard-next/discounts/components/VoucherSummary/VoucherSummary.tsx+++ b/saleor/static/dashboard-next/discounts/components/VoucherSummary/VoucherSummary.tsx@@ -12,10 +12,7 @@ import Percent from "../../../components/Percent";import Skeleton from "../../../components/Skeleton";import i18n from "../../../i18n";import { maybe } from "../../../misc";-import {- VoucherDiscountValueType,- VoucherType-} from "../../../types/globalTypes";+import { VoucherDiscountValueType } from "../../../types/globalTypes";import { translateVoucherTypes } from "../../translations";import { VoucherDetails_voucher } from "../../types/VoucherDetails";diff --git a/saleor/static/dashboard-next/discounts/fixtures.ts b/saleor/static/dashboard-next/discounts/fixtures.tsindex 2d08eb6824..353d2620be 100644--- a/saleor/static/dashboard-next/discounts/fixtures.ts+++ b/saleor/static/dashboard-next/discounts/fixtures.ts@@ -110,7 +110,8 @@ export const sale: SaleDetails_sale = {hasNextPage: false,hasPreviousPage: false,startCursor: null- }+ },+ totalCount: 2},collections: {__typename: "CollectionCountableConnection",@@ -134,7 +135,8 @@ export const sale: SaleDetails_sale = {hasNextPage: false,hasPreviousPage: false,startCursor: null- }+ },+ totalCount: 4},endDate: null,id: "U2FsZTo1",@@ -221,7 +223,8 @@ export const sale: SaleDetails_sale = {hasNextPage: false,hasPreviousPage: false,startCursor: "YXJyYXljb25uZWN0aW9uOjA="- }+ },+ totalCount: 4},startDate: "2019-01-03",type: "PERCENTAGE" as SaleType,diff --git a/saleor/static/dashboard-next/discounts/views/SaleDetails/index.tsx b/saleor/static/dashboard-next/discounts/views/SaleDetails/index.tsxindex ef4a42e53f..29c3efceca 100644--- a/saleor/static/dashboard-next/discounts/views/SaleDetails/index.tsx+++ b/saleor/static/dashboard-next/discounts/views/SaleDetails/index.tsx@@ -34,6 +34,7 @@ import {TypedSaleUpdate} from "../../mutations";import { TypedSaleDetails } from "../../queries";+import { SaleCataloguesAdd } from "../../types/SaleCataloguesAdd";import { SaleDelete } from "../../types/SaleDelete";import { saleListUrl, saleUrl } from "../../urls";import {@@ -90,6 +91,12 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({}));+ const handleCatalogueAdd = (data: SaleCataloguesAdd) => {+ if (data.saleCataloguesAdd.errors.length === 0) {+ navigate(saleUrl(id), true, true);+ }+ };+const handleSaleDelete = (data: SaleDelete) => {if (data.saleDelete.errors.length === 0) {pushMessage({@@ -104,7 +111,7 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({return (<TypedSaleCataloguesRemove>{(saleCataloguesRemove, saleCataloguesRemoveOpts) => (- <TypedSaleCataloguesAdd>+ <TypedSaleCataloguesAdd onCompleted={handleCatalogueAdd}>{(saleCataloguesAdd, saleCataloguesAddOpts) => (<TypedSaleUpdate>{(saleUpdate, saleUpdateOpts) => (diff --git a/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx b/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsxindex 66d5a629e9..fa65b30e46 100644--- a/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx+++ b/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx@@ -9,7 +9,6 @@ import { getMutationState, maybe } from "../../misc";import {DiscountValueTypeEnum,VoucherDiscountValueType,- VoucherType,VoucherTypeEnum} from "../../types/globalTypes";import VoucherCreatePage from "../components/VoucherCreatePage";diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsx b/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsxindex ebe32eaeaa..b827705ad2 100644--- a/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsx+++ b/saleor/static/dashboard-next/discounts/views/VoucherDetails/index.tsx@@ -23,7 +23,10 @@ import { SearchProductsProvider } from "../../../containers/SearchProducts";import i18n from "../../../i18n";import { getMutationState, maybe } from "../../../misc";import { productUrl } from "../../../products/urls";-import { DiscountValueTypeEnum, VoucherType } from "../../../types/globalTypes";+import {+ DiscountValueTypeEnum,+ VoucherDiscountValueType+} from "../../../types/globalTypes";import VoucherDetailsPage, {VoucherDetailsPageTab} from "../../components/VoucherDetailsPage";@@ -47,6 +50,7 @@ import {voucherDeletePath,voucherDeleteUrl} from "./urls";+import { VoucherCataloguesAdd } from "../../types/VoucherCataloguesAdd";const PAGINATE_BY = 20;@@ -61,7 +65,9 @@ interface VoucherDetailsProps {params: VoucherDetailsQueryParams;}-function discountValueTypeEnum(type: VoucherType): DiscountValueTypeEnum {+function discountValueTypeEnum(+ type: VoucherDiscountValueType+): DiscountValueTypeEnum {return type.toString() === DiscountValueTypeEnum.FIXED? DiscountValueTypeEnum.FIXED: DiscountValueTypeEnum.PERCENTAGE;@@ -91,6 +97,11 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({}));+ const handleCatalogueAdd = (data: VoucherCataloguesAdd) => {+ if (data.voucherCataloguesAdd.errors.length === 0) {+ navigate(voucherUrl(id), true, true);+ }+ };const handleVoucherDelete = (data: VoucherDelete) => {if (data.voucherDelete.errors.length === 0) {pushMessage({@@ -105,7 +116,9 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({return (<TypedVoucherCataloguesRemove>{(voucherCataloguesRemove, voucherCataloguesRemoveOpts) => (- <TypedVoucherCataloguesAdd>+ <TypedVoucherCataloguesAdd+ onCompleted={handleCatalogueAdd}+ >{(voucherCataloguesAdd, voucherCataloguesAddOpts) => (<TypedVoucherUpdate>{(voucherUpdate, voucherUpdateOpts) => (@@ -304,6 +317,11 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({variables: {id,input: {+ discountValue:+ formData.value,+ discountValueType: discountValueTypeEnum(+ formData.discountType+ ),endDate:formData.endDate ===""@@ -311,11 +329,7 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({: formData.endDate,name: formData.name,startDate:- formData.startDate,- type: discountValueTypeEnum(- formData.type- ),- value: formData.value+ formData.startDate}}})