Fix error messages with service account

This commit is contained in:
Krzysztof Bialoglowicz 2019-10-18 14:33:05 +02:00
parent c40bd1a2e6
commit 13da934927
3 changed files with 7 additions and 46 deletions

View file

@ -47,6 +47,9 @@ export const commonMessages = defineMessages({
properties: { properties: {
defaultMessage: "Properties" defaultMessage: "Properties"
}, },
requiredField: {
defaultMessage: "This field is required"
},
savedChanges: { savedChanges: {
defaultMessage: "Saved changes" defaultMessage: "Saved changes"
}, },

View file

@ -123389,7 +123389,7 @@ exports[`Storyshots Views / Webhooks / Create webhook form errors 1`] = `
<p <p
class="MuiFormHelperText-root-id MuiFormHelperText-contained-id MuiFormHelperText-error-id" class="MuiFormHelperText-root-id MuiFormHelperText-contained-id MuiFormHelperText-error-id"
> >
Missing token or serviceAccount This field is required
</p> </p>
</div> </div>
</div> </div>
@ -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 secret key is used to create a hash signature with each payload. *optional field
</p> </p>
</div> </div>
<div
class="FormSpacer-spacer-id"
/>
<p
class="MuiTypography-root-id MuiTypography-body2-id MuiTypography-colorError-id"
>
Missing token or serviceAccount
</p>
</div> </div>
</div> </div>
</div> </div>
@ -124957,7 +124949,7 @@ exports[`Storyshots Views / Webhooks / Webhook details form errors 1`] = `
<p <p
class="MuiFormHelperText-root-id MuiFormHelperText-contained-id MuiFormHelperText-error-id" class="MuiFormHelperText-root-id MuiFormHelperText-contained-id MuiFormHelperText-error-id"
> >
Missing token or serviceAccount This field is required
</p> </p>
</div> </div>
</div> </div>
@ -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 secret key is used to create a hash signature with each payload. *optional field
</p> </p>
</div> </div>
<div
class="FormSpacer-spacer-id"
/>
<p
class="MuiTypography-root-id MuiTypography-body2-id MuiTypography-colorError-id"
>
Missing token or serviceAccount
</p>
</div> </div>
</div> </div>
</div> </div>

View file

@ -4,7 +4,7 @@ import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography"; import Typography from "@material-ui/core/Typography";
import makeStyles from "@material-ui/styles/makeStyles"; import makeStyles from "@material-ui/styles/makeStyles";
import React from "react"; import React from "react";
import { IntlShape, useIntl } from "react-intl"; import { useIntl } from "react-intl";
import CardTitle from "@saleor/components/CardTitle"; import CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer"; import FormSpacer from "@saleor/components/FormSpacer";
@ -15,7 +15,6 @@ import SingleAutocompleteSelectField, {
import { ChangeEvent } from "@saleor/hooks/useForm"; import { ChangeEvent } from "@saleor/hooks/useForm";
import { commonMessages } from "@saleor/intl"; import { commonMessages } from "@saleor/intl";
import { FormErrors } from "@saleor/types"; import { FormErrors } from "@saleor/types";
import { WebhookErrorCode } from "@saleor/types/globalTypes";
import { WebhookCreate_webhookCreate_webhookErrors } from "@saleor/webhooks/types/WebhookCreate"; import { WebhookCreate_webhookCreate_webhookErrors } from "@saleor/webhooks/types/WebhookCreate";
import { FormData } from "../WebhooksDetailsPage"; import { FormData } from "../WebhooksDetailsPage";
@ -55,19 +54,9 @@ const WebhookInfo: React.StatelessComponent<WebhookInfoProps> = ({
}) => { }) => {
const classes = useStyles({}); const classes = useStyles({});
const intl = useIntl(); const intl = useIntl();
const translatedErrors = translateErrors(intl);
const serviceAccountsError = const serviceAccountsError =
apiErrors.filter(error => error.field === null).length > 0; 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 ( return (
<Card> <Card>
<CardTitle <CardTitle
@ -111,10 +100,7 @@ const WebhookInfo: React.StatelessComponent<WebhookInfoProps> = ({
error={serviceAccountsError} error={serviceAccountsError}
helperText={ helperText={
serviceAccountsError && serviceAccountsError &&
intl.formatMessage({ intl.formatMessage(commonMessages.requiredField)
defaultMessage: "Missing service account",
description: "webhook service account error"
})
} }
name="serviceAccount" name="serviceAccount"
onChange={serviceOnChange} onChange={serviceOnChange}
@ -160,18 +146,6 @@ const WebhookInfo: React.StatelessComponent<WebhookInfoProps> = ({
value={data.secretKey} value={data.secretKey}
onChange={onChange} onChange={onChange}
/> />
{apiErrors.length > 0 && (
<>
<FormSpacer />
{apiErrors
.filter(error => error.field === null)
.map(error => (
<Typography color="error" key={error.code}>
{translatedErrors[error.code]}
</Typography>
))}
</>
)}
</CardContent> </CardContent>
</Card> </Card>
); );