2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-26 13:59:32 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
import AppHeader from "@saleor/components/AppHeader";
|
|
|
|
import CardSpacer from "@saleor/components/CardSpacer";
|
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
|
|
|
import Container from "@saleor/components/Container";
|
|
|
|
import Form from "@saleor/components/Form";
|
|
|
|
import Grid from "@saleor/components/Grid";
|
|
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
|
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
2019-12-02 10:49:14 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { UserError } from "../../../types";
|
|
|
|
import {
|
2019-08-09 11:14:35 +00:00
|
|
|
DiscountValueTypeEnum,
|
|
|
|
VoucherTypeEnum
|
2019-06-19 14:40:52 +00:00
|
|
|
} from "../../../types/globalTypes";
|
2019-08-09 11:14:35 +00:00
|
|
|
import { RequirementsPicker } from "../../types";
|
|
|
|
import VoucherDates from "../VoucherDates";
|
2019-06-19 14:40:52 +00:00
|
|
|
import VoucherInfo from "../VoucherInfo";
|
2019-08-09 11:14:35 +00:00
|
|
|
import VoucherLimits from "../VoucherLimits";
|
|
|
|
import VoucherRequirements from "../VoucherRequirements";
|
|
|
|
import VoucherTypes from "../VoucherTypes";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-08-09 11:14:35 +00:00
|
|
|
import VoucherValue from "../VoucherValue";
|
2019-06-19 14:40:52 +00:00
|
|
|
export interface FormData {
|
2019-08-09 11:14:35 +00:00
|
|
|
applyOncePerCustomer: boolean;
|
2019-06-19 14:40:52 +00:00
|
|
|
applyOncePerOrder: boolean;
|
|
|
|
code: string;
|
2019-08-09 11:14:35 +00:00
|
|
|
discountType: DiscountValueTypeEnum;
|
2019-06-19 14:40:52 +00:00
|
|
|
endDate: string;
|
2019-08-09 11:14:35 +00:00
|
|
|
endTime: string;
|
|
|
|
hasEndDate: boolean;
|
|
|
|
hasUsageLimit: boolean;
|
|
|
|
minCheckoutItemsQuantity: string;
|
2020-01-09 11:13:24 +00:00
|
|
|
minSpent: string;
|
2019-08-09 11:14:35 +00:00
|
|
|
requirementsPicker: RequirementsPicker;
|
2019-06-19 14:40:52 +00:00
|
|
|
startDate: string;
|
2019-08-09 11:14:35 +00:00
|
|
|
startTime: string;
|
|
|
|
type: VoucherTypeEnum;
|
|
|
|
usageLimit: string;
|
2019-06-19 14:40:52 +00:00
|
|
|
value: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface VoucherCreatePageProps {
|
|
|
|
defaultCurrency: string;
|
|
|
|
disabled: boolean;
|
|
|
|
errors: UserError[];
|
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
|
|
onBack: () => void;
|
|
|
|
onSubmit: (data: FormData) => void;
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const VoucherCreatePage: React.FC<VoucherCreatePageProps> = ({
|
2019-06-19 14:40:52 +00:00
|
|
|
defaultCurrency,
|
|
|
|
disabled,
|
|
|
|
errors,
|
|
|
|
saveButtonBarState,
|
|
|
|
onBack,
|
|
|
|
onSubmit
|
|
|
|
}) => {
|
2019-08-26 13:59:32 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
const initialForm: FormData = {
|
2019-08-09 11:14:35 +00:00
|
|
|
applyOncePerCustomer: false,
|
2019-06-19 14:40:52 +00:00
|
|
|
applyOncePerOrder: false,
|
|
|
|
code: "",
|
2019-08-09 11:14:35 +00:00
|
|
|
discountType: DiscountValueTypeEnum.FIXED,
|
2019-06-19 14:40:52 +00:00
|
|
|
endDate: "",
|
2019-08-09 11:14:35 +00:00
|
|
|
endTime: "",
|
|
|
|
hasEndDate: false,
|
|
|
|
hasUsageLimit: false,
|
|
|
|
minCheckoutItemsQuantity: "0",
|
2020-01-09 11:13:24 +00:00
|
|
|
minSpent: "0",
|
2019-08-09 11:14:35 +00:00
|
|
|
requirementsPicker: RequirementsPicker.NONE,
|
2019-06-19 14:40:52 +00:00
|
|
|
startDate: "",
|
2019-08-09 11:14:35 +00:00
|
|
|
startTime: "",
|
|
|
|
type: VoucherTypeEnum.ENTIRE_ORDER,
|
|
|
|
usageLimit: "0",
|
2019-06-19 14:40:52 +00:00
|
|
|
value: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
|
|
|
|
{({ change, data, errors: formErrors, hasChanged, submit }) => (
|
|
|
|
<Container>
|
2019-08-26 13:59:32 +00:00
|
|
|
<AppHeader onBack={onBack}>
|
|
|
|
{intl.formatMessage(sectionNames.vouchers)}
|
|
|
|
</AppHeader>
|
|
|
|
<PageHeader
|
|
|
|
title={intl.formatMessage({
|
|
|
|
defaultMessage: "Create Voucher",
|
|
|
|
description: "page header"
|
|
|
|
})}
|
|
|
|
/>
|
2019-06-19 14:40:52 +00:00
|
|
|
<Grid>
|
|
|
|
<div>
|
|
|
|
<VoucherInfo
|
|
|
|
data={data}
|
|
|
|
errors={formErrors}
|
|
|
|
disabled={disabled}
|
2019-08-09 11:14:35 +00:00
|
|
|
onChange={change}
|
2019-06-19 14:40:52 +00:00
|
|
|
variant="create"
|
2019-08-09 11:14:35 +00:00
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<VoucherTypes
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
errors={formErrors}
|
2019-06-19 14:40:52 +00:00
|
|
|
onChange={change}
|
|
|
|
/>
|
2019-08-09 11:14:35 +00:00
|
|
|
{data.discountType.toString() !== "SHIPPING" ? (
|
|
|
|
<VoucherValue
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
defaultCurrency={defaultCurrency}
|
|
|
|
errors={formErrors}
|
|
|
|
onChange={change}
|
|
|
|
variant="create"
|
|
|
|
/>
|
|
|
|
) : null}
|
2019-06-19 14:40:52 +00:00
|
|
|
<CardSpacer />
|
2019-08-09 11:14:35 +00:00
|
|
|
<VoucherRequirements
|
2019-06-19 14:40:52 +00:00
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
defaultCurrency={defaultCurrency}
|
|
|
|
errors={formErrors}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
2019-08-09 11:14:35 +00:00
|
|
|
<VoucherLimits
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
defaultCurrency={defaultCurrency}
|
|
|
|
errors={formErrors}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<VoucherDates
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
defaultCurrency={defaultCurrency}
|
|
|
|
errors={formErrors}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
2019-06-19 14:40:52 +00:00
|
|
|
</div>
|
|
|
|
</Grid>
|
|
|
|
<SaveButtonBar
|
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
onCancel={onBack}
|
|
|
|
onSave={submit}
|
|
|
|
state={saveButtonBarState}
|
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
VoucherCreatePage.displayName = "VoucherCreatePage";
|
|
|
|
export default VoucherCreatePage;
|