saleor-dashboard/src/utils/errors/attribute.ts
Dawid Tarasiuk fc02fce701
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 15:42:14 +01:00

46 lines
1.5 KiB
TypeScript

import { AttributeErrorFragment } from "@saleor/fragments/types/AttributeErrorFragment";
import { commonMessages } from "@saleor/intl";
import { AttributeErrorCode } from "@saleor/types/globalTypes";
import { defineMessages, IntlShape } from "react-intl";
import commonErrorMessages from "./common";
const messages = defineMessages({
alreadyExists: {
defaultMessage: "An attribute already exists."
},
nameAlreadyTaken: {
defaultMessage: "This name is already taken. Please provide another."
},
notFound: {
defaultMessage: "Attribute not found."
}
});
function getAttributeErrorMessage(
err: Omit<AttributeErrorFragment, "__typename"> | undefined,
intl: IntlShape
): string {
if (err) {
switch (err.code) {
case AttributeErrorCode.ALREADY_EXISTS:
return intl.formatMessage(messages.alreadyExists);
case AttributeErrorCode.GRAPHQL_ERROR:
return intl.formatMessage(commonErrorMessages.graphqlError);
case AttributeErrorCode.REQUIRED:
return intl.formatMessage(commonMessages.requiredField);
case AttributeErrorCode.INVALID:
return intl.formatMessage(commonErrorMessages.invalid);
case AttributeErrorCode.UNIQUE:
return intl.formatMessage(messages.nameAlreadyTaken);
case AttributeErrorCode.NOT_FOUND:
return intl.formatMessage(messages.notFound);
default:
return intl.formatMessage(commonErrorMessages.unknownError);
}
}
return undefined;
}
export default getAttributeErrorMessage;