2023-01-16 09:45:12 +00:00
|
|
|
import { AttributeErrorCode, AttributeErrorFragment } from "@dashboard/graphql";
|
|
|
|
import getAttributeErrorMessage from "@dashboard/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(
|
2023-01-26 08:38:19 +00:00
|
|
|
err: AttributeErrorFragment | undefined,
|
2022-06-21 09:36:55 +00:00
|
|
|
intl: IntlShape,
|
2023-01-26 08:38:19 +00:00
|
|
|
): string | undefined {
|
2020-03-24 14:05:26 +00:00
|
|
|
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(
|
2023-01-26 08:38:19 +00:00
|
|
|
err: AttributeErrorFragment | undefined,
|
2022-06-21 09:36:55 +00:00
|
|
|
intl: IntlShape,
|
2023-01-26 08:38:19 +00:00
|
|
|
): string | undefined {
|
2020-03-24 14:05:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|