Skip to content

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

Add filter tab name as reqiured

Krzysztof Bialoglowicza3ca881ccba9
diff --git a/saleor/static/dashboard-next/components/SaveFilterTabDialog/SaveFilterTabDialog.tsx b/saleor/static/dashboard-next/components/SaveFilterTabDialog/SaveFilterTabDialog.tsx
index 4980a9540c..0b257873d2 100644
--- a/saleor/static/dashboard-next/components/SaveFilterTabDialog/SaveFilterTabDialog.tsx
+++ b/saleor/static/dashboard-next/components/SaveFilterTabDialog/SaveFilterTabDialog.tsx
@@ -30,44 +30,58 @@ const SaveFilterTabDialog: React.FC<SaveFilterTabDialogProps> = ({
onClose,
onSubmit,
open
-}) => (
- <Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
- <DialogTitle>
- {i18n.t("Save Custom Search", {
- context: "save filter tab"
- })}
- </DialogTitle>
- <Form initial={initialForm} onSubmit={onSubmit}>
- {({ change, data, submit }) => (
- <>
- <DialogContent>
- <TextField
- fullWidth
- label={i18n.t("Search Name", {
- context: "save search"
- })}
- name={"name" as keyof SaveFilterTabDialogFormData}
- value={data.name}
- onChange={change}
- />
- </DialogContent>
- <DialogActions>
- <Button onClick={onClose}>
- {i18n.t("Cancel", { context: "button" })}
- </Button>
- <ConfirmButton
- transitionState={confirmButtonState}
- color="primary"
- variant="contained"
- onClick={submit}
- >
- {i18n.t("Save")}
- </ConfirmButton>
- </DialogActions>
- </>
- )}
- </Form>
- </Dialog>
-);
+}) => {
+ const [errors, setErrors] = React.useState(false);
+ const handleErrors = data => {
+ if (data.name.length) {
+ onSubmit(data);
+ setErrors(false);
+ } else {
+ setErrors(true);
+ }
+ };
+
+ return (
+ <Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
+ <DialogTitle>
+ {i18n.t("Save Custom Search", {
+ context: "save filter tab"
+ })}
+ </DialogTitle>
+ <Form initial={initialForm} onSubmit={handleErrors}>
+ {({ change, data, submit }) => (
+ <>
+ <DialogContent>
+ <TextField
+ fullWidth
+ label={i18n.t("Search Name", {
+ context: "save search"
+ })}
+ name={"name" as keyof SaveFilterTabDialogFormData}
+ value={data.name}
+ onChange={change}
+ error={errors}
+ helperText={errors ? "This field is required" : null}
+ />
+ </DialogContent>
+ <DialogActions>
+ <Button onClick={onClose}>
+ {i18n.t("Cancel", { context: "button" })}
+ </Button>
+ <ConfirmButton
+ transitionState={confirmButtonState}
+ color="primary"
+ variant="contained"
+ onClick={submit}
+ >
+ {i18n.t("Save")}
+ </ConfirmButton>
+ </DialogActions>
+ </>
+ )}
+ </Form>
+ </Dialog>
+ );
+};
SaveFilterTabDialog.displayName = "SaveFilterTabDialog";
export default SaveFilterTabDialog;