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

131 lines
3.8 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-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 CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer";
import Hr from "@saleor/components/Hr";
import { WebhookErrorFragment } from "@saleor/fragments/types/WebhookErrorFragment";
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";
import React from "react";
import { useIntl } from "react-intl";
2019-10-09 06:01:52 +00:00
import { FormData } from "../WebhooksDetailsPage";
interface WebhookInfoProps {
data: FormData;
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-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
const WebhookInfo: React.FC<WebhookInfoProps> = ({
2019-10-09 06:01:52 +00:00
data,
2019-10-09 20:50:03 +00:00
disabled,
errors,
Apps (#599) * create Apps view * create more app components, generate types and messages * apps refactor, update snapshots * show error message in tooltip when app installation fail * update apps components and view, add apps list to storybook * update defaultMessages * create app details view * update AppListPage with Skeleton component * create app activate/deactivate dialogs, create app details stories * add AppHeader to AppDetailsPage * update defaultMessages * update AppDetails view and components after review * create custom app details view * refactor webhooks * update webhooks fixtures * update WebhookDetailsPage story * update strings * create CustomAppCreate view and components * update AppListPage story * create AppInstall view and page * handle errors in AppInstall view * update defaultMessages * add AppInstallPage to storybook * add status prop to MessageManager * update defaultMessages * remove service account section * remove service account routes * remove as operator from notify status * add notifications for app installations * update styles for deactivated app * update app installations with local storage * update defaultMessages * AppInstall update * dd delete button to ongoin installations table * fix active installations condition * fix error messages in AppsList * update defaultMessages * add iframe to AppDetailsPage * create AppDetailsSettingsPage * install macaw-ui * apps styles clean up * update schema, fixtures * few apps updates * WebhookCreate - fix onBack button name * WebhookCreatePage story update * rename apps table from external to thirdparty * update defaultMessages * fix test, update snapshots * AppDetailsSettings - add token to headers * fix first number in local apps query * app details settings - use shop domain host * add onSettingsRowClick to InstalledApps * resolve conflicts * update changelog and messages * add noopener noreferrer do app privacy link * update snapshots * update snapshots * updates after review * update defaultMessages * CustomAppDetails - add missing notify status
2020-07-22 10:54:15 +00:00
onChange
2019-10-09 06:01:52 +00:00
}) => {
const classes = useStyles({});
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>
<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}
2020-03-18 11:03:20 +00:00
error={!!formErrors.name}
helperText={getWebhookErrorMessage(formErrors.name, intl)}
2019-10-09 20:50:03 +00:00
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>
<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) ||
2020-02-24 14:14:48 +00:00
intl.formatMessage({
defaultMessage: "This URL will receive webhook POST requests",
description: "webhook target url help text"
})
}
2019-10-09 20:50:03 +00:00
label={intl.formatMessage({
defaultMessage: "Target URL",
description: "webhook"
})}
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) ||
2020-02-24 14:14:48 +00:00
intl.formatMessage({
defaultMessage:
"secret key is used to create a hash signature with each payload. *optional field",
description: "webhook secret key help text"
})
}
2019-10-09 20:50:03 +00:00
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;