saleor-dashboard/src/webhooks/components/WebhookInfo/WebhookInfo.tsx

141 lines
4.1 KiB
TypeScript
Raw Normal View History

2019-10-09 06:01:52 +00:00
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
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 makeStyles from "@material-ui/styles/makeStyles";
import React from "react";
2019-10-09 20:50:03 +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-09 20:50:03 +00:00
import SingleSelectField from "@saleor/components/SingleSelectField";
2019-10-11 13:35:33 +00:00
import { SingleAutocompleteSelectField } from "@saleor/components/SingleAutocompleteSelectField";
import { commonMessages } from "@saleor/intl";
2019-10-09 20:50:03 +00:00
import { FormErrors } from "@saleor/types";
2019-10-09 06:01:52 +00:00
import { FormData } from "../WebhooksDetailsPage";
2019-10-09 20:50:03 +00:00
import { ServiceList_serviceAccounts_edges_node } from "../../types/ServiceList";
2019-10-09 06:01:52 +00:00
interface WebhookInfoProps {
data: FormData;
2019-10-09 20:50:03 +00:00
disabled: boolean;
services: ServiceList_serviceAccounts_edges_node[];
errors: FormErrors<"name" | "targetUrl" | "secretKey">;
2019-10-09 06:01:52 +00:00
onChange: (event: React.ChangeEvent<any>) => void;
}
const useStyles = makeStyles(() => ({
status: {
paddingTop: 20
},
title: {
2019-10-09 20:50:03 +00:00
fontSize: 16,
lineHeight: 1.9,
paddingBottom: 10
2019-10-09 06:01:52 +00:00
}
}));
const WebhookInfo: React.StatelessComponent<WebhookInfoProps> = ({
data,
2019-10-09 20:50:03 +00:00
disabled,
services,
errors,
2019-10-09 06:01:52 +00:00
onChange
}) => {
const classes = useStyles({});
const intl = useIntl();
2019-10-09 20:50:03 +00:00
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}
displayValue={data.serviceAccount}
2019-10-09 20:50:03 +00:00
label={intl.formatMessage({
defaultMessage: "Assign to Service Account"
})}
2019-10-11 13:35:33 +00:00
name="serviceAccount"
2019-10-09 20:50:03 +00:00
onChange={onChange}
2019-10-11 13:35:33 +00:00
value={data.serviceAccount}
choices={services.map(service => ({
label: service.name,
value: service.id
}))}
InputProps={{
autoComplete: "off"
}}
2019-10-09 20:50:03 +00:00
/>
<FormSpacer />
<TextField
disabled={disabled}
error={!!errors.targetUrl}
helperText={intl.formatMessage({
defaultMessage: "This URL will recieve webhook POST requests",
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;