2022-03-09 08:56:55 +00:00
|
|
|
import { AttributeErrorCode, AttributeErrorFragment } from "@saleor/graphql";
|
2020-11-19 14:42:14 +00:00
|
|
|
import getAttributeErrorMessage from "@saleor/utils/errors/attribute";
|
2020-05-14 09:30:32 +00:00
|
|
|
import { defineMessages, IntlShape } from "react-intl";
|
|
|
|
|
2020-03-24 14:05:26 +00:00
|
|
|
const messages = defineMessages({
|
|
|
|
attributeSlugUnique: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "eWV760",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Attribute with this slug already exists",
|
2020-03-24 14:05:26 +00:00
|
|
|
},
|
|
|
|
attributeValueAlreadyExists: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "J/QqOI",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "This value already exists within this attribute",
|
|
|
|
},
|
2020-03-24 14:05:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export function getAttributeSlugErrorMessage(
|
2020-11-19 14:42:14 +00:00
|
|
|
err: AttributeErrorFragment,
|
2022-06-21 09:36:55 +00:00
|
|
|
intl: IntlShape,
|
2020-03-24 14:05:26 +00:00
|
|
|
): string {
|
|
|
|
switch (err?.code) {
|
2020-11-19 14:42:14 +00:00
|
|
|
case AttributeErrorCode.UNIQUE:
|
2020-03-24 14:05:26 +00:00
|
|
|
return intl.formatMessage(messages.attributeSlugUnique);
|
|
|
|
default:
|
2020-11-19 14:42:14 +00:00
|
|
|
return getAttributeErrorMessage(err, intl);
|
2020-03-24 14:05:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getAttributeValueErrorMessage(
|
2020-11-19 14:42:14 +00:00
|
|
|
err: AttributeErrorFragment,
|
2022-06-21 09:36:55 +00:00
|
|
|
intl: IntlShape,
|
2020-03-24 14:05:26 +00:00
|
|
|
): string {
|
|
|
|
switch (err?.code) {
|
2020-11-19 14:42:14 +00:00
|
|
|
case AttributeErrorCode.ALREADY_EXISTS:
|
2020-03-24 14:05:26 +00:00
|
|
|
return intl.formatMessage(messages.attributeValueAlreadyExists);
|
|
|
|
default:
|
2020-11-19 14:42:14 +00:00
|
|
|
return getAttributeErrorMessage(err, intl);
|
2020-03-24 14:05:26 +00:00
|
|
|
}
|
|
|
|
}
|