Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add VoucherType component
Krzysztof Bialoglowicz8c96d2642314
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherTypes/VoucherTypes.tsx b/saleor/static/dashboard-next/discounts/components/VoucherTypes/VoucherTypes.tsxnew file mode 100644index 0000000000..e553885534--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/VoucherTypes/VoucherTypes.tsx@@ -0,0 +1,73 @@+import Card from "@material-ui/core/Card";+import CardContent from "@material-ui/core/CardContent";+import {+ createStyles,+ Theme,+ withStyles,+ WithStyles+} from "@material-ui/core/styles";+import * as React from "react";++import CardTitle from "@saleor/components/CardTitle";+import RadioGroupField from "@saleor/components/RadioGroupField";+import i18n from "../../../i18n";+import { FormErrors } from "../../../types";+import { VoucherType } from "../../../types/globalTypes";+import { translateVoucherTypes } from "../../translations";+import { FormData } from "../VoucherDetailsPage";++interface VoucherTypesProps {+ data: FormData;+ errors: FormErrors<"name" | "code" | "type">;+ disabled: boolean;+ variant: "create" | "update";+ onChange: (event: React.ChangeEvent<any>) => void;+}++const styles = (theme: Theme) =>+ createStyles({+ root: {+ display: "grid",+ gridColumnGap: theme.spacing.unit * 2 + "px",+ gridTemplateColumns: "1fr"+ }+ });++const VoucherTypes = withStyles(styles, {+ name: "VoucherTypes"+})(+ ({+ classes,+ data,+ disabled,+ errors,+ variant,+ onChange+ }: VoucherTypesProps & WithStyles<typeof styles>) => {+ const translatedVoucherTypes = translateVoucherTypes();+ const voucherTypeChoices = Object.values(VoucherType).map(type => ({+ label: translatedVoucherTypes[type],+ value: type+ }));++ return (+ <Card>+ <CardTitle title={i18n.t("Discount Type")} />+ <CardContent>+ <div className={classes.root}>+ <RadioGroupField+ choices={voucherTypeChoices}+ disabled={disabled}+ error={!!errors.type}+ hint={errors.type}+ name={"type" as keyof FormData}+ value={data.type}+ onChange={onChange}+ />+ </div>+ </CardContent>+ </Card>+ );+ }+);+export default VoucherTypes;diff --git a/saleor/static/dashboard-next/discounts/components/VoucherTypes/index.ts b/saleor/static/dashboard-next/discounts/components/VoucherTypes/index.tsnew file mode 100644index 0000000000..89168c9e73--- /dev/null+++ b/saleor/static/dashboard-next/discounts/components/VoucherTypes/index.ts@@ -0,0 +1,2 @@+export { default } from "./VoucherTypes";+export * from "./VoucherTypes";