2019-08-09 10:17:04 +00:00
|
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
|
|
|
|
import TextField from "@material-ui/core/TextField";
|
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
2019-09-09 09:28:06 +00:00
|
|
|
|
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
|
|
|
|
import SingleSelectField from "@saleor/components/SingleSelectField";
|
2020-11-19 14:42:14 +00:00
|
|
|
|
import { AttributeErrorFragment } from "@saleor/fragments/types/AttributeErrorFragment";
|
2019-08-16 11:47:30 +00:00
|
|
|
|
import { commonMessages } from "@saleor/intl";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";
|
2020-11-19 14:42:14 +00:00
|
|
|
|
import { getFormErrors } from "@saleor/utils/errors";
|
|
|
|
|
import getAttributeErrorMessage from "@saleor/utils/errors/attribute";
|
2020-05-14 09:30:32 +00:00
|
|
|
|
import React from "react";
|
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
import slugify from "slugify";
|
|
|
|
|
|
2020-03-24 14:05:26 +00:00
|
|
|
|
import { getAttributeSlugErrorMessage } from "../../errors";
|
2020-05-14 09:30:32 +00:00
|
|
|
|
import { AttributePageFormData } from "../AttributePage";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
|
|
|
|
|
export interface AttributeDetailsProps {
|
|
|
|
|
canChangeType: boolean;
|
|
|
|
|
data: AttributePageFormData;
|
|
|
|
|
disabled: boolean;
|
2020-11-19 14:42:14 +00:00
|
|
|
|
errors: AttributeErrorFragment[];
|
2019-08-09 10:17:04 +00:00
|
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const AttributeDetails: React.FC<AttributeDetailsProps> = ({
|
|
|
|
|
canChangeType,
|
|
|
|
|
data,
|
|
|
|
|
disabled,
|
|
|
|
|
errors,
|
|
|
|
|
onChange
|
2019-08-16 11:47:30 +00:00
|
|
|
|
}) => {
|
|
|
|
|
const intl = useIntl();
|
|
|
|
|
const inputTypeChoices = [
|
|
|
|
|
{
|
2019-08-22 16:25:55 +00:00
|
|
|
|
label: intl.formatMessage({
|
|
|
|
|
defaultMessage: "Dropdown",
|
|
|
|
|
description: "product attribute type"
|
|
|
|
|
}),
|
2019-08-16 11:47:30 +00:00
|
|
|
|
value: AttributeInputTypeEnum.DROPDOWN
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-08-22 16:25:55 +00:00
|
|
|
|
label: intl.formatMessage({
|
|
|
|
|
defaultMessage: "Multiple Select",
|
|
|
|
|
description: "product attribute type"
|
|
|
|
|
}),
|
2019-08-16 11:47:30 +00:00
|
|
|
|
value: AttributeInputTypeEnum.MULTISELECT
|
2020-12-16 10:53:28 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: intl.formatMessage({
|
|
|
|
|
defaultMessage: "File",
|
|
|
|
|
description: "file attribute type"
|
|
|
|
|
}),
|
|
|
|
|
value: AttributeInputTypeEnum.FILE
|
2019-08-16 11:47:30 +00:00
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2020-03-24 14:05:26 +00:00
|
|
|
|
const formErrors = getFormErrors(["name", "slug", "inputType"], errors);
|
|
|
|
|
|
2019-08-16 11:47:30 +00:00
|
|
|
|
return (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardTitle
|
2019-08-20 09:17:06 +00:00
|
|
|
|
title={intl.formatMessage(commonMessages.generalInformations)}
|
2019-08-09 10:17:04 +00:00
|
|
|
|
/>
|
2019-08-16 11:47:30 +00:00
|
|
|
|
<CardContent>
|
|
|
|
|
<TextField
|
|
|
|
|
disabled={disabled}
|
2020-03-24 14:05:26 +00:00
|
|
|
|
error={!!formErrors.name}
|
2019-08-22 16:25:55 +00:00
|
|
|
|
label={intl.formatMessage({
|
|
|
|
|
defaultMessage: "Default Label",
|
|
|
|
|
description: "attribute's label"
|
|
|
|
|
})}
|
2019-08-16 11:47:30 +00:00
|
|
|
|
name={"name" as keyof AttributePageFormData}
|
|
|
|
|
fullWidth
|
2020-11-19 14:42:14 +00:00
|
|
|
|
helperText={getAttributeErrorMessage(formErrors.name, intl)}
|
2019-08-16 11:47:30 +00:00
|
|
|
|
value={data.name}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
/>
|
|
|
|
|
<FormSpacer />
|
|
|
|
|
<TextField
|
|
|
|
|
disabled={disabled}
|
2020-03-24 14:05:26 +00:00
|
|
|
|
error={!!formErrors.slug}
|
2019-08-22 16:25:55 +00:00
|
|
|
|
label={intl.formatMessage({
|
|
|
|
|
defaultMessage: "Attribute Code",
|
|
|
|
|
description: "attribute's slug short code label"
|
|
|
|
|
})}
|
2019-08-16 11:47:30 +00:00
|
|
|
|
name={"slug" as keyof AttributePageFormData}
|
|
|
|
|
placeholder={slugify(data.name).toLowerCase()}
|
|
|
|
|
fullWidth
|
|
|
|
|
helperText={
|
2020-03-24 14:05:26 +00:00
|
|
|
|
getAttributeSlugErrorMessage(formErrors.slug, intl) ||
|
2019-08-22 16:25:55 +00:00
|
|
|
|
intl.formatMessage({
|
|
|
|
|
defaultMessage:
|
2019-08-16 11:47:30 +00:00
|
|
|
|
"This is used internally. Make sure you don’t use spaces",
|
2019-08-22 16:25:55 +00:00
|
|
|
|
description: "attribute slug input field helper text"
|
|
|
|
|
})
|
2019-08-16 11:47:30 +00:00
|
|
|
|
}
|
|
|
|
|
value={data.slug}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
/>
|
|
|
|
|
<FormSpacer />
|
|
|
|
|
<SingleSelectField
|
|
|
|
|
choices={inputTypeChoices}
|
|
|
|
|
disabled={disabled || !canChangeType}
|
2020-03-24 14:05:26 +00:00
|
|
|
|
error={!!formErrors.inputType}
|
2020-11-19 14:42:14 +00:00
|
|
|
|
hint={getAttributeErrorMessage(formErrors.inputType, intl)}
|
2019-08-22 16:25:55 +00:00
|
|
|
|
label={intl.formatMessage({
|
|
|
|
|
defaultMessage: "Catalog Input type for Store Owner",
|
|
|
|
|
description: "attribute's editor component"
|
|
|
|
|
})}
|
2019-08-16 11:47:30 +00:00
|
|
|
|
name="inputType"
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
value={data.inputType}
|
|
|
|
|
/>
|
|
|
|
|
<FormSpacer />
|
2019-09-09 09:28:06 +00:00
|
|
|
|
<ControlledCheckbox
|
2019-09-11 14:24:24 +00:00
|
|
|
|
name={"valueRequired" as keyof AttributePageFormData}
|
2019-08-22 16:25:55 +00:00
|
|
|
|
label={intl.formatMessage({
|
|
|
|
|
defaultMessage: "Value Required",
|
|
|
|
|
description: "check to require attribute to have value"
|
|
|
|
|
})}
|
2019-09-09 09:28:06 +00:00
|
|
|
|
checked={data.valueRequired}
|
2019-08-16 11:47:30 +00:00
|
|
|
|
onChange={onChange}
|
2019-09-09 09:28:06 +00:00
|
|
|
|
disabled={disabled}
|
2019-08-16 11:47:30 +00:00
|
|
|
|
/>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
};
|
2019-08-09 10:17:04 +00:00
|
|
|
|
AttributeDetails.displayName = "AttributeDetails";
|
|
|
|
|
export default AttributeDetails;
|