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

128 lines
3.6 KiB
TypeScript
Raw Normal View History

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";
import { WebhookErrorFragment } from "@saleor/fragments/types/WebhookErrorFragment";
2019-10-11 13:35:33 +00:00
import { commonMessages } from "@saleor/intl";
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
import { makeStyles } 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";
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({
2021-04-14 07:39:34 +00:00
defaultMessage: "Secret Key",
2019-10-09 20:50:03 +00:00
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;