2021-05-14 08:15:15 +00:00
|
|
|
|
import { Card, CardContent, TextField, Typography } from "@material-ui/core";
|
2021-01-12 11:11:15 +00:00
|
|
|
|
import { ATTRIBUTE_TYPES_WITH_DEDICATED_VALUES } from "@saleor/attributes/utils/data";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
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";
|
2020-11-19 14:42:14 +00:00
|
|
|
|
import ControlledSwitch from "@saleor/components/ControlledSwitch";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
|
|
|
|
import Hr from "@saleor/components/Hr";
|
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";
|
2021-01-12 11:11:15 +00:00
|
|
|
|
import { AttributeTypeEnum } 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";
|
2021-01-12 11:11:15 +00:00
|
|
|
|
import { defineMessages, FormattedMessage, useIntl } from "react-intl";
|
2020-05-14 09:30:32 +00:00
|
|
|
|
|
2019-08-09 10:17:04 +00:00
|
|
|
|
import { AttributePageFormData } from "../AttributePage";
|
|
|
|
|
|
2021-01-12 11:11:15 +00:00
|
|
|
|
const messages = defineMessages({
|
|
|
|
|
availableInGrid: {
|
|
|
|
|
defaultMessage: "Add to Column Options",
|
|
|
|
|
description: "add attribute as column in product list table"
|
|
|
|
|
},
|
|
|
|
|
availableInGridCaption: {
|
|
|
|
|
defaultMessage:
|
|
|
|
|
"If enabled this attribute can be used as a column in product table.",
|
|
|
|
|
description: "caption"
|
|
|
|
|
},
|
|
|
|
|
dashboardPropertiesTitle: {
|
|
|
|
|
defaultMessage: "Dashboard Properties",
|
|
|
|
|
description: "attribute properties regarding dashboard"
|
|
|
|
|
},
|
|
|
|
|
filterableInDashboard: {
|
|
|
|
|
defaultMessage: "Use in Filtering",
|
|
|
|
|
description: "use attribute in filtering"
|
|
|
|
|
},
|
|
|
|
|
filterableInDashboardCaption: {
|
|
|
|
|
defaultMessage:
|
|
|
|
|
"If enabled, you’ll be able to use this attribute to filter products in product list.",
|
|
|
|
|
description: "caption"
|
|
|
|
|
},
|
|
|
|
|
filterableInStorefront: {
|
|
|
|
|
defaultMessage: "Use in Faceted Navigation",
|
|
|
|
|
description: "attribute is filterable in storefront"
|
|
|
|
|
},
|
|
|
|
|
storefrontPropertiesTitle: {
|
|
|
|
|
defaultMessage: "Storefront Properties",
|
|
|
|
|
description: "attribute properties regarding storefront"
|
|
|
|
|
},
|
|
|
|
|
storefrontSearchPosition: {
|
|
|
|
|
defaultMessage: "Position in faceted navigation",
|
|
|
|
|
description: "attribute position in storefront filters"
|
|
|
|
|
},
|
|
|
|
|
visibleInStorefront: {
|
|
|
|
|
defaultMessage: "Public",
|
|
|
|
|
description: "attribute visibility in storefront"
|
|
|
|
|
},
|
|
|
|
|
visibleInStorefrontCaption: {
|
|
|
|
|
defaultMessage: "If enabled, attribute will be accessible to customers.",
|
|
|
|
|
description: "caption"
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-08-09 10:17:04 +00:00
|
|
|
|
export interface AttributePropertiesProps {
|
|
|
|
|
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 AttributeProperties: React.FC<AttributePropertiesProps> = ({
|
|
|
|
|
data,
|
|
|
|
|
errors,
|
|
|
|
|
disabled,
|
|
|
|
|
onChange
|
2019-08-16 11:47:30 +00:00
|
|
|
|
}) => {
|
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
2020-03-24 14:05:26 +00:00
|
|
|
|
const formErrors = getFormErrors(["storefrontSearchPosition"], errors);
|
|
|
|
|
|
2021-01-12 11:11:15 +00:00
|
|
|
|
const dashboardProperties = ATTRIBUTE_TYPES_WITH_DEDICATED_VALUES.includes(
|
|
|
|
|
data.inputType
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const storefrontFacetedNavigationProperties =
|
|
|
|
|
ATTRIBUTE_TYPES_WITH_DEDICATED_VALUES.includes(data.inputType) &&
|
|
|
|
|
data.type === AttributeTypeEnum.PRODUCT_TYPE;
|
|
|
|
|
|
2019-08-16 11:47:30 +00:00
|
|
|
|
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
|
|
|
|
|
2019-08-16 11:47:30 +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
|
|
|
|
|
2019-08-16 11:47:30 +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
|
|
|
|
|
2019-08-16 11:47:30 +00:00
|
|
|
|
/>
|
|
|
|
|
</Typography>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
/> */}
|
|
|
|
|
|
|
|
|
|
<Typography variant="subtitle1">
|
2021-01-12 11:11:15 +00:00
|
|
|
|
<FormattedMessage {...messages.storefrontPropertiesTitle} />
|
2019-08-16 11:47:30 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
<Hr />
|
2021-01-12 11:11:15 +00:00
|
|
|
|
{storefrontFacetedNavigationProperties && (
|
|
|
|
|
<>
|
|
|
|
|
<ControlledCheckbox
|
|
|
|
|
name={"filterableInStorefront" as keyof FormData}
|
|
|
|
|
label={intl.formatMessage(messages.filterableInStorefront)}
|
|
|
|
|
checked={data.filterableInStorefront}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
/>
|
|
|
|
|
{data.filterableInStorefront && (
|
|
|
|
|
<>
|
|
|
|
|
<FormSpacer />
|
|
|
|
|
<TextField
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
error={!!formErrors.storefrontSearchPosition}
|
|
|
|
|
fullWidth
|
|
|
|
|
helperText={getAttributeErrorMessage(
|
|
|
|
|
formErrors.storefrontSearchPosition,
|
|
|
|
|
intl
|
|
|
|
|
)}
|
|
|
|
|
name={
|
|
|
|
|
"storefrontSearchPosition" as keyof AttributePageFormData
|
|
|
|
|
}
|
|
|
|
|
label={intl.formatMessage(messages.storefrontSearchPosition)}
|
|
|
|
|
value={data.storefrontSearchPosition}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2019-08-16 11:47:30 +00:00
|
|
|
|
<FormSpacer />
|
2020-11-19 14:42:14 +00:00
|
|
|
|
<ControlledSwitch
|
2019-09-09 09:28:06 +00:00
|
|
|
|
name={"visibleInStorefront" as keyof FormData}
|
2020-11-19 14:42:14 +00:00
|
|
|
|
label={
|
|
|
|
|
<>
|
2021-01-12 11:11:15 +00:00
|
|
|
|
<FormattedMessage {...messages.visibleInStorefront} />
|
2020-11-19 14:42:14 +00:00
|
|
|
|
<Typography variant="caption">
|
2021-01-12 11:11:15 +00:00
|
|
|
|
<FormattedMessage {...messages.visibleInStorefrontCaption} />
|
2020-11-19 14:42:14 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
</>
|
|
|
|
|
}
|
2019-09-09 09:28:06 +00:00
|
|
|
|
checked={data.visibleInStorefront}
|
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
|
|
|
|
/>
|
2021-01-12 11:11:15 +00:00
|
|
|
|
{dashboardProperties && (
|
2020-12-16 10:53:28 +00:00
|
|
|
|
<>
|
|
|
|
|
<CardSpacer />
|
|
|
|
|
<Typography variant="subtitle1">
|
2021-01-12 11:11:15 +00:00
|
|
|
|
<FormattedMessage {...messages.dashboardPropertiesTitle} />
|
2020-12-16 10:53:28 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
<Hr />
|
|
|
|
|
<CardSpacer />
|
|
|
|
|
<ControlledCheckbox
|
|
|
|
|
name={"filterableInDashboard" as keyof FormData}
|
|
|
|
|
label={
|
|
|
|
|
<>
|
2021-01-12 11:11:15 +00:00
|
|
|
|
<FormattedMessage {...messages.filterableInDashboard} />
|
2020-12-16 10:53:28 +00:00
|
|
|
|
<Typography variant="caption">
|
2021-01-12 11:11:15 +00:00
|
|
|
|
<FormattedMessage
|
|
|
|
|
{...messages.filterableInDashboardCaption}
|
|
|
|
|
/>
|
2020-12-16 10:53:28 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
checked={data.filterableInDashboard}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
/>
|
|
|
|
|
<FormSpacer />
|
|
|
|
|
<ControlledCheckbox
|
|
|
|
|
name={"availableInGrid" as keyof FormData}
|
|
|
|
|
label={
|
|
|
|
|
<>
|
2021-01-12 11:11:15 +00:00
|
|
|
|
<FormattedMessage {...messages.availableInGrid} />
|
2020-12-16 10:53:28 +00:00
|
|
|
|
<Typography variant="caption">
|
2021-01-12 11:11:15 +00:00
|
|
|
|
<FormattedMessage {...messages.availableInGridCaption} />
|
2020-12-16 10:53:28 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
checked={data.availableInGrid}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2019-08-16 11:47:30 +00:00
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
};
|
2019-08-09 10:17:04 +00:00
|
|
|
|
AttributeProperties.displayName = "AttributeProperties";
|
|
|
|
|
export default AttributeProperties;
|