saleor-dashboard/src/attributes/components/AttributeDetails/AttributeDetails.tsx

114 lines
3.6 KiB
TypeScript
Raw Normal View History

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 React from "react";
2019-08-16 13:55:04 +00:00
import { useIntl } from "react-intl";
2019-08-09 10:17:04 +00:00
import slugify from "slugify";
import CardTitle from "@saleor/components/CardTitle";
import ControlledSwitch from "@saleor/components/ControlledSwitch";
import FormSpacer from "@saleor/components/FormSpacer";
import SingleSelectField from "@saleor/components/SingleSelectField";
import { commonMessages } from "@saleor/intl";
2019-08-09 10:17:04 +00:00
import { FormErrors } from "@saleor/types";
import { AttributeInputTypeEnum } from "@saleor/types/globalTypes";
import { AttributePageFormData } from "../AttributePage";
export interface AttributeDetailsProps {
canChangeType: boolean;
data: AttributePageFormData;
disabled: boolean;
errors: FormErrors<"name" | "slug" | "inputType">;
onChange: (event: React.ChangeEvent<any>) => void;
}
const AttributeDetails: React.FC<AttributeDetailsProps> = ({
canChangeType,
data,
disabled,
errors,
onChange
}) => {
const intl = useIntl();
const inputTypeChoices = [
{
2019-08-22 16:19:16 +00:00
label: intl.formatMessage({defaultMessage: "Dropdown",
2019-08-20 09:17:06 +00:00
description: "product attribute type",
2019-08-22 16:19:16 +00:00
}),
value: AttributeInputTypeEnum.DROPDOWN
},
{
2019-08-22 16:19:16 +00:00
label: intl.formatMessage({defaultMessage: "Multiple Select",
2019-08-20 09:17:06 +00:00
description: "product attribute type",
2019-08-22 16:19:16 +00:00
}),
value: AttributeInputTypeEnum.MULTISELECT
}
];
return (
<Card>
<CardTitle
2019-08-20 09:17:06 +00:00
title={intl.formatMessage(commonMessages.generalInformations)}
2019-08-09 10:17:04 +00:00
/>
<CardContent>
<TextField
disabled={disabled}
error={!!errors.name}
2019-08-22 16:19:16 +00:00
label={intl.formatMessage({defaultMessage: "Default Label",
2019-08-20 09:17:06 +00:00
description: "attribute's label",
2019-08-22 16:19:16 +00:00
})}
name={"name" as keyof AttributePageFormData}
fullWidth
helperText={errors.name}
value={data.name}
onChange={onChange}
/>
<FormSpacer />
<TextField
disabled={disabled}
error={!!errors.slug}
2019-08-22 16:19:16 +00:00
label={intl.formatMessage({defaultMessage: "Attribute Code",
2019-08-20 09:17:06 +00:00
description: "attribute's slug short code label",
2019-08-22 16:19:16 +00:00
})}
name={"slug" as keyof AttributePageFormData}
placeholder={slugify(data.name).toLowerCase()}
fullWidth
helperText={
errors.slug ||
2019-08-22 16:19:16 +00:00
intl.formatMessage({defaultMessage:
"This is used internally. Make sure you dont use spaces",
description: "attribute slug input field helper text",
2019-08-22 16:19:16 +00:00
})
}
value={data.slug}
onChange={onChange}
/>
<FormSpacer />
<SingleSelectField
choices={inputTypeChoices}
disabled={disabled || !canChangeType}
error={!!errors.inputType}
hint={errors.inputType}
2019-08-22 16:19:16 +00:00
label={intl.formatMessage({defaultMessage: "Catalog Input type for Store Owner",
2019-08-20 09:17:06 +00:00
description: "attribute's editor component",
2019-08-22 16:19:16 +00:00
})}
name="inputType"
onChange={onChange}
value={data.inputType}
/>
<FormSpacer />
<ControlledSwitch
checked={data.valueRequired}
2019-08-22 16:19:16 +00:00
label={intl.formatMessage({defaultMessage: "Value Required",
description: "check to require attribute to have value",
2019-08-22 16:19:16 +00:00
})}
name={"valueRequired" as keyof AttributePageFormData}
onChange={onChange}
/>
</CardContent>
</Card>
);
};
2019-08-09 10:17:04 +00:00
AttributeDetails.displayName = "AttributeDetails";
export default AttributeDetails;