2021-05-14 08:15:15 +00:00
|
|
|
import { Card, CardContent, TextField, Typography } from "@material-ui/core";
|
2019-10-09 06:01:52 +00:00
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
|
|
|
import Hr from "@saleor/components/Hr";
|
2022-03-09 08:56:55 +00:00
|
|
|
import { WebhookErrorFragment } from "@saleor/graphql";
|
2019-10-11 13:35:33 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2020-03-18 11:03:20 +00:00
|
|
|
import { getFormErrors } from "@saleor/utils/errors";
|
|
|
|
import getWebhookErrorMessage from "@saleor/utils/errors/webhooks";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
2022-02-01 09:58:06 +00:00
|
|
|
import { WebhookFormData } from "../WebhooksDetailsPage/WebhooksDetailsPage";
|
2021-12-13 14:43:30 +00:00
|
|
|
import { messages } from "./messages";
|
2019-10-09 06:01:52 +00:00
|
|
|
|
|
|
|
interface WebhookInfoProps {
|
2022-02-01 09:58:06 +00:00
|
|
|
data: WebhookFormData;
|
2019-10-09 20:50:03 +00:00
|
|
|
disabled: boolean;
|
2020-03-18 11:03:20 +00:00
|
|
|
errors: WebhookErrorFragment[];
|
2019-10-09 06:01:52 +00:00
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const WebhookInfo: React.FC<WebhookInfoProps> = ({
|
2019-10-09 06:01:52 +00:00
|
|
|
data,
|
2019-10-09 20:50:03 +00:00
|
|
|
disabled,
|
|
|
|
errors,
|
2022-06-21 09:36:55 +00:00
|
|
|
onChange,
|
2019-10-09 06:01:52 +00:00
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
2020-03-18 11:03:20 +00:00
|
|
|
|
|
|
|
const formErrors = getFormErrors(["name", "targetUrl", "secretKey"], errors);
|
2019-10-18 12:01:26 +00:00
|
|
|
|
2019-10-09 06:01:52 +00:00
|
|
|
return (
|
|
|
|
<Card>
|
2021-12-13 14:43:30 +00:00
|
|
|
<CardTitle title={intl.formatMessage(messages.webhookInformation)} />
|
2019-10-09 20:50:03 +00:00
|
|
|
<CardContent>
|
2021-12-13 14:43:30 +00:00
|
|
|
<Typography variant="caption">
|
2019-10-11 13:35:33 +00:00
|
|
|
{intl.formatMessage(commonMessages.generalInformations)}
|
2019-10-09 20:50:03 +00:00
|
|
|
</Typography>
|
2021-12-13 14:43:30 +00:00
|
|
|
<FormSpacer />
|
2019-10-09 20:50:03 +00:00
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-03-18 11:03:20 +00:00
|
|
|
error={!!formErrors.name}
|
|
|
|
helperText={getWebhookErrorMessage(formErrors.name, intl)}
|
2021-12-13 14:43:30 +00:00
|
|
|
label={intl.formatMessage(messages.webhookName)}
|
2019-10-09 20:50:03 +00:00
|
|
|
fullWidth
|
|
|
|
name="name"
|
|
|
|
value={data.name}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<Hr />
|
|
|
|
<FormSpacer />
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-03-18 11:03:20 +00:00
|
|
|
error={!!formErrors.targetUrl}
|
2020-02-24 14:14:48 +00:00
|
|
|
helperText={
|
2020-03-18 11:03:20 +00:00
|
|
|
getWebhookErrorMessage(formErrors.targetUrl, intl) ||
|
2021-12-13 14:43:30 +00:00
|
|
|
intl.formatMessage(messages.targetUrlDescription)
|
2020-02-24 14:14:48 +00:00
|
|
|
}
|
2021-12-13 14:43:30 +00:00
|
|
|
label={intl.formatMessage(messages.targetUrl)}
|
2019-10-09 20:50:03 +00:00
|
|
|
fullWidth
|
|
|
|
name="targetUrl"
|
|
|
|
value={data.targetUrl}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
2020-03-18 11:03:20 +00:00
|
|
|
error={!!formErrors.secretKey}
|
2020-02-24 14:14:48 +00:00
|
|
|
helperText={
|
2020-03-18 11:03:20 +00:00
|
|
|
getWebhookErrorMessage(formErrors.secretKey, intl) ||
|
2021-12-13 14:43:30 +00:00
|
|
|
intl.formatMessage(messages.secretKeyDescription)
|
2020-02-24 14:14:48 +00:00
|
|
|
}
|
2021-12-13 14:43:30 +00:00
|
|
|
label={intl.formatMessage(messages.secretKey)}
|
2019-10-09 20:50:03 +00:00
|
|
|
fullWidth
|
|
|
|
name="secretKey"
|
|
|
|
value={data.secretKey}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
</CardContent>
|
2019-10-09 06:01:52 +00:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
WebhookInfo.displayName = "WebhookInfo";
|
|
|
|
export default WebhookInfo;
|