2019-06-19 14:40:52 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
|
|
|
import TextField from "@material-ui/core/TextField";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-26 17:48:13 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import slugify from "slugify";
|
|
|
|
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import { FormData } from "../PageDetailsPage";
|
|
|
|
|
|
|
|
export interface PageSlugProps {
|
|
|
|
data: FormData;
|
|
|
|
disabled: boolean;
|
|
|
|
errors: Partial<Record<"slug", string>>;
|
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PageSlug: React.StatelessComponent<PageSlugProps> = ({
|
|
|
|
data,
|
|
|
|
disabled,
|
|
|
|
errors,
|
|
|
|
onChange
|
2019-08-26 17:48:13 +00:00
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardTitle
|
|
|
|
title={intl.formatMessage({
|
|
|
|
defaultMessage: "URL"
|
|
|
|
})}
|
2019-06-19 14:40:52 +00:00
|
|
|
/>
|
2019-08-26 17:48:13 +00:00
|
|
|
<CardContent>
|
|
|
|
<TextField
|
|
|
|
name={"slug" as keyof FormData}
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.slug}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Slug",
|
|
|
|
description: "page internal name"
|
|
|
|
})}
|
|
|
|
helperText={
|
|
|
|
errors.slug ||
|
|
|
|
intl.formatMessage({
|
|
|
|
defaultMessage:
|
|
|
|
"If empty, URL will be autogenerated from Page Name"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
placeholder={slugify(data.title)}
|
|
|
|
value={data.slug}
|
|
|
|
onChange={onChange}
|
|
|
|
fullWidth
|
|
|
|
/>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
PageSlug.displayName = "PageSlug";
|
|
|
|
export default PageSlug;
|