2022-07-07 08:29:33 +00:00
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
CardContent,
|
|
|
|
Popper,
|
|
|
|
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-07-07 08:29:33 +00:00
|
|
|
import Link from "@saleor/components/Link";
|
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";
|
2022-07-07 08:29:33 +00:00
|
|
|
import { Pill } from "@saleor/macaw-ui";
|
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";
|
2022-07-07 08:29:33 +00:00
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2020-05-14 09:30:32 +00:00
|
|
|
|
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";
|
2022-07-07 08:29:33 +00:00
|
|
|
import { useStyles } from "./styles";
|
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();
|
2022-07-07 08:29:33 +00:00
|
|
|
const classes = useStyles();
|
2020-03-18 11:03:20 +00:00
|
|
|
|
|
|
|
const formErrors = getFormErrors(["name", "targetUrl", "secretKey"], errors);
|
2019-10-18 12:01:26 +00:00
|
|
|
|
2022-07-07 08:29:33 +00:00
|
|
|
const [isPopupOpen, setPopupOpen] = React.useState(false);
|
|
|
|
const anchor = React.useRef<HTMLDivElement>(null);
|
|
|
|
|
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}
|
2022-07-07 08:29:33 +00:00
|
|
|
InputProps={{
|
|
|
|
endAdornment: (
|
|
|
|
<div
|
|
|
|
ref={anchor}
|
|
|
|
onMouseOver={() => setPopupOpen(true)}
|
|
|
|
onMouseLeave={() => setPopupOpen(false)}
|
|
|
|
>
|
|
|
|
<Pill
|
|
|
|
label={intl.formatMessage(commonMessages.deprecated)}
|
|
|
|
color={"error"}
|
|
|
|
outlined
|
|
|
|
size="small"
|
|
|
|
/>
|
|
|
|
<Popper
|
|
|
|
anchorEl={anchor.current}
|
|
|
|
open={isPopupOpen}
|
|
|
|
placement={"top"}
|
|
|
|
>
|
|
|
|
<Card elevation={8} className={classes.toolbar}>
|
|
|
|
<Typography>
|
|
|
|
<FormattedMessage {...messages.useSignature} />
|
|
|
|
</Typography>
|
|
|
|
<Link
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2022-08-24 09:41:59 +00:00
|
|
|
href="https://docs.saleor.io/docs/3.x/developer/extending/apps/synchronous-webhooks/key-concepts#payload-signature"
|
2022-07-07 08:29:33 +00:00
|
|
|
>
|
|
|
|
<FormattedMessage {...messages.learnMore} />
|
|
|
|
</Link>
|
|
|
|
</Card>
|
|
|
|
</Popper>
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
}}
|
2019-10-09 20:50:03 +00:00
|
|
|
/>
|
|
|
|
</CardContent>
|
2019-10-09 06:01:52 +00:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
WebhookInfo.displayName = "WebhookInfo";
|
|
|
|
export default WebhookInfo;
|