
* Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix visual bugs and artifacts * Fix dropdown menus being clipped (#1762) * wip * Fix clipped select menus * Remove unused import * Fix spacing * Fix tests * Fix select content appearing under dialogs (#1777) * Fix type errors * Fix bulk delete button placement * Fix filter arrow buttons * Fix messages * Remove backling from pages list * Move status above events * Update messages and snapshots Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
257 lines
8.6 KiB
TypeScript
257 lines
8.6 KiB
TypeScript
import { AttributeDetails_attribute_choices } from "@saleor/attributes/types/AttributeDetails";
|
|
import { ATTRIBUTE_TYPES_WITH_DEDICATED_VALUES } from "@saleor/attributes/utils/data";
|
|
import CardSpacer from "@saleor/components/CardSpacer";
|
|
import Container from "@saleor/components/Container";
|
|
import Form from "@saleor/components/Form";
|
|
import Grid from "@saleor/components/Grid";
|
|
import Metadata from "@saleor/components/Metadata/Metadata";
|
|
import { MetadataFormData } from "@saleor/components/Metadata/types";
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
import Savebar from "@saleor/components/Savebar";
|
|
import { ListSettingsUpdate } from "@saleor/components/TablePagination";
|
|
import { AttributeDetailsFragment } from "@saleor/fragments/types/AttributeDetailsFragment";
|
|
import { AttributeErrorFragment } from "@saleor/fragments/types/AttributeErrorFragment";
|
|
import { sectionNames } from "@saleor/intl";
|
|
import { ConfirmButtonTransitionState } from "@saleor/macaw-ui";
|
|
import { Backlink } from "@saleor/macaw-ui";
|
|
import { maybe } from "@saleor/misc";
|
|
import { ListSettings, ReorderAction } from "@saleor/types";
|
|
import {
|
|
AttributeEntityTypeEnum,
|
|
AttributeInputTypeEnum,
|
|
AttributeTypeEnum,
|
|
MeasurementUnitsEnum
|
|
} from "@saleor/types/globalTypes";
|
|
import { mapEdgesToItems, mapMetadataItemToInput } from "@saleor/utils/maps";
|
|
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
|
|
import React from "react";
|
|
import { useIntl } from "react-intl";
|
|
import slugify from "slugify";
|
|
|
|
import AttributeDetails from "../AttributeDetails";
|
|
import AttributeOrganization from "../AttributeOrganization";
|
|
import AttributeProperties from "../AttributeProperties";
|
|
import AttributeValues from "../AttributeValues";
|
|
|
|
export interface AttributePageProps {
|
|
attribute: AttributeDetailsFragment | null;
|
|
disabled: boolean;
|
|
errors: AttributeErrorFragment[];
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
values: AttributeDetails_attribute_choices;
|
|
onBack: () => void;
|
|
onDelete: () => void;
|
|
onSubmit: (data: AttributePageFormData) => void;
|
|
onValueAdd: () => void;
|
|
onValueDelete: (id: string) => void;
|
|
onValueReorder: ReorderAction;
|
|
onValueUpdate: (id: string) => void;
|
|
settings?: ListSettings;
|
|
onUpdateListSettings?: ListSettingsUpdate;
|
|
pageInfo: {
|
|
hasNextPage: boolean;
|
|
hasPreviousPage: boolean;
|
|
};
|
|
onNextPage: () => void;
|
|
onPreviousPage: () => void;
|
|
children: (data: AttributePageFormData) => React.ReactNode;
|
|
}
|
|
|
|
export interface AttributePageFormData extends MetadataFormData {
|
|
type: AttributeTypeEnum;
|
|
availableInGrid: boolean;
|
|
filterableInDashboard: boolean;
|
|
inputType: AttributeInputTypeEnum;
|
|
entityType: AttributeEntityTypeEnum;
|
|
filterableInStorefront: boolean;
|
|
name: string;
|
|
slug: string;
|
|
storefrontSearchPosition: string;
|
|
valueRequired: boolean;
|
|
unit: MeasurementUnitsEnum | null | undefined;
|
|
visibleInStorefront: boolean;
|
|
}
|
|
|
|
const AttributePage: React.FC<AttributePageProps> = ({
|
|
attribute,
|
|
disabled,
|
|
errors: apiErrors,
|
|
saveButtonBarState,
|
|
values,
|
|
onBack,
|
|
onDelete,
|
|
onSubmit,
|
|
onValueAdd,
|
|
onValueDelete,
|
|
onValueReorder,
|
|
onValueUpdate,
|
|
settings,
|
|
onUpdateListSettings,
|
|
pageInfo,
|
|
onNextPage,
|
|
onPreviousPage,
|
|
children
|
|
}) => {
|
|
const intl = useIntl();
|
|
const {
|
|
isMetadataModified,
|
|
isPrivateMetadataModified,
|
|
makeChangeHandler: makeMetadataChangeHandler
|
|
} = useMetadataChangeTrigger();
|
|
|
|
const initialForm: AttributePageFormData =
|
|
attribute === null
|
|
? {
|
|
availableInGrid: true,
|
|
entityType: null,
|
|
filterableInDashboard: true,
|
|
filterableInStorefront: true,
|
|
inputType: AttributeInputTypeEnum.DROPDOWN,
|
|
metadata: [],
|
|
name: "",
|
|
privateMetadata: [],
|
|
slug: "",
|
|
storefrontSearchPosition: "",
|
|
type: AttributeTypeEnum.PRODUCT_TYPE,
|
|
valueRequired: true,
|
|
visibleInStorefront: true,
|
|
unit: undefined
|
|
}
|
|
: {
|
|
availableInGrid: attribute?.availableInGrid ?? true,
|
|
entityType: attribute?.entityType ?? null,
|
|
filterableInDashboard: attribute?.filterableInDashboard ?? true,
|
|
filterableInStorefront: attribute?.filterableInStorefront ?? true,
|
|
inputType: attribute?.inputType ?? AttributeInputTypeEnum.DROPDOWN,
|
|
metadata: attribute?.metadata?.map(mapMetadataItemToInput),
|
|
name: attribute?.name ?? "",
|
|
privateMetadata: attribute?.privateMetadata?.map(
|
|
mapMetadataItemToInput
|
|
),
|
|
slug: attribute?.slug ?? "",
|
|
storefrontSearchPosition:
|
|
attribute?.storefrontSearchPosition.toString() ?? "",
|
|
type: attribute?.type || AttributeTypeEnum.PRODUCT_TYPE,
|
|
valueRequired: !!attribute?.valueRequired ?? true,
|
|
visibleInStorefront: attribute?.visibleInStorefront ?? true,
|
|
unit: attribute?.unit || null
|
|
};
|
|
|
|
const handleSubmit = (data: AttributePageFormData) => {
|
|
const metadata =
|
|
!attribute || isMetadataModified ? data.metadata : undefined;
|
|
const privateMetadata =
|
|
!attribute || isPrivateMetadataModified
|
|
? data.privateMetadata
|
|
: undefined;
|
|
const type = attribute === null ? data.type : undefined;
|
|
|
|
return onSubmit({
|
|
...data,
|
|
metadata,
|
|
privateMetadata,
|
|
slug: data.slug || slugify(data.name).toLowerCase(),
|
|
type
|
|
});
|
|
};
|
|
|
|
return (
|
|
<Form initial={initialForm} onSubmit={handleSubmit}>
|
|
{({
|
|
change,
|
|
set,
|
|
data,
|
|
hasChanged,
|
|
submit,
|
|
errors,
|
|
setError,
|
|
clearErrors
|
|
}) => {
|
|
const changeMetadata = makeMetadataChangeHandler(change);
|
|
|
|
return (
|
|
<>
|
|
<Container>
|
|
<Backlink onClick={onBack}>
|
|
{intl.formatMessage(sectionNames.attributes)}
|
|
</Backlink>
|
|
<PageHeader
|
|
title={
|
|
attribute === null
|
|
? intl.formatMessage({
|
|
defaultMessage: "Create New Attribute",
|
|
description: "page title"
|
|
})
|
|
: maybe(() => attribute.name)
|
|
}
|
|
/>
|
|
<Grid>
|
|
<div>
|
|
<AttributeDetails
|
|
canChangeType={attribute === null}
|
|
data={data}
|
|
disabled={disabled}
|
|
apiErrors={apiErrors}
|
|
onChange={change}
|
|
set={set}
|
|
errors={errors}
|
|
setError={setError}
|
|
clearErrors={clearErrors}
|
|
/>
|
|
{ATTRIBUTE_TYPES_WITH_DEDICATED_VALUES.includes(
|
|
data.inputType
|
|
) && (
|
|
<>
|
|
<CardSpacer />
|
|
<AttributeValues
|
|
inputType={data.inputType}
|
|
disabled={disabled}
|
|
values={mapEdgesToItems(values)}
|
|
onValueAdd={onValueAdd}
|
|
onValueDelete={onValueDelete}
|
|
onValueReorder={onValueReorder}
|
|
onValueUpdate={onValueUpdate}
|
|
settings={settings}
|
|
onUpdateListSettings={onUpdateListSettings}
|
|
pageInfo={pageInfo}
|
|
onNextPage={onNextPage}
|
|
onPreviousPage={onPreviousPage}
|
|
/>
|
|
</>
|
|
)}
|
|
<CardSpacer />
|
|
<Metadata data={data} onChange={changeMetadata} />
|
|
</div>
|
|
<div>
|
|
<AttributeOrganization
|
|
canChangeType={attribute === null}
|
|
data={data}
|
|
disabled={disabled}
|
|
onChange={change}
|
|
/>
|
|
<CardSpacer />
|
|
<AttributeProperties
|
|
data={data}
|
|
errors={apiErrors}
|
|
disabled={disabled}
|
|
onChange={change}
|
|
/>
|
|
</div>
|
|
</Grid>
|
|
<Savebar
|
|
disabled={disabled || !hasChanged}
|
|
state={saveButtonBarState}
|
|
onCancel={onBack}
|
|
onSubmit={submit}
|
|
onDelete={attribute === null ? undefined : onDelete}
|
|
/>
|
|
</Container>
|
|
{children(data)}
|
|
</>
|
|
);
|
|
}}
|
|
</Form>
|
|
);
|
|
};
|
|
AttributePage.displayName = "AttributePage";
|
|
export default AttributePage;
|