import React from "react"; import slugify from "slugify"; import AppHeader from "@saleor/components/AppHeader"; import CardSpacer from "@saleor/components/CardSpacer"; import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton"; import Container from "@saleor/components/Container"; import Form from "@saleor/components/Form"; import Grid from "@saleor/components/Grid"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; import i18n from "@saleor/i18n"; import { maybe } from "@saleor/misc"; import { ReorderAction, UserError } from "@saleor/types"; import { AttributeInputTypeEnum } from "@saleor/types/globalTypes"; import { AttributeDetailsFragment, AttributeDetailsFragment_values } from "../../types/AttributeDetailsFragment"; import AttributeDetails from "../AttributeDetails"; import AttributeProperties from "../AttributeProperties"; import AttributeValues from "../AttributeValues"; export interface AttributePageProps { attribute: AttributeDetailsFragment | null; disabled: boolean; errors: UserError[]; saveButtonBarState: ConfirmButtonTransitionState; values: AttributeDetailsFragment_values[]; onBack: () => void; onDelete: () => void; onSubmit: (data: AttributePageFormData) => void; onValueAdd: () => void; onValueDelete: (id: string) => void; onValueReorder: ReorderAction; onValueUpdate: (id: string) => void; } export interface AttributePageFormData { filterableInDashboard: boolean; inputType: AttributeInputTypeEnum; filterableInStorefront: boolean; name: string; slug: string; storefrontSearchPosition: string; valueRequired: boolean; visibleInStorefront: boolean; } const AttributePage: React.FC = ({ attribute, disabled, errors, saveButtonBarState, values, onBack, onDelete, onSubmit, onValueAdd, onValueDelete, onValueReorder, onValueUpdate }) => { const initialForm: AttributePageFormData = attribute === null ? { filterableInDashboard: true, filterableInStorefront: true, inputType: AttributeInputTypeEnum.DROPDOWN, name: "", slug: "", storefrontSearchPosition: "", valueRequired: true, visibleInStorefront: true } : { filterableInDashboard: maybe( () => attribute.filterableInDashboard, true ), filterableInStorefront: maybe( () => attribute.filterableInStorefront, true ), inputType: maybe( () => attribute.inputType, AttributeInputTypeEnum.DROPDOWN ), name: maybe(() => attribute.name, ""), slug: maybe(() => attribute.slug, ""), storefrontSearchPosition: maybe( () => attribute.storefrontSearchPosition.toString(), "" ), valueRequired: maybe(() => attribute.valueRequired, true), visibleInStorefront: maybe(() => attribute.visibleInStorefront, true) }; const handleSubmit = (data: AttributePageFormData) => onSubmit({ ...data, slug: data.slug || slugify(data.name).toLowerCase() }); return (
{({ change, errors: formErrors, data, submit }) => ( {i18n.t("Attributes")} attribute.name) } />
)}
); }; AttributePage.displayName = "AttributePage"; export default AttributePage;