Skip to content

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

Refactor code to use FormErrors type

dominik-zeglen4b8213d95534
diff --git a/saleor/static/dashboard-next/discounts/components/SalePricing/SalePricing.tsx b/saleor/static/dashboard-next/discounts/components/SalePricing/SalePricing.tsx
index 670a0dec12..54916abc8a 100644
--- a/saleor/static/dashboard-next/discounts/components/SalePricing/SalePricing.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SalePricing/SalePricing.tsx
@@ -14,6 +14,7 @@ import CardTitle from "../../../components/CardTitle";
import Hr from "../../../components/Hr";
import TextFieldWithChoice from "../../../components/TextFieldWithChoice";
import i18n from "../../../i18n";
+import { FormErrors } from "../../../types";
import { SaleType } from "../../../types/globalTypes";
import { FormData } from "../SaleDetailsPage";
@@ -21,11 +22,7 @@ export interface SalePricingProps {
data: FormData;
defaultCurrency: string;
disabled: boolean;
- errors: {
- startDate?: string;
- endDate?: string;
- value?: string;
- };
+ errors: FormErrors<"startDate" | "endDate" | "value">;
onChange: (event: React.ChangeEvent<any>) => void;
}
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherOptions/VoucherOptions.tsx b/saleor/static/dashboard-next/discounts/components/VoucherOptions/VoucherOptions.tsx
index 4ac5eab70b..a4b5fc2708 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherOptions/VoucherOptions.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherOptions/VoucherOptions.tsx
@@ -16,6 +16,7 @@ import FormSpacer from "../../../components/FormSpacer";
import Hr from "../../../components/Hr";
import TextFieldWithChoice from "../../../components/TextFieldWithChoice";
import i18n from "../../../i18n";
+import { FormErrors } from "../../../types";
import { VoucherDiscountValueType } from "../../../types/globalTypes";
import { FormData } from "../VoucherDetailsPage";
@@ -23,14 +24,14 @@ interface VoucherOptionsProps {
data: FormData;
defaultCurrency: string;
disabled: boolean;
- errors: Partial<{
- discountType: string;
- endDate: string;
- minAmountSpent: string;
- startDate: string;
- usageLimit: string;
- value: string;
- }>;
+ errors: FormErrors<
+ | "discountType"
+ | "discountValue"
+ | "endDate"
+ | "minAmountSpent"
+ | "startDate"
+ | "usageLimit"
+ >;
onChange: (event: React.ChangeEvent<any>) => void;
}
@@ -59,6 +60,7 @@ const VoucherOptions = withStyles(styles, {
<CardContent className={classes.root}>
<TextFieldWithChoice
disabled={disabled}
+ error={!!errors.discountValue}
ChoiceProps={{
label:
data.discountType === VoucherDiscountValueType.FIXED
@@ -76,8 +78,7 @@ const VoucherOptions = withStyles(styles, {
}
]
}}
- error={!!errors.value}
- helperText={errors.value}
+ helperText={errors.discountValue}
name={"value" as keyof FormData}
onChange={onChange}
label={i18n.t("Discount Value")}