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

103 lines
3 KiB
TypeScript
Raw Normal View History

import { Card, CardContent, Typography } from "@material-ui/core";
Page types (#807) * Create attribute class selector * Use ProductAttributeType to check if product is simple or with variants * Allow attribute class selection only during its creation * Update attribute type selection translations * Show only product attributes in columns picker on product list view * Cleanups in Attribute Organization component * Create Page Types list page * Create content management section in settings * Implement page types list view * Remove unused imports from page type list * Updatte page type list style * Remove legacy code from page type list component * Update PageTypeListPage component * Create Page Types details page * Fix page type attribute reordering * Implement PageType create view * Implement PageType update view * gUpdate page type details components * Fix page type update component * Update page type components stories * Update page type errors handling * Update page type details view * Create Page Types details page * Implement PageType create view * Update product attribute assignment mutations * Add page types attribute assignment mutations * Add page types attribute assignment handling * Temporarily fix page create mutation * Update page type error messages * Remove legacy storybook page type stories * Update attribute assignment dialogs stories * Update page type details error handling * Update props for page type components * Create attribute class selector * Implement page types list view * Add page type selector on page create and details views * Add attributes list to page details views * Update page types list * Use attribute errors for attributes muatations * Save attribute values on page create and update * Update messages for page view * Update page attributes fragment * Use AttributeError in AttributeBulkDelete * Update page type and its attribute selection * Handle page types deleting * Update page types deleting messages * Handle page types attribute reorder * Fix PageOrganizeContent component types * Update graphqql types * Fix page fixture * Update messages * Update test snapshots * Pass pageTypes to PageForm * Update changelog with page type addition note * Update package-lock * Update test snapshots * Fix malformed generated type * Update messages after rebase
2020-11-19 14:42:14 +00:00
import CardTitle from "@saleor/components/CardTitle";
import RadioGroupField from "@saleor/components/RadioGroupField";
import { makeStyles } from "@saleor/theme";
Page types (#807) * Create attribute class selector * Use ProductAttributeType to check if product is simple or with variants * Allow attribute class selection only during its creation * Update attribute type selection translations * Show only product attributes in columns picker on product list view * Cleanups in Attribute Organization component * Create Page Types list page * Create content management section in settings * Implement page types list view * Remove unused imports from page type list * Updatte page type list style * Remove legacy code from page type list component * Update PageTypeListPage component * Create Page Types details page * Fix page type attribute reordering * Implement PageType create view * Implement PageType update view * gUpdate page type details components * Fix page type update component * Update page type components stories * Update page type errors handling * Update page type details view * Create Page Types details page * Implement PageType create view * Update product attribute assignment mutations * Add page types attribute assignment mutations * Add page types attribute assignment handling * Temporarily fix page create mutation * Update page type error messages * Remove legacy storybook page type stories * Update attribute assignment dialogs stories * Update page type details error handling * Update props for page type components * Create attribute class selector * Implement page types list view * Add page type selector on page create and details views * Add attributes list to page details views * Update page types list * Use attribute errors for attributes muatations * Save attribute values on page create and update * Update messages for page view * Update page attributes fragment * Use AttributeError in AttributeBulkDelete * Update page type and its attribute selection * Handle page types deleting * Update page types deleting messages * Handle page types attribute reorder * Fix PageOrganizeContent component types * Update graphqql types * Fix page fixture * Update messages * Update test snapshots * Pass pageTypes to PageForm * Update changelog with page type addition note * Update package-lock * Update test snapshots * Fix malformed generated type * Update messages after rebase
2020-11-19 14:42:14 +00:00
import { AttributeTypeEnum } from "@saleor/types/globalTypes";
import React from "react";
import { defineMessages, FormattedMessage, useIntl } from "react-intl";
import { AttributePageFormData } from "../AttributePage";
export interface AttributeOrganizationProps {
canChangeType: boolean;
data: AttributePageFormData;
disabled: boolean;
onChange: (event: React.ChangeEvent<any>) => void;
}
const messages = defineMessages({
contentAttribute: {
defaultMessage: "Content Attribute",
description: "attribute type"
},
productAttribute: {
defaultMessage: "Product Attribute",
description: "attribute type"
}
});
const useStyles = makeStyles(
theme => ({
card: {
overflow: "visible"
},
cardSubtitle: {
fontSize: "1rem",
marginBottom: theme.spacing(0.5)
},
label: {
marginBottom: theme.spacing(0.5)
}
}),
{ name: "AttributeOrganization" }
);
const AttributeOrganization: React.FC<AttributeOrganizationProps> = props => {
const { canChangeType, data, disabled, onChange } = props;
const classes = useStyles(props);
const intl = useIntl();
return (
<Card>
<CardTitle
title={intl.formatMessage({
defaultMessage: "Organization",
description: "section header"
})}
/>
<CardContent>
{canChangeType ? (
<RadioGroupField
choices={[
{
label: intl.formatMessage(messages.productAttribute),
value: AttributeTypeEnum.PRODUCT_TYPE
},
{
label: intl.formatMessage(messages.contentAttribute),
value: AttributeTypeEnum.PAGE_TYPE
}
]}
disabled={disabled}
label={
<>
<FormattedMessage defaultMessage="Attribute Class" />
<Typography variant="caption">
<FormattedMessage defaultMessage="Define where this attribute should be used in Saleor system" />
</Typography>
</>
}
name={"type" as keyof FormData}
value={data.type}
onChange={onChange}
/>
) : (
<>
<Typography className={classes.label} variant="caption">
<FormattedMessage defaultMessage="Attribute Class" />
</Typography>
<Typography>
{data.type === AttributeTypeEnum.PRODUCT_TYPE
? intl.formatMessage(messages.productAttribute)
: intl.formatMessage(messages.contentAttribute)}
</Typography>
</>
)}
</CardContent>
</Card>
);
};
AttributeOrganization.displayName = "AttributeOrganization";
export default AttributeOrganization;