Skip to content

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

Improve form error handling (#1976)

Dominik Żegleńfd177cc17bd2
diff --git a/saleor/static/dashboard-next/components/RichTextEditor.tsx b/saleor/static/dashboard-next/components/RichTextEditor.tsx
index 3d7d4dc78a..39eeff1e55 100644
--- a/saleor/static/dashboard-next/components/RichTextEditor.tsx
+++ b/saleor/static/dashboard-next/components/RichTextEditor.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
interface RichTextEditorProps {
defaultValue?: string;
+ error?: boolean;
fullWidth?: boolean;
helperText: string;
label: string;
@@ -14,6 +15,7 @@ interface RichTextEditorProps {
export const RichTextEditor: React.StatelessComponent<RichTextEditorProps> = ({
defaultValue,
+ error,
fullWidth,
helperText,
label,
@@ -21,7 +23,7 @@ export const RichTextEditor: React.StatelessComponent<RichTextEditorProps> = ({
onChange,
value
}) => (
- <FormControl style={fullWidth ? { width: "100%" } : {}}>
+ <FormControl style={fullWidth ? { width: "100%" } : {}} error={error}>
<InputLabel shrink={!!(value || defaultValue)}>{label}</InputLabel>
<Input
multiline
diff --git a/saleor/static/dashboard-next/page/components/PageBaseForm.tsx b/saleor/static/dashboard-next/page/components/PageBaseForm.tsx
index ee1d43f6c9..47dc718fb5 100644
--- a/saleor/static/dashboard-next/page/components/PageBaseForm.tsx
+++ b/saleor/static/dashboard-next/page/components/PageBaseForm.tsx
@@ -66,6 +66,7 @@ export const PageBaseForm = decorate<PageBaseFormComponentProps>(
? classes.addHelperTextPadding
: ""
}
+ error={!!(errorList && errorList.title)}
helperText={errorList && errorList.title ? errorList.title : ""}
fullWidth
/>
@@ -82,6 +83,7 @@ export const PageBaseForm = decorate<PageBaseFormComponentProps>(
})
}
onChange={onChange}
+ error={!!(errorList && errorList.content)}
fullWidth
/>
</Grid>
@@ -98,6 +100,7 @@ export const PageBaseForm = decorate<PageBaseFormComponentProps>(
})
}
onChange={onChange}
+ error={!!(errorList && errorList.slug)}
fullWidth
/>
<FormSpacer />
@@ -113,6 +116,7 @@ export const PageBaseForm = decorate<PageBaseFormComponentProps>(
helperText={
errorList && errorList.availableOn ? errorList.availableOn : ""
}
+ error={!!(errorList && errorList.availableOn)}
/>
<FormSpacer />
{created && (