Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add missing voucher settings
Krzysztof Bialoglowicze0510f7e1734
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherCreatePage/VoucherCreatePage.tsx b/saleor/static/dashboard-next/discounts/components/VoucherCreatePage/VoucherCreatePage.tsxindex 9f313e7f82..1f512461a1 100644--- a/saleor/static/dashboard-next/discounts/components/VoucherCreatePage/VoucherCreatePage.tsx+++ b/saleor/static/dashboard-next/discounts/components/VoucherCreatePage/VoucherCreatePage.tsx@@ -22,6 +22,7 @@ import VoucherTypes from "../VoucherTypes";import VoucherValue from "../VoucherValue";export interface FormData {+ applyOncePerCustomer: boolean;applyOncePerOrder: boolean;code: string;discountType: DiscountValueTypeEnum;@@ -30,6 +31,8 @@ export interface FormData {hasEndDate: boolean;hasUsageLimit: boolean;minAmountSpent: string;+ minCheckoutItemsQuantity: string;+ requirementsPicker: string;startDate: string;startTime: string;type: VoucherTypeEnum;@@ -55,6 +58,7 @@ const VoucherCreatePage: React.StatelessComponent<VoucherCreatePageProps> = ({onSubmit}) => {const initialForm: FormData = {+ applyOncePerCustomer: false,applyOncePerOrder: false,code: "",discountType: DiscountValueTypeEnum.FIXED,@@ -63,6 +67,8 @@ const VoucherCreatePage: React.StatelessComponent<VoucherCreatePageProps> = ({hasEndDate: false,hasUsageLimit: false,minAmountSpent: "0",+ minCheckoutItemsQuantity: "0",+ requirementsPicker: "NONE",startDate: "",startTime: "",type: VoucherTypeEnum.ENTIRE_ORDER,diff --git a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsxindex 6e8ea046a2..f5119724b5 100644--- a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx+++ b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx@@ -44,6 +44,7 @@ export function voucherDetailsPageTab(tab: string): VoucherDetailsPageTab {}export interface FormData {+ applyOncePerCustomer: boolean;applyOncePerOrder: boolean;code: string;discountType: DiscountValueTypeEnum;@@ -52,6 +53,8 @@ export interface FormData {hasEndDate: boolean;hasUsageLimit: boolean;minAmountSpent: string;+ minCheckoutItemsQuantity: string;+ requirementsPicker: string;startDate: string;startTime: string;type: VoucherTypeEnum;@@ -123,7 +126,17 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({collectionListToolbar,productListToolbar}) => {+ let requirementsPickerInitValue;+ if (maybe(() => voucher.minAmountSpent.amount) > 0) {+ requirementsPickerInitValue = "ORDER";+ } else if (maybe(() => voucher.minCheckoutItemsQuantity) > 0) {+ requirementsPickerInitValue = "ITEM";+ } else {+ requirementsPickerInitValue = "NONE";+ }+const initialForm: FormData = {+ applyOncePerCustomer: maybe(() => voucher.applyOncePerCustomer, false),applyOncePerOrder: maybe(() => voucher.applyOncePerOrder, false),code: maybe(() => voucher.code, ""),discountType: maybe(@@ -135,6 +148,11 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({hasEndDate: maybe(() => !!voucher.endDate),hasUsageLimit: maybe(() => !!voucher.usageLimit),minAmountSpent: maybe(() => voucher.minAmountSpent.amount.toString(), "0"),+ minCheckoutItemsQuantity: maybe(+ () => voucher.minCheckoutItemsQuantity.toString(),+ "0"+ ),+ requirementsPicker: requirementsPickerInitValue,startDate: splitDateTime(maybe(() => voucher.startDate, "")).date,startTime: splitDateTime(maybe(() => voucher.startDate, "")).time,type: maybe(() => voucher.type, VoucherTypeEnum.ENTIRE_ORDER),diff --git a/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx b/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsxindex efebc93d25..838de06307 100644--- a/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx+++ b/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx@@ -51,6 +51,12 @@ const VoucherLimits = ({fullWidth/>)}+ <ControlledCheckbox+ checked={data.applyOncePerCustomer}+ label={i18n.t("Limit to one use per customer")}+ name={"applyOncePerCustomer" as keyof FormData}+ onChange={onChange}+ /></CardContent></Card>);diff --git a/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx b/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsxindex c1ba452771..50ab3c3797 100644--- a/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx+++ b/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx@@ -4,15 +4,17 @@ import TextField from "@material-ui/core/TextField";import * as React from "react";import CardTitle from "@saleor/components/CardTitle";-import i18n from "../../../i18n";-import { FormErrors } from "../../../types";+import { FormSpacer } from "@saleor/components/FormSpacer";+import RadioGroupField from "@saleor/components/RadioGroupField";+import i18n from "@saleor/i18n";+import { FormErrors } from "@saleor/types";import { FormData } from "../VoucherDetailsPage";interface VoucherRequirementsProps {data: FormData;defaultCurrency: string;disabled: boolean;- errors: FormErrors<"minAmountSpent">;+ errors: FormErrors<"minAmountSpent" | "minCheckoutItemsQuantity">;onChange: (event: React.ChangeEvent<any>) => void;}@@ -22,20 +24,57 @@ const VoucherRequirements = ({errors,onChange}: VoucherRequirementsProps) => {+ const requirementsPickerChoices = [+ {+ label: i18n.t("None"),+ value: "NONE"+ },+ {+ label: i18n.t("Minimal order value"),+ value: "ORDER"+ },+ {+ label: i18n.t("Minimum quantity of items"),+ value: "ITEM"+ }+ ];+return (<Card><CardTitle title={i18n.t("Minimum Requirements")} /><CardContent>- <TextField+ <RadioGroupField+ choices={requirementsPickerChoices}disabled={disabled}- error={!!errors.minAmountSpent}- helperText={errors.minAmountSpent}- label={i18n.t("Minimal order value")}- name={"minAmountSpent" as keyof FormData}- value={data.minAmountSpent}+ name={"requirementsPicker" as keyof FormData}+ value={data.requirementsPicker}onChange={onChange}- fullWidth/>+ <FormSpacer />+ {data.requirementsPicker.toString() === "ORDER" ? (+ <TextField+ disabled={disabled}+ error={!!errors.minAmountSpent}+ helperText={errors.minAmountSpent}+ label={i18n.t("Minimal order value")}+ name={"minAmountSpent" as keyof FormData}+ value={data.minAmountSpent}+ onChange={onChange}+ fullWidth+ />+ ) : null}+ {data.requirementsPicker.toString() === "ITEM" ? (+ <TextField+ disabled={disabled}+ error={!!errors.minCheckoutItemsQuantity}+ helperText={errors.minCheckoutItemsQuantity}+ label={i18n.t("Minimum quantity of items")}+ name={"minCheckoutItemsQuantity" as keyof FormData}+ value={data.minCheckoutItemsQuantity}+ onChange={onChange}+ fullWidth+ />+ ) : null}</CardContent></Card>);diff --git a/saleor/static/dashboard-next/discounts/queries.ts b/saleor/static/dashboard-next/discounts/queries.tsindex a20f3cfd0b..693c691c04 100644--- a/saleor/static/dashboard-next/discounts/queries.ts+++ b/saleor/static/dashboard-next/discounts/queries.ts@@ -95,6 +95,7 @@ export const voucherFragment = gql`currencyamount}+ minCheckoutItemsQuantity}`;@@ -108,6 +109,7 @@ export const voucherDetailsFragment = gql`usageLimitusedapplyOncePerOrder+ applyOncePerCustomerproducts(after: $after, before: $before, first: $first, last: $last) {edges {node {diff --git a/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx b/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsxindex 8d1062295a..058f23b21c 100644--- a/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx+++ b/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx@@ -52,6 +52,7 @@ export const VoucherDetails: React.StatelessComponent = () => {voucherCreate({variables: {input: {+ applyOncePerCustomer: formData.applyOncePerCustomer,applyOncePerOrder: formData.applyOncePerOrder,code: formData.code,discountValue:@@ -65,7 +66,16 @@ export const VoucherDetails: React.StatelessComponent = () => {endDate: formData.hasEndDate? joinDateTime(formData.endDate, formData.endTime): null,- minAmountSpent: parseFloat(formData.minAmountSpent),+ minAmountSpent:+ formData.requirementsPicker === "NONE" ||+ formData.requirementsPicker === "ITEM"+ ? 0+ : parseFloat(formData.minAmountSpent),+ minCheckoutItemsQuantity:+ formData.requirementsPicker === "NONE" ||+ formData.requirementsPicker === "ORDER"+ ? 0+ : parseFloat(formData.minCheckoutItemsQuantity),startDate: joinDateTime(formData.startDate,formData.startTimediff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsxindex 9c9de4d467..435bdb484e 100644--- a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx+++ b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx@@ -315,6 +315,8 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({variables: {id,input: {+ applyOncePerCustomer:+ formData.applyOncePerCustomer,applyOncePerOrder:formData.applyOncePerOrder,discountValue:@@ -333,9 +335,20 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({formData.endTime): null,- minAmountSpent: parseFloat(- formData.minAmountSpent- ),+ minAmountSpent:+ formData.requirementsPicker ===+ "NONE" ||+ formData.requirementsPicker === "ITEM"+ ? 0+ : parseFloat(formData.minAmountSpent),+ minCheckoutItemsQuantity:+ formData.requirementsPicker ===+ "NONE" ||+ formData.requirementsPicker === "ORDER"+ ? 0+ : parseFloat(+ formData.minCheckoutItemsQuantity+ ),startDate: joinDateTime(formData.startDate,formData.startTime