From 13da934927a1eb468708b27ed1340983b12a9f84 Mon Sep 17 00:00:00 2001
From: Krzysztof Bialoglowicz
Date: Fri, 18 Oct 2019 14:33:05 +0200
Subject: [PATCH] Fix error messages with service account
---
src/intl.ts | 3 ++
.../__snapshots__/Stories.test.ts.snap | 20 ++-----------
.../components/WebhookInfo/WebhookInfo.tsx | 30 ++-----------------
3 files changed, 7 insertions(+), 46 deletions(-)
diff --git a/src/intl.ts b/src/intl.ts
index 867bf279c..45839e65a 100644
--- a/src/intl.ts
+++ b/src/intl.ts
@@ -47,6 +47,9 @@ export const commonMessages = defineMessages({
properties: {
defaultMessage: "Properties"
},
+ requiredField: {
+ defaultMessage: "This field is required"
+ },
savedChanges: {
defaultMessage: "Saved changes"
},
diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap
index e9264fe09..9eeaa4605 100644
--- a/src/storybook/__snapshots__/Stories.test.ts.snap
+++ b/src/storybook/__snapshots__/Stories.test.ts.snap
@@ -123389,7 +123389,7 @@ exports[`Storyshots Views / Webhooks / Create webhook form errors 1`] = `
- Missing token or serviceAccount
+ This field is required
@@ -123479,14 +123479,6 @@ exports[`Storyshots Views / Webhooks / Create webhook form errors 1`] = `
secret key is used to create a hash signature with each payload. *optional field
-
-
- Missing token or serviceAccount
-
@@ -124957,7 +124949,7 @@ exports[`Storyshots Views / Webhooks / Webhook details form errors 1`] = `
- Missing token or serviceAccount
+ This field is required
@@ -125047,14 +125039,6 @@ exports[`Storyshots Views / Webhooks / Webhook details form errors 1`] = `
secret key is used to create a hash signature with each payload. *optional field
-
-
- Missing token or serviceAccount
-
diff --git a/src/webhooks/components/WebhookInfo/WebhookInfo.tsx b/src/webhooks/components/WebhookInfo/WebhookInfo.tsx
index 11da21fc8..de17ae2db 100644
--- a/src/webhooks/components/WebhookInfo/WebhookInfo.tsx
+++ b/src/webhooks/components/WebhookInfo/WebhookInfo.tsx
@@ -4,7 +4,7 @@ import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import makeStyles from "@material-ui/styles/makeStyles";
import React from "react";
-import { IntlShape, useIntl } from "react-intl";
+import { useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer";
@@ -15,7 +15,6 @@ import SingleAutocompleteSelectField, {
import { ChangeEvent } from "@saleor/hooks/useForm";
import { commonMessages } from "@saleor/intl";
import { FormErrors } from "@saleor/types";
-import { WebhookErrorCode } from "@saleor/types/globalTypes";
import { WebhookCreate_webhookCreate_webhookErrors } from "@saleor/webhooks/types/WebhookCreate";
import { FormData } from "../WebhooksDetailsPage";
@@ -55,19 +54,9 @@ const WebhookInfo: React.StatelessComponent = ({
}) => {
const classes = useStyles({});
const intl = useIntl();
- const translatedErrors = translateErrors(intl);
const serviceAccountsError =
apiErrors.filter(error => error.field === null).length > 0;
- function translateErrors(intl: IntlShape) {
- return {
- [WebhookErrorCode.INVALID]: intl.formatMessage({
- defaultMessage: "Missing service account",
- description: "webhook service account error"
- })
- };
- }
-
return (
= ({
error={serviceAccountsError}
helperText={
serviceAccountsError &&
- intl.formatMessage({
- defaultMessage: "Missing service account",
- description: "webhook service account error"
- })
+ intl.formatMessage(commonMessages.requiredField)
}
name="serviceAccount"
onChange={serviceOnChange}
@@ -160,18 +146,6 @@ const WebhookInfo: React.StatelessComponent = ({
value={data.secretKey}
onChange={onChange}
/>
- {apiErrors.length > 0 && (
- <>
-
- {apiErrors
- .filter(error => error.field === null)
- .map(error => (
-
- {translatedErrors[error.code]}
-
- ))}
- >
- )}
);