Skip to content

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

Create slug when not supplied

dominik-zeglen055ab23a3f79
diff --git a/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx b/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx
index 3036994128..85840b2250 100644
--- a/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx
+++ b/saleor/static/dashboard-next/attributes/components/AttributeDetails/AttributeDetails.tsx
@@ -2,6 +2,7 @@ import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import TextField from "@material-ui/core/TextField";
import React from "react";
+import slugify from "slugify";
import CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer";
@@ -56,6 +57,7 @@ const AttributeDetails: React.FC<AttributeDetailsProps> = ({
error={!!errors.slug}
label={i18n.t("Attribute Code")}
name={"slug" as keyof AttributePageFormData}
+ placeholder={slugify(data.name).toLowerCase()}
fullWidth
helperText={
errors.slug ||
diff --git a/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx b/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx
index d101b84446..b15cb228db 100644
--- a/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx
+++ b/saleor/static/dashboard-next/attributes/components/AttributePage/AttributePage.tsx
@@ -1,4 +1,5 @@
import React from "react";
+import slugify from "slugify";
import AppHeader from "@saleor/components/AppHeader";
import CardSpacer from "@saleor/components/CardSpacer";
@@ -90,8 +91,14 @@ const AttributePage: React.FC<AttributePageProps> = ({
visibleInStorefront: maybe(() => attribute.visibleInStorefront, false)
};
+ const handleSubmit = (data: AttributePageFormData) =>
+ onSubmit({
+ ...data,
+ slug: data.slug || slugify(data.name).toLowerCase()
+ });
+
return (
- <Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
+ <Form errors={errors} initial={initialForm} onSubmit={handleSubmit}>
{({ change, errors: formErrors, data, submit }) => (
<Container>
<AppHeader onBack={onBack}>{i18n.t("Attributes")}</AppHeader>