Skip to content

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

Fix voucher types

Krzysztof Bialoglowiczfc7c9bdfd30b
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherCreatePage/VoucherCreatePage.tsx b/saleor/static/dashboard-next/discounts/components/VoucherCreatePage/VoucherCreatePage.tsx
index 673afb1460..51d7ceb601 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherCreatePage/VoucherCreatePage.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherCreatePage/VoucherCreatePage.tsx
@@ -14,8 +14,11 @@ import {
VoucherDiscountValueType,
VoucherType
} from "../../../types/globalTypes";
+import VoucherDates from "../VoucherDates";
import VoucherInfo from "../VoucherInfo";
-import VoucherOptions from "../VoucherOptions";
+import VoucherLimits from "../VoucherLimits";
+import VoucherRequirements from "../VoucherRequirements";
+import VoucherTypes from "../VoucherTypes";
export interface FormData {
applyOncePerOrder: boolean;
@@ -75,7 +78,14 @@ const VoucherCreatePage: React.StatelessComponent<VoucherCreatePageProps> = ({
onChange={change}
/>
<CardSpacer />
- <VoucherOptions
+ <VoucherTypes
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <VoucherRequirements
data={data}
disabled={disabled}
defaultCurrency={defaultCurrency}
@@ -83,6 +93,21 @@ const VoucherCreatePage: React.StatelessComponent<VoucherCreatePageProps> = ({
onChange={change}
/>
<CardSpacer />
+ <VoucherLimits
+ data={data}
+ disabled={disabled}
+ defaultCurrency={defaultCurrency}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <VoucherDates
+ data={data}
+ disabled={disabled}
+ defaultCurrency={defaultCurrency}
+ errors={formErrors}
+ onChange={change}
+ />
</div>
</Grid>
<SaveButtonBar
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx
index 75e9955e53..039b0bd7e8 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx
@@ -12,7 +12,7 @@ import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
import { Tab, TabContainer } from "@saleor/components/Tab";
import i18n from "../../../i18n";
-import { maybe } from "../../../misc";
+import { maybe, splitDateTime } from "../../../misc";
import { ListProps, TabListActions, UserError } from "../../../types";
import {
VoucherDiscountValueType,
@@ -22,10 +22,13 @@ import { VoucherDetails_voucher } from "../../types/VoucherDetails";
import DiscountCategories from "../DiscountCategories";
import DiscountCollections from "../DiscountCollections";
import DiscountProducts from "../DiscountProducts";
+import VoucherDates from "../VoucherDates";
import VoucherInfo from "../VoucherInfo";
-import VoucherOptions from "../VoucherOptions";
+import VoucherLimits from "../VoucherLimits";
+import VoucherRequirements from "../VoucherRequirements";
import VoucherSummary from "../VoucherSummary";
import VoucherTypes from "../VoucherTypes";
+import VoucherValue from "../VoucherValue";
export enum VoucherDetailsPageTab {
categories = "categories",
@@ -45,8 +48,10 @@ export interface FormData {
code: string;
discountType: VoucherDiscountValueType;
endDate: string;
+ endTime: string;
minAmountSpent: number;
startDate: string;
+ startTime: string;
type: VoucherType;
usageLimit: number;
value: number;
@@ -123,9 +128,11 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({
() => voucher.discountValueType,
VoucherDiscountValueType.FIXED
),
- endDate: maybe(() => voucher.endDate, ""),
+ endDate: splitDateTime(maybe(() => voucher.endDate, "")).date,
+ endTime: splitDateTime(maybe(() => voucher.endDate, "")).time,
minAmountSpent: maybe(() => voucher.minAmountSpent.amount, 0),
- startDate: maybe(() => voucher.startDate, ""),
+ startDate: splitDateTime(maybe(() => voucher.startDate, "")).date,
+ startTime: splitDateTime(maybe(() => voucher.startDate, "")).time,
type: maybe(() => voucher.type, VoucherType.ENTIRE_ORDER),
usageLimit: maybe(() => voucher.usageLimit || 0, 0),
value: maybe(() => voucher.discountValue, 0)
@@ -153,13 +160,15 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({
onChange={change}
/>
<CardSpacer />
- <VoucherOptions
- data={data}
- disabled={disabled}
- defaultCurrency={defaultCurrency}
- errors={formErrors}
- onChange={change}
- />
+ {data.discountType !== VoucherDiscountValueType.SHIPPING ? (
+ <VoucherValue
+ data={data}
+ disabled={disabled}
+ defaultCurrency={defaultCurrency}
+ errors={formErrors}
+ onChange={change}
+ />
+ ) : null}
<CardSpacer />
{data.type === VoucherType.CATEGORY ||
data.type === VoucherType.COLLECTION ||
@@ -252,7 +261,7 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({
/>
)}
</>
- ) : data.type === VoucherType.SHIPPING ? (
+ ) : data.discountType === VoucherDiscountValueType.SHIPPING ? (
<CountryList
countries={maybe(() => voucher.countries)}
disabled={disabled}
@@ -271,6 +280,30 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({
onCountryUnassign={onCountryUnassign}
/>
) : null}
+ <CardSpacer />
+ <VoucherRequirements
+ data={data}
+ disabled={disabled}
+ defaultCurrency={defaultCurrency}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <VoucherLimits
+ data={data}
+ disabled={disabled}
+ defaultCurrency={defaultCurrency}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <VoucherDates
+ data={data}
+ disabled={disabled}
+ defaultCurrency={defaultCurrency}
+ errors={formErrors}
+ onChange={change}
+ />
</div>
<div>
<VoucherSummary
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx b/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx
index 1554ef1a51..27d9e0cdd9 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx
@@ -19,7 +19,7 @@ import i18n from "../../../i18n";
import { FormErrors } from "../../../types";
import {
VoucherDiscountValueType,
- VoucherType
+ VoucherTypeEnum
} from "../../../types/globalTypes";
import { translateVoucherTypes } from "../../translations";
import { FormData } from "../VoucherDetailsPage";
@@ -53,7 +53,7 @@ const VoucherValue = withStyles(styles, {
onChange
}: VoucherValueProps & WithStyles<typeof styles>) => {
const translatedVoucherTypes = translateVoucherTypes();
- const voucherTypeChoices = Object.values(VoucherType).map(type => ({
+ const voucherTypeChoices = Object.values(VoucherTypeEnum).map(type => ({
hidden: type === "SHIPPING" ? true : false,
label: translatedVoucherTypes[type],
value: type
diff --git a/saleor/static/dashboard-next/discounts/translations.ts b/saleor/static/dashboard-next/discounts/translations.ts
index 6a29e3b39b..fc8aa0b7b4 100644
--- a/saleor/static/dashboard-next/discounts/translations.ts
+++ b/saleor/static/dashboard-next/discounts/translations.ts
@@ -2,12 +2,7 @@ import i18n from "../i18n";
import { VoucherType } from "../types/globalTypes";
export const translateVoucherTypes = () => ({
- // [VoucherType.CATEGORY]: i18n.t("Selected Categories"),
- // [VoucherType.COLLECTION]: i18n.t("Selected Collections"),
- [VoucherType.PRODUCT]: i18n.t("Specyfic Products"),
[VoucherType.SHIPPING]: i18n.t("Shipment"),
[VoucherType.ENTIRE_ORDER]: i18n.t("Entire order"),
- [VoucherType.SPECIFIC_PRODUCT]: i18n.t(
- "Selected Products, Collections and Categories"
- )
+ [VoucherType.SPECIFIC_PRODUCT]: i18n.t("Specific Products")
});
diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
index ae4385c8e8..726d1f8ec8 100644
--- a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
+++ b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
@@ -22,11 +22,13 @@ import SearchCategories from "../../containers/SearchCategories";
import SearchCollections from "../../containers/SearchCollections";
import SearchProducts from "../../containers/SearchProducts";
import i18n from "../../i18n";
-import { decimal, getMutationState, maybe } from "../../misc";
+import { decimal, getMutationState, maybe, connectDateTime } from "../../misc";
import { productUrl } from "../../products/urls";
import {
DiscountValueTypeEnum,
- VoucherDiscountValueType
+ VoucherDiscountValueType,
+ VoucherType,
+ VoucherTypeEnum
} from "../../types/globalTypes";
import DiscountCountrySelectDialog from "../components/DiscountCountrySelectDialog";
import VoucherDetailsPage, {
@@ -55,14 +57,6 @@ interface VoucherDetailsProps {
params: VoucherUrlQueryParams;
}
-function discountValueTypeEnum(
- type: VoucherDiscountValueType
-): DiscountValueTypeEnum {
- return type.toString() === DiscountValueTypeEnum.FIXED
- ? DiscountValueTypeEnum.FIXED
- : DiscountValueTypeEnum.PERCENTAGE;
-}
-
export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
id,
params
@@ -319,28 +313,33 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
activeTab={params.activeTab}
onBack={() => navigate(voucherListUrl())}
onTabClick={changeTab}
- onSubmit={formData =>
+ onSubmit={formData => {
+ console.log(
+ connectDateTime(
+ formData.endDate,
+ formData.endTime
+ )
+ );
voucherUpdate({
variables: {
id,
input: {
+ code: formData.code,
discountValue: decimal(formData.value),
- discountValueType: discountValueTypeEnum(
- formData.discountType
+ discountValueType: formData.discountType,
+ endDate: connectDateTime(
+ formData.endDate,
+ formData.endTime
),
- endDate:
- formData.endDate === null
- ? null
- : moment(formData.endDate),
-
- startDate:
- formData.startDate === null
- ? null
- : moment(formData.startDate)
+ startDate: connectDateTime(
+ formData.startDate,
+ formData.startTime
+ ),
+ type: formData.type
}
}
- })
- }
+ });
+ }}
onRemove={() => openModal("remove")}
saveButtonBarState={formTransitionState}
categoryListToolbar={
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index 1bb579068d..786a7dc9fa 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -215,10 +215,7 @@ export enum VoucherType {
}
export enum VoucherTypeEnum {
- CATEGORY = "CATEGORY",
- COLLECTION = "COLLECTION",
ENTIRE_ORDER = "ENTIRE_ORDER",
- PRODUCT = "PRODUCT",
SHIPPING = "SHIPPING",
SPECIFIC_PRODUCT = "SPECIFIC_PRODUCT"
}