2019-10-09 06:01:52 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
2019-10-28 16:16:49 +00:00
|
|
|
import makeStyles from "@material-ui/core/styles/makeStyles";
|
2019-10-09 20:50:03 +00:00
|
|
|
import TextField from "@material-ui/core/TextField";
|
2019-10-09 06:01:52 +00:00
|
|
|
import Typography from "@material-ui/core/Typography";
|
|
|
|
import React from "react";
|
2019-10-18 12:33:05 +00:00
|
|
|
import { useIntl } from "react-intl";
|
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";
|
2019-10-17 12:38:01 +00:00
|
|
|
import SingleAutocompleteSelectField, {
|
|
|
|
SingleAutocompleteChoiceType
|
2019-10-14 14:41:41 +00:00
|
|
|
} from "@saleor/components/SingleAutocompleteSelectField";
|
|
|
|
import { ChangeEvent } from "@saleor/hooks/useForm";
|
2019-10-11 13:35:33 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2019-10-09 20:50:03 +00:00
|
|
|
import { FormErrors } from "@saleor/types";
|
2019-10-18 12:01:26 +00:00
|
|
|
import { WebhookCreate_webhookCreate_webhookErrors } from "@saleor/webhooks/types/WebhookCreate";
|
2019-10-09 06:01:52 +00:00
|
|
|
import { FormData } from "../WebhooksDetailsPage";
|
|
|
|
|
|
|
|
interface WebhookInfoProps {
|
2019-10-18 12:01:26 +00:00
|
|
|
apiErrors: WebhookCreate_webhookCreate_webhookErrors[];
|
2019-10-09 06:01:52 +00:00
|
|
|
data: FormData;
|
2019-10-09 20:50:03 +00:00
|
|
|
disabled: boolean;
|
2019-10-14 14:41:41 +00:00
|
|
|
serviceDisplayValue: string;
|
|
|
|
services: SingleAutocompleteChoiceType[];
|
2019-10-09 20:50:03 +00:00
|
|
|
errors: FormErrors<"name" | "targetUrl" | "secretKey">;
|
2019-10-09 06:01:52 +00:00
|
|
|
onChange: (event: React.ChangeEvent<any>) => void;
|
2019-10-14 14:41:41 +00:00
|
|
|
serviceOnChange: (event: ChangeEvent) => void;
|
2019-10-17 11:59:18 +00:00
|
|
|
fetchServiceAccounts: (data: string) => void;
|
2019-10-09 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 15:28:40 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
() => ({
|
|
|
|
status: {
|
|
|
|
paddingTop: 20
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
fontSize: 16,
|
|
|
|
lineHeight: 1.9,
|
|
|
|
paddingBottom: 10
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
{ name: "WebhookInfo" }
|
|
|
|
);
|
2019-10-09 06:01:52 +00:00
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const WebhookInfo: React.FC<WebhookInfoProps> = ({
|
2019-10-18 12:01:26 +00:00
|
|
|
apiErrors,
|
2019-10-09 06:01:52 +00:00
|
|
|
data,
|
2019-10-09 20:50:03 +00:00
|
|
|
disabled,
|
|
|
|
services,
|
2019-10-14 14:41:41 +00:00
|
|
|
serviceDisplayValue,
|
2019-10-17 11:59:18 +00:00
|
|
|
fetchServiceAccounts,
|
2019-10-09 20:50:03 +00:00
|
|
|
errors,
|
2019-10-14 14:41:41 +00:00
|
|
|
onChange,
|
|
|
|
serviceOnChange
|
2019-10-09 06:01:52 +00:00
|
|
|
}) => {
|
|
|
|
const classes = useStyles({});
|
|
|
|
const intl = useIntl();
|
2019-10-18 12:01:26 +00:00
|
|
|
const serviceAccountsError =
|
|
|
|
apiErrors.filter(error => error.field === null).length > 0;
|
|
|
|
|
2019-10-09 06:01:52 +00:00
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardTitle
|
|
|
|
title={intl.formatMessage({
|
2019-10-09 20:50:03 +00:00
|
|
|
defaultMessage: "Webhook Information",
|
2019-10-09 06:01:52 +00:00
|
|
|
description: "section header"
|
|
|
|
})}
|
|
|
|
/>
|
2019-10-09 20:50:03 +00:00
|
|
|
<CardContent>
|
|
|
|
<Typography className={classes.title}>
|
2019-10-11 13:35:33 +00:00
|
|
|
{intl.formatMessage(commonMessages.generalInformations)}
|
2019-10-09 20:50:03 +00:00
|
|
|
</Typography>
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.name}
|
|
|
|
helperText={errors.name}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Webhook Name",
|
|
|
|
description: "webhook"
|
|
|
|
})}
|
|
|
|
fullWidth
|
|
|
|
name="name"
|
|
|
|
value={data.name}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<Hr />
|
|
|
|
<FormSpacer />
|
|
|
|
<Typography className={classes.title}>
|
|
|
|
{intl.formatMessage({
|
|
|
|
defaultMessage: "Webhook specific information",
|
|
|
|
description: "webhook specific information"
|
|
|
|
})}
|
|
|
|
</Typography>
|
2019-10-11 13:35:33 +00:00
|
|
|
<SingleAutocompleteSelectField
|
|
|
|
disabled={disabled}
|
2019-10-14 14:41:41 +00:00
|
|
|
displayValue={serviceDisplayValue}
|
2019-10-09 20:50:03 +00:00
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Assign to Service Account"
|
|
|
|
})}
|
2019-10-18 12:01:26 +00:00
|
|
|
error={serviceAccountsError}
|
|
|
|
helperText={
|
|
|
|
serviceAccountsError &&
|
2019-10-18 12:33:05 +00:00
|
|
|
intl.formatMessage(commonMessages.requiredField)
|
2019-10-18 12:01:26 +00:00
|
|
|
}
|
2019-10-11 13:35:33 +00:00
|
|
|
name="serviceAccount"
|
2019-10-14 14:41:41 +00:00
|
|
|
onChange={serviceOnChange}
|
2019-10-11 13:35:33 +00:00
|
|
|
value={data.serviceAccount}
|
2019-10-14 14:41:41 +00:00
|
|
|
choices={services}
|
2019-10-17 11:59:18 +00:00
|
|
|
fetchChoices={fetchServiceAccounts}
|
2019-10-11 13:35:33 +00:00
|
|
|
InputProps={{
|
|
|
|
autoComplete: "off"
|
|
|
|
}}
|
2019-10-09 20:50:03 +00:00
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.targetUrl}
|
|
|
|
helperText={intl.formatMessage({
|
2019-10-17 11:59:18 +00:00
|
|
|
defaultMessage: "This URL will receive webhook POST requests",
|
2019-10-09 20:50:03 +00:00
|
|
|
description: "webhook target url help text"
|
|
|
|
})}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Target URL",
|
|
|
|
description: "webhook"
|
|
|
|
})}
|
|
|
|
fullWidth
|
|
|
|
name="targetUrl"
|
|
|
|
value={data.targetUrl}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<TextField
|
|
|
|
disabled={disabled}
|
|
|
|
error={!!errors.secretKey}
|
|
|
|
helperText={intl.formatMessage({
|
|
|
|
defaultMessage:
|
|
|
|
"secret key is used to create a hash signature with each payload. *optional field",
|
|
|
|
description: "webhook secret key help text"
|
|
|
|
})}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Secrect Key",
|
|
|
|
description: "webhook"
|
|
|
|
})}
|
|
|
|
fullWidth
|
|
|
|
name="secretKey"
|
|
|
|
value={data.secretKey}
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
</CardContent>
|
2019-10-09 06:01:52 +00:00
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
WebhookInfo.displayName = "WebhookInfo";
|
|
|
|
export default WebhookInfo;
|