2020-07-07 10:14:12 +00:00
|
|
|
import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment";
|
2020-03-24 14:05:26 +00:00
|
|
|
import { ProductErrorCode } from "@saleor/types/globalTypes";
|
|
|
|
import { getProductErrorMessage } from "@saleor/utils/errors";
|
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: {
|
|
|
|
defaultMessage: "Attribute with this slug already exists"
|
|
|
|
},
|
|
|
|
attributeValueAlreadyExists: {
|
|
|
|
defaultMessage: "This value already exists within this attribute"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export function getAttributeSlugErrorMessage(
|
|
|
|
err: ProductErrorFragment,
|
|
|
|
intl: IntlShape
|
|
|
|
): string {
|
|
|
|
switch (err?.code) {
|
|
|
|
case ProductErrorCode.UNIQUE:
|
|
|
|
return intl.formatMessage(messages.attributeSlugUnique);
|
|
|
|
default:
|
|
|
|
return getProductErrorMessage(err, intl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getAttributeValueErrorMessage(
|
|
|
|
err: ProductErrorFragment,
|
|
|
|
intl: IntlShape
|
|
|
|
): string {
|
|
|
|
switch (err?.code) {
|
|
|
|
case ProductErrorCode.ALREADY_EXISTS:
|
|
|
|
return intl.formatMessage(messages.attributeValueAlreadyExists);
|
|
|
|
default:
|
|
|
|
return getProductErrorMessage(err, intl);
|
|
|
|
}
|
|
|
|
}
|