Skip to content

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

Fix review issue

Krzysztof Bialoglowicz169def4875d9
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherInfo/VoucherInfo.tsx b/saleor/static/dashboard-next/discounts/components/VoucherInfo/VoucherInfo.tsx
index a5f0537bd0..6a7aeda38b 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherInfo/VoucherInfo.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherInfo/VoucherInfo.tsx
@@ -15,7 +15,7 @@ interface VoucherInfoProps {
errors: FormErrors<"code">;
disabled: boolean;
variant: "create" | "update";
- onChange: (event: React.ChangeEvent<any>) => void;
+ onChange: (event: any) => void;
}
const VoucherInfo = ({
@@ -25,15 +25,15 @@ const VoucherInfo = ({
variant,
onChange
}: VoucherInfoProps) => {
- const [generatedCode, setGeneratedCode] = React.useState();
const onGenerateCode = () => {
- setGeneratedCode(generateCode(10));
+ onChange({
+ target: {
+ name: "code",
+ value: generateCode(10)
+ }
+ });
};
- const onChangeInput = event => {
- setGeneratedCode(event.target.value);
- onChange(event);
- };
return (
<Card>
<CardTitle
@@ -54,8 +54,8 @@ const VoucherInfo = ({
helperText={errors.code}
name={"code" as keyof FormData}
label={i18n.t("Discount Code")}
- value={generatedCode || data.code}
- onChange={e => onChangeInput(e)}
+ value={data.code}
+ onChange={onChange}
/>
</CardContent>
</Card>
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx b/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx
index 80504d4692..efebc93d25 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx
@@ -1,11 +1,5 @@
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 TextField from "@material-ui/core/TextField";
import * as React from "react";
@@ -23,56 +17,42 @@ interface VoucherLimitsProps {
onChange: (event: React.ChangeEvent<any>) => void;
}
-const styles = (theme: Theme) =>
- createStyles({
- root: {
- display: "grid",
- gridColumnGap: theme.spacing.unit * 2 + "px",
- gridTemplateColumns: "1fr"
- }
- });
-
-const VoucherLimits = withStyles(styles, {
- name: "VoucherLimits"
-})(
- ({
- classes,
- data,
- disabled,
- errors,
- onChange
- }: VoucherLimitsProps & WithStyles<typeof styles>) => {
- return (
- <Card>
- <CardTitle title={i18n.t("Usage Limit ")} />
- <CardContent className={classes.root}>
- <ControlledCheckbox
- checked={data.hasUsageLimit}
- label={i18n.t(
- "Limit number of times this discount can be used in total"
- )}
- name={"hasUsageLimit" as keyof FormData}
+const VoucherLimits = ({
+ data,
+ disabled,
+ errors,
+ onChange
+}: VoucherLimitsProps) => {
+ return (
+ <Card>
+ <CardTitle title={i18n.t("Usage Limit ")} />
+ <CardContent>
+ <ControlledCheckbox
+ checked={data.hasUsageLimit}
+ label={i18n.t(
+ "Limit number of times this discount can be used in total"
+ )}
+ name={"hasUsageLimit" as keyof FormData}
+ onChange={onChange}
+ />
+ {data.hasUsageLimit && (
+ <TextField
+ disabled={disabled}
+ error={!!errors.usageLimit}
+ helperText={errors.usageLimit}
+ label={i18n.t("Limit of Uses")}
+ name={"usageLimit" as keyof FormData}
+ value={data.usageLimit}
onChange={onChange}
+ type="number"
+ inputProps={{
+ min: 0
+ }}
+ fullWidth
/>
- {data.hasUsageLimit && (
- <TextField
- disabled={disabled}
- error={!!errors.usageLimit}
- helperText={errors.usageLimit}
- label={i18n.t("Limit of Uses")}
- name={"usageLimit" as keyof FormData}
- value={data.usageLimit}
- onChange={onChange}
- type="number"
- inputProps={{
- min: 0
- }}
- fullWidth
- />
- )}
- </CardContent>
- </Card>
- );
- }
-);
+ )}
+ </CardContent>
+ </Card>
+ );
+};
export default VoucherLimits;
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx b/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx
index 3a4b858cc2..c1ba452771 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx
@@ -4,7 +4,6 @@ import TextField from "@material-ui/core/TextField";
import * as React from "react";
import CardTitle from "@saleor/components/CardTitle";
-import Grid from "@saleor/components/Grid";
import i18n from "../../../i18n";
import { FormErrors } from "../../../types";
import { FormData } from "../VoucherDetailsPage";
@@ -27,18 +26,16 @@ const VoucherRequirements = ({
<Card>
<CardTitle title={i18n.t("Minimum Requirements")} />
<CardContent>
- <Grid variant="uniform">
- <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
- />
- </Grid>
+ <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
+ />
</CardContent>
</Card>
);
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx b/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx
index 9bfa29e471..8222fe0463 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx
@@ -1,7 +1,7 @@
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import Typography from "@material-ui/core/Typography";
-import * as React from "react";
+import React from "react";
import CardTitle from "@saleor/components/CardTitle";
import ControlledSwitch from "@saleor/components/ControlledSwitch";