Skip to content

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

Fix review issues

Krzysztof Bialoglowiczfb0a086ebc58
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f19f8b91f..ae874a4370 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -78,9 +78,6 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix margin calculations when product/variant price is set to zero - #4170 by @MahmoudRizk
- Fix applying discounts in checkout's subtotal calculation in API - #4192 by @maarcingebala
- Fix GATEWAYS_ENUM to always contain all implemented payment gateways - #4108 by @koradon
-- Fix exploding object select in menu section - #4282 by @dominik-zeglen
-- Add default state to rich text editor - #4281 by @dominik-zeglen
-- Fix rich text editor responsiveness and story - #4295 by @dominik-zeglen
## 2.6.0
diff --git a/saleor/static/dashboard-next/components/RadioGroupField/RadioGroupField.tsx b/saleor/static/dashboard-next/components/RadioGroupField/RadioGroupField.tsx
index b031ddb81f..b87ecda29b 100644
--- a/saleor/static/dashboard-next/components/RadioGroupField/RadioGroupField.tsx
+++ b/saleor/static/dashboard-next/components/RadioGroupField/RadioGroupField.tsx
@@ -24,9 +24,6 @@ const styles = createStyles({
"& > span": {
padding: "6px"
}
- },
- radioLabelHidden: {
- display: "none"
}
});
@@ -34,7 +31,6 @@ interface RadioGroupFieldProps extends WithStyles<typeof styles> {
choices: Array<{
value: string;
label: string | React.ReactNode;
- hidden: boolean;
}>;
className?: string;
disabled?: boolean;
@@ -43,7 +39,7 @@ interface RadioGroupFieldProps extends WithStyles<typeof styles> {
label?: string;
name?: string;
value?: string;
- onChange(event: any);
+ onChange: (event: React.ChangeEvent<any>) => void;
}
export const RadioGroupField = withStyles(styles, {
@@ -80,9 +76,7 @@ export const RadioGroupField = withStyles(styles, {
choices.map(choice => (
<FormControlLabel
value={choice.value}
- className={classNames(classes.radioLabel, {
- [classes.radioLabelHidden]: choice.hidden
- })}
+ className={classes.radioLabel}
control={<Radio color="primary" />}
label={choice.label}
key={choice.value}
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherDates/VoucherDates.tsx b/saleor/static/dashboard-next/discounts/components/VoucherDates/VoucherDates.tsx
index 91a234ec81..7194ba7a4e 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherDates/VoucherDates.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherDates/VoucherDates.tsx
@@ -1,16 +1,11 @@
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";
import CardTitle from "@saleor/components/CardTitle";
import { ControlledCheckbox } from "@saleor/components/ControlledCheckbox";
+import Grid from "@saleor/components/Grid";
import i18n from "../../../i18n";
import { FormErrors } from "../../../types";
import { FormData } from "../VoucherDetailsPage";
@@ -23,88 +18,74 @@ interface VoucherDatesProps {
onChange: (event: React.ChangeEvent<any>) => void;
}
-const styles = (theme: Theme) =>
- createStyles({
- root: {
- display: "grid",
- gridColumnGap: theme.spacing.unit * 2 + "px",
- gridTemplateColumns: "1fr 1fr"
- }
- });
-
-const VoucherDates = withStyles(styles, {
- name: "VoucherDates"
-})(
- ({
- classes,
- data,
- disabled,
- errors,
- onChange
- }: VoucherDatesProps & WithStyles<typeof styles>) => {
- return (
- <Card>
- <CardTitle title={i18n.t("Active Dates")} />
- <CardContent>
- <div className={classes.root}>
+const VoucherDates = ({
+ data,
+ disabled,
+ errors,
+ onChange
+}: VoucherDatesProps) => {
+ return (
+ <Card>
+ <CardTitle title={i18n.t("Active Dates")} />
+ <CardContent>
+ <Grid variant="uniform">
+ <TextField
+ disabled={disabled}
+ error={!!errors.startDate}
+ helperText={errors.startDate}
+ name={"startDate" as keyof FormData}
+ onChange={onChange}
+ label={i18n.t("Start Date")}
+ value={data.startDate}
+ type="date"
+ fullWidth
+ />
+ <TextField
+ disabled={disabled}
+ error={!!errors.startDate}
+ helperText={errors.startDate}
+ name={"startTime" as keyof FormData}
+ onChange={onChange}
+ label={i18n.t("Start Hour")}
+ value={data.startTime}
+ type="time"
+ fullWidth
+ />
+ </Grid>
+ <ControlledCheckbox
+ checked={data.hasEndDate}
+ label={i18n.t("Set end date")}
+ name={"hasEndDate" as keyof FormData}
+ onChange={onChange}
+ />
+ {data.hasEndDate && (
+ <Grid variant="uniform">
<TextField
disabled={disabled}
- error={!!errors.startDate}
- helperText={errors.startDate}
- name={"startDate" as keyof FormData}
+ error={!!errors.endDate}
+ helperText={errors.endDate}
+ name={"endDate" as keyof FormData}
onChange={onChange}
- label={i18n.t("Start Date")}
- value={data.startDate}
+ label={i18n.t("End Date")}
+ value={data.endDate}
type="date"
fullWidth
/>
<TextField
disabled={disabled}
- error={!!errors.startDate}
- helperText={errors.startDate}
- name={"startTime" as keyof FormData}
+ error={!!errors.endDate}
+ helperText={errors.endDate}
+ name={"endTime" as keyof FormData}
onChange={onChange}
- label={i18n.t("Start Hour")}
- value={data.startTime}
+ label={i18n.t("End Hour")}
+ value={data.endTime}
type="time"
fullWidth
/>
- </div>
- <ControlledCheckbox
- checked={data.hasEndDate}
- label={i18n.t("Set end date")}
- name={"hasEndDate" as keyof FormData}
- onChange={onChange}
- />
- {data.hasEndDate ? (
- <div className={classes.root}>
- <TextField
- disabled={disabled}
- error={!!errors.endDate}
- helperText={errors.endDate}
- name={"endDate" as keyof FormData}
- onChange={onChange}
- label={i18n.t("End Date")}
- value={data.endDate}
- type="date"
- fullWidth
- />
- <TextField
- disabled={disabled}
- error={!!errors.endDate}
- helperText={errors.endDate}
- name={"endTime" as keyof FormData}
- onChange={onChange}
- label={i18n.t("End Hour")}
- value={data.endTime}
- type="time"
- fullWidth
- />
- </div>
- ) : null}
- </CardContent>
- </Card>
- );
- }
-);
+ </Grid>
+ )}
+ </CardContent>
+ </Card>
+ );
+};
export default VoucherDates;
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherInfo/VoucherInfo.tsx b/saleor/static/dashboard-next/discounts/components/VoucherInfo/VoucherInfo.tsx
index fd2addf44d..a5f0537bd0 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherInfo/VoucherInfo.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherInfo/VoucherInfo.tsx
@@ -1,17 +1,12 @@
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 React from "react";
import Button from "@material-ui/core/Button";
import CardTitle from "@saleor/components/CardTitle";
import i18n from "../../../i18n";
+import { generateCode } from "../../../misc";
import { FormErrors } from "../../../types";
import { FormData } from "../VoucherDetailsPage";
@@ -19,77 +14,51 @@ interface VoucherInfoProps {
data: FormData;
errors: FormErrors<"code">;
disabled: boolean;
- variant: string;
+ variant: "create" | "update";
onChange: (event: React.ChangeEvent<any>) => void;
}
-const styles = (theme: Theme) =>
- createStyles({
- nameInput: {
- gridColumnEnd: "span 2"
- },
- root: {
- display: "grid",
- gridColumnGap: theme.spacing.unit * 2 + "px",
- gridTemplateColumns: "1fr"
- }
- });
+const VoucherInfo = ({
+ data,
+ disabled,
+ errors,
+ variant,
+ onChange
+}: VoucherInfoProps) => {
+ const [generatedCode, setGeneratedCode] = React.useState();
+ const onGenerateCode = () => {
+ setGeneratedCode(generateCode(10));
+ };
-const VoucherInfo = withStyles(styles, {
- name: "VoucherInfo"
-})(
- ({
- classes,
- data,
- disabled,
- errors,
- variant,
- onChange
- }: VoucherInfoProps & WithStyles<typeof styles>) => {
- const [generateCode, setGenerateCode] = React.useState();
- const onGenerateCode = () => {
- let result = "";
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- for (let i = 0; i < 10; i++) {
- result += characters.charAt(
- Math.floor(Math.random() * characters.length)
- );
- }
- setGenerateCode(result);
- };
-
- const onChangeInput = event => {
- setGenerateCode(event.target.value);
- onChange(event);
- };
- return (
- <Card>
- <CardTitle
- title={i18n.t("General Information")}
- toolbar={
- variant === "create" ? (
- <Button color="primary" onClick={onGenerateCode}>
- {i18n.t("Generate Code")}
- </Button>
- ) : null
- }
+ const onChangeInput = event => {
+ setGeneratedCode(event.target.value);
+ onChange(event);
+ };
+ return (
+ <Card>
+ <CardTitle
+ title={i18n.t("General Information")}
+ toolbar={
+ variant === "create" ? (
+ <Button color="primary" onClick={onGenerateCode}>
+ {i18n.t("Generate Code")}
+ </Button>
+ ) : null
+ }
+ />
+ <CardContent>
+ <TextField
+ disabled={variant === "update" || disabled}
+ error={!!errors.code}
+ fullWidth
+ helperText={errors.code}
+ name={"code" as keyof FormData}
+ label={i18n.t("Discount Code")}
+ value={generatedCode || data.code}
+ onChange={e => onChangeInput(e)}
/>
- <CardContent>
- <div className={classes.root}>
- <TextField
- disabled={variant === "update" || disabled}
- error={!!errors.code}
- fullWidth
- helperText={errors.code}
- name={"code" as keyof FormData}
- label={i18n.t("Discount Code")}
- value={generateCode || data.code}
- onChange={e => onChangeInput(e)}
- />
- </div>
- </CardContent>
- </Card>
- );
- }
-);
+ </CardContent>
+ </Card>
+ );
+};
export default VoucherInfo;
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx b/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx
index ba3f375d6c..80504d4692 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherLimits/VoucherLimits.tsx
@@ -54,7 +54,7 @@ const VoucherLimits = withStyles(styles, {
name={"hasUsageLimit" as keyof FormData}
onChange={onChange}
/>
- {data.hasUsageLimit ? (
+ {data.hasUsageLimit && (
<TextField
disabled={disabled}
error={!!errors.usageLimit}
@@ -69,7 +69,7 @@ const VoucherLimits = withStyles(styles, {
}}
fullWidth
/>
- ) : null}
+ )}
</CardContent>
</Card>
);
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx b/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx
index 43f265c137..3a4b858cc2 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherRequirements/VoucherRequirements.tsx
@@ -1,15 +1,10 @@
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";
import CardTitle from "@saleor/components/CardTitle";
+import Grid from "@saleor/components/Grid";
import i18n from "../../../i18n";
import { FormErrors } from "../../../types";
import { FormData } from "../VoucherDetailsPage";
@@ -18,50 +13,34 @@ interface VoucherRequirementsProps {
data: FormData;
defaultCurrency: string;
disabled: boolean;
- errors: FormErrors<
- | "minAmountSpent"
- >;
+ errors: FormErrors<"minAmountSpent">;
onChange: (event: React.ChangeEvent<any>) => void;
}
-const styles = (theme: Theme) =>
- createStyles({
- root: {
- display: "grid",
- gridColumnGap: theme.spacing.unit * 2 + "px",
- gridTemplateColumns: "1fr 1fr"
- }
- });
-
-const VoucherRequirements = withStyles(styles, {
- name: "VoucherRequirements"
-})(
- ({
- classes,
- data,
- disabled,
- errors,
- onChange
- }: VoucherRequirementsProps & WithStyles<typeof styles>) => {
- return (
- <Card>
- <CardTitle title={i18n.t("Minimum Requirements")} />
- <CardContent>
- <div className={classes.root}>
- <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
- />
- </div>
- </CardContent>
- </Card>
- );
- }
-);
+const VoucherRequirements = ({
+ data,
+ disabled,
+ errors,
+ onChange
+}: VoucherRequirementsProps) => {
+ return (
+ <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>
+ </CardContent>
+ </Card>
+ );
+};
export default VoucherRequirements;
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherTypes/VoucherTypes.tsx b/saleor/static/dashboard-next/discounts/components/VoucherTypes/VoucherTypes.tsx
index 556f72e9b8..53dc48af30 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherTypes/VoucherTypes.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherTypes/VoucherTypes.tsx
@@ -1,14 +1,9 @@
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 Grid from "@saleor/components/Grid";
import RadioGroupField from "@saleor/components/RadioGroupField";
import i18n from "../../../i18n";
import { FormErrors } from "../../../types";
@@ -22,68 +17,47 @@ interface VoucherTypesProps {
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,
- onChange
- }: VoucherTypesProps & WithStyles<typeof styles>) => {
- const voucherTypeChoices = Object.values(DiscountValueTypeEnum).map(
- type => {
- switch (type.toString()) {
- case DiscountValueTypeEnum.FIXED:
- return {
- hidden: false,
- label: i18n.t("Fixed Amount"),
- value: type
- };
- case DiscountValueTypeEnum.PERCENTAGE:
- return {
- hidden: false,
- label: i18n.t("Percentage"),
- value: type
- };
- }
- }
- );
-
- voucherTypeChoices.push({
+const VoucherTypes = ({
+ data,
+ disabled,
+ errors,
+ onChange
+}: VoucherTypesProps) => {
+ const voucherTypeChoices = [
+ {
+ hidden: false,
+ label: i18n.t("Fixed Amount"),
+ value: DiscountValueTypeEnum.FIXED
+ },
+ {
+ hidden: false,
+ label: i18n.t("Percentage"),
+ value: DiscountValueTypeEnum.PERCENTAGE
+ },
+ {
hidden: false,
label: i18n.t("Free Shipping"),
value: "SHIPPING"
- });
+ }
+ ];
- return (
- <Card>
- <CardTitle title={i18n.t("Discount Type")} />
- <CardContent>
- <div className={classes.root}>
- <RadioGroupField
- choices={voucherTypeChoices}
- disabled={disabled}
- error={!!errors.discountType}
- hint={errors.discountType}
- name={"discountType" as keyof FormData}
- value={data.discountType}
- onChange={onChange}
- />
- </div>
- </CardContent>
- </Card>
- );
- }
-);
+ return (
+ <Card>
+ <CardTitle title={i18n.t("Discount Type")} />
+ <CardContent>
+ <Grid variant="uniform">
+ <RadioGroupField
+ choices={voucherTypeChoices}
+ disabled={disabled}
+ error={!!errors.discountType}
+ hint={errors.discountType}
+ name={"discountType" as keyof FormData}
+ value={data.discountType}
+ onChange={onChange}
+ />
+ </Grid>
+ </CardContent>
+ </Card>
+ );
+};
export default VoucherTypes;
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx b/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx
index 888175e3ce..9bfa29e471 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherValue/VoucherValue.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 Typography from "@material-ui/core/Typography";
import * as React from "react";
@@ -30,107 +24,89 @@ interface VoucherValueProps {
onChange: (event: React.ChangeEvent<any>) => void;
}
-export enum VoucherTypeEnum {
+export enum VoucherType {
ENTIRE_ORDER = "ENTIRE_ORDER",
- SHIPPING = "SHIPPING",
SPECIFIC_PRODUCT = "SPECIFIC_PRODUCT"
}
-const styles = (theme: Theme) =>
- createStyles({
- root: {
- display: "grid",
- gridColumnGap: theme.spacing.unit * 2 + "px",
- gridTemplateColumns: "1fr"
- }
- });
+const VoucherValue = ({
+ data,
+ defaultCurrency,
+ disabled,
+ errors,
+ variant,
+ onChange
+}: VoucherValueProps) => {
+ const translatedVoucherTypes = translateVoucherTypes();
+ const voucherTypeChoices = Object.values(VoucherType).map(type => ({
+ label: translatedVoucherTypes[type],
+ value: type
+ }));
-const VoucherValue = withStyles(styles, {
- name: "VoucherValue"
-})(
- ({
- classes,
- data,
- defaultCurrency,
- disabled,
- errors,
- variant,
- onChange
- }: VoucherValueProps & WithStyles<typeof styles>) => {
- const translatedVoucherTypes = translateVoucherTypes();
- const voucherTypeChoices = Object.values(VoucherTypeEnum).map(type => ({
- hidden: type === "SHIPPING" ? true : false,
- label: translatedVoucherTypes[type],
- value: type
- }));
-
- return (
- <Card>
- <CardTitle title={i18n.t("Value")} />
- <CardContent>
- <div className={classes.root}>
- <TextFieldWithChoice
+ return (
+ <Card>
+ <CardTitle title={i18n.t("Value")} />
+ <CardContent>
+ <TextFieldWithChoice
+ disabled={disabled}
+ error={!!errors.discountValue}
+ ChoiceProps={{
+ label:
+ data.discountType === DiscountValueTypeEnum.FIXED
+ ? defaultCurrency
+ : "%",
+ name: "discountType" as keyof FormData,
+ values: null
+ }}
+ helperText={errors.discountValue}
+ name={"value" as keyof FormData}
+ onChange={onChange}
+ label={i18n.t("Discount Value")}
+ value={data.value}
+ type="number"
+ fullWidth
+ inputProps={{
+ min: 0
+ }}
+ />
+ <FormSpacer />
+ {variant === "update" ? (
+ <>
+ <RadioGroupField
+ choices={voucherTypeChoices}
disabled={disabled}
- error={!!errors.discountValue}
- ChoiceProps={{
- label:
- data.discountType === DiscountValueTypeEnum.FIXED
- ? defaultCurrency
- : "%",
- name: "discountType" as keyof FormData,
- values: null
- }}
- helperText={errors.discountValue}
- name={"value" as keyof FormData}
+ error={!!errors.type}
+ hint={errors.type}
+ label={i18n.t("Discount Specific Information")}
+ name={"type" as keyof FormData}
+ value={data.type}
onChange={onChange}
- label={i18n.t("Discount Value")}
- value={data.value}
- type="number"
- fullWidth
- inputProps={{
- min: 0
- }}
/>
<FormSpacer />
- {variant === "update" ? (
- <>
- <RadioGroupField
- choices={voucherTypeChoices}
- disabled={disabled}
- error={!!errors.type}
- hint={errors.type}
- label="Discount Specific Information"
- name={"type" as keyof FormData}
- value={data.type}
- onChange={onChange}
- />
- <FormSpacer />
- </>
- ) : null}
- <Hr />
- <FormSpacer />
- <ControlledSwitch
- checked={data.applyOncePerOrder}
- label={
- <>
- {i18n.t("Only once per order", {
- context: "voucher application"
- })}
- <Typography variant="caption">
- {i18n.t(
- "If this option is disabled, discount will be counted for every eligible product"
- )}
- </Typography>
- </>
- }
- onChange={onChange}
- name={"applyOncePerOrder" as keyof FormData}
- disabled={disabled}
- />
- </div>
- </CardContent>
- </Card>
- );
- }
-);
+ </>
+ ) : null}
+ <Hr />
+ <FormSpacer />
+ <ControlledSwitch
+ checked={data.applyOncePerOrder}
+ label={
+ <>
+ {i18n.t("Only once per order", {
+ context: "voucher application"
+ })}
+ <Typography variant="caption">
+ {i18n.t(
+ "If this option is disabled, discount will be counted for every eligible product"
+ )}
+ </Typography>
+ </>
+ }
+ onChange={onChange}
+ name={"applyOncePerOrder" as keyof FormData}
+ disabled={disabled}
+ />
+ </CardContent>
+ </Card>
+ );
+};
export default VoucherValue;
diff --git a/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx b/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx
index 42b10c6960..caa3d563fe 100644
--- a/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx
+++ b/saleor/static/dashboard-next/discounts/views/VoucherCreate.tsx
@@ -5,7 +5,7 @@ import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import useShop from "@saleor/hooks/useShop";
import i18n from "../../i18n";
-import { connectDateTime, decimal, getMutationState, maybe } from "../../misc";
+import { decimal, getMutationState, joinDateTime, maybe } from "../../misc";
import {
DiscountValueTypeEnum,
VoucherTypeEnum
@@ -62,12 +62,9 @@ export const VoucherDetails: React.StatelessComponent = () => {
formData.discountType.toString() === "SHIPPING"
? DiscountValueTypeEnum.PERCENTAGE
: formData.discountType,
- endDate: connectDateTime(
- formData.endDate,
- formData.endTime
- ),
+ endDate: joinDateTime(formData.endDate, formData.endTime),
minAmountSpent: formData.minAmountSpent,
- startDate: connectDateTime(
+ startDate: joinDateTime(
formData.startDate,
formData.startTime
),
diff --git a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
index fd7777bd48..680d0cc36c 100644
--- a/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
+++ b/saleor/static/dashboard-next/discounts/views/VoucherDetails.tsx
@@ -21,7 +21,7 @@ import SearchCategories from "../../containers/SearchCategories";
import SearchCollections from "../../containers/SearchCollections";
import SearchProducts from "../../containers/SearchProducts";
import i18n from "../../i18n";
-import { connectDateTime, decimal, getMutationState, maybe } from "../../misc";
+import { decimal, getMutationState, joinDateTime, maybe } from "../../misc";
import { productUrl } from "../../products/urls";
import {
DiscountValueTypeEnum,
@@ -310,7 +310,7 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
activeTab={params.activeTab}
onBack={() => navigate(voucherListUrl())}
onTabClick={changeTab}
- onSubmit={formData => {
+ onSubmit={formData =>
voucherUpdate({
variables: {
id,
@@ -327,25 +327,25 @@ export const VoucherDetails: React.StatelessComponent<VoucherDetailsProps> = ({
"SHIPPING"
? DiscountValueTypeEnum.PERCENTAGE
: formData.discountType,
- endDate: connectDateTime(
+ endDate: joinDateTime(
formData.endDate,
formData.endTime
),
minAmountSpent: formData.minAmountSpent,
- startDate: connectDateTime(
+ startDate: joinDateTime(
formData.startDate,
formData.startTime
),
type:
formData.discountType.toString() ===
"SHIPPING"
- ? VoucherTypeEnum.ENTIRE_ORDER
+ ? VoucherTypeEnum.SHIPPING
: formData.type,
usageLimit: formData.usageLimit
}
}
- });
- }}
+ })
+ }
onRemove={() => openModal("remove")}
saveButtonBarState={formTransitionState}
categoryListToolbar={
diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.ts
index 07b5ee2370..c89827576f 100644
--- a/saleor/static/dashboard-next/misc.ts
+++ b/saleor/static/dashboard-next/misc.ts
@@ -237,7 +237,7 @@ export function stopPropagation(cb: () => void) {
};
}
-export function connectDateTime(date: string, time?: string) {
+export function joinDateTime(date: string, time?: string) {
if (!date) {
return null;
}
@@ -253,6 +253,7 @@ export function splitDateTime(dateTime: string) {
time: ""
};
}
+ // Default html input format YYYY-MM-DD HH:mm
const splitDateTime = moment(dateTime)
.format("YYYY-MM-DD HH:mm")
.split(" ");
@@ -261,3 +262,12 @@ export function splitDateTime(dateTime: string) {
time: splitDateTime[1]
};
}
+
+export function generateCode(charNum: number) {
+ let result = "";
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ for (let i = 0; i < charNum; i++) {
+ result += characters.charAt(Math.floor(Math.random() * characters.length));
+ }
+ return result;
+}