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

167 lines
5.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 Typography from "@material-ui/core/Typography";
import CardSpacer from "@saleor/components/CardSpacer";
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 Hr from "@saleor/components/Hr";
import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment";
import { commonMessages } from "@saleor/intl";
2020-03-24 14:05:26 +00:00
import { getFormErrors, getProductErrorMessage } from "@saleor/utils/errors";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
2019-08-09 10:17:04 +00:00
import { AttributePageFormData } from "../AttributePage";
export interface AttributePropertiesProps {
data: AttributePageFormData;
disabled: boolean;
2020-03-24 14:05:26 +00:00
errors: ProductErrorFragment[];
2019-08-09 10:17:04 +00:00
onChange: (event: React.ChangeEvent<any>) => void;
}
const AttributeProperties: React.FC<AttributePropertiesProps> = ({
data,
errors,
disabled,
onChange
}) => {
const intl = useIntl();
2020-03-24 14:05:26 +00:00
const formErrors = getFormErrors(["storefrontSearchPosition"], errors);
return (
<Card>
<CardTitle title={intl.formatMessage(commonMessages.properties)} />
<CardContent>
{/* <Typography variant="subtitle1">
<FormattedMessage
defaultMessage="General Properties"
description="attribute general properties section"
2019-08-22 16:19:16 +00:00
/>
</Typography>
<Hr />
<CardSpacer />
<ControlledSwitch
name={"" as keyof AttributePageFormData}
checked={false}
disabled={disabled}
label={
<>
<FormattedMessage
defaultMessage="Variant Attribute"
description="attribute is variant-only"
2019-08-22 16:19:16 +00:00
/>
<Typography variant="caption">
<FormattedMessage
defaultMessage="If enabled, you'll be able to use this attribute to create product variants"
2019-08-22 16:19:16 +00:00
/>
</Typography>
</>
}
onChange={onChange}
/> */}
<Typography variant="subtitle1">
<FormattedMessage
defaultMessage="Storefront Properties"
description="attribute properties regarding storefront"
/>
</Typography>
<Hr />
2019-09-09 09:28:06 +00:00
<ControlledCheckbox
name={"filterableInStorefront" as keyof FormData}
label={intl.formatMessage({
2019-10-22 11:17:07 +00:00
defaultMessage: "Use in Faceted Navigation",
2019-08-22 16:19:16 +00:00
description: "attribute is filterable in storefront"
})}
2019-09-09 09:28:06 +00:00
checked={data.filterableInStorefront}
onChange={onChange}
2019-09-09 09:28:06 +00:00
disabled={disabled}
/>
2019-09-09 09:28:06 +00:00
<FormSpacer />
{data.filterableInStorefront && (
<TextField
disabled={disabled}
2020-03-24 14:05:26 +00:00
error={!!formErrors.storefrontSearchPosition}
fullWidth
2020-03-24 14:05:26 +00:00
helperText={getProductErrorMessage(
formErrors.storefrontSearchPosition,
intl
)}
name={"storefrontSearchPosition" as keyof AttributePageFormData}
label={intl.formatMessage({
defaultMessage: "Position in faceted navigation",
2019-08-22 16:19:16 +00:00
description: "attribute position in storefront filters"
})}
value={data.storefrontSearchPosition}
onChange={onChange}
/>
)}
<FormSpacer />
2019-09-09 09:28:06 +00:00
<ControlledCheckbox
name={"visibleInStorefront" as keyof FormData}
label={intl.formatMessage({
defaultMessage: "Visible on Product Page in Storefront",
2019-08-22 16:19:16 +00:00
description: "attribute"
})}
2019-09-09 09:28:06 +00:00
checked={data.visibleInStorefront}
onChange={onChange}
2019-09-09 09:28:06 +00:00
disabled={disabled}
/>
<CardSpacer />
<Typography variant="subtitle1">
<FormattedMessage
defaultMessage="Dashboard Properties"
description="attribute properties regarding dashboard"
/>
</Typography>
<Hr />
<CardSpacer />
2019-09-09 09:28:06 +00:00
<ControlledCheckbox
name={"filterableInDashboard" as keyof FormData}
label={
<>
<FormattedMessage
defaultMessage="Use in Filtering"
description="use attribute in filtering"
/>
<Typography variant="caption">
<FormattedMessage defaultMessage="If enabled, youll be able to use this attribute to filter products in product list." />
</Typography>
</>
}
2019-09-09 09:28:06 +00:00
checked={data.filterableInDashboard}
onChange={onChange}
2019-09-09 09:28:06 +00:00
disabled={disabled}
/>
<FormSpacer />
2019-09-09 09:28:06 +00:00
<ControlledCheckbox
name={"availableInGrid" as keyof FormData}
label={
<>
<FormattedMessage
defaultMessage="Add to Column Options"
description="add attribute as column in product list table"
/>
<Typography variant="caption">
2019-09-12 10:38:23 +00:00
<FormattedMessage defaultMessage="If enabled this attribute can be used as a column in product table." />
2019-09-09 09:28:06 +00:00
</Typography>
</>
}
2019-09-09 09:28:06 +00:00
checked={data.availableInGrid}
2019-08-09 10:17:04 +00:00
onChange={onChange}
2019-09-09 09:28:06 +00:00
disabled={disabled}
2019-08-09 10:17:04 +00:00
/>
</CardContent>
</Card>
);
};
2019-08-09 10:17:04 +00:00
AttributeProperties.displayName = "AttributeProperties";
export default AttributeProperties;