2019-10-09 06:01:52 +00:00
|
|
|
import AppHeader from "@saleor/components/AppHeader";
|
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
|
|
|
import Container from "@saleor/components/Container";
|
|
|
|
import Form from "@saleor/components/Form";
|
2019-10-09 20:50:03 +00:00
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
2019-10-09 06:01:52 +00:00
|
|
|
import Grid from "@saleor/components/Grid";
|
|
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
|
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
|
|
|
import { sectionNames } from "@saleor/intl";
|
|
|
|
import { maybe } from "@saleor/misc";
|
|
|
|
import { UserError } from "@saleor/types";
|
2019-10-09 20:50:03 +00:00
|
|
|
import { WebhookEventTypeEnum } from "@saleor/types/globalTypes";
|
2019-10-09 06:01:52 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
2019-10-09 20:50:03 +00:00
|
|
|
import { ServiceList_serviceAccounts_edges_node } from "../../types/ServiceList";
|
2019-10-10 05:38:21 +00:00
|
|
|
import { Webhook_webhook } from "../../types/Webhook";
|
2019-10-09 06:01:52 +00:00
|
|
|
import WebhookEvents from "../WebhookEvents";
|
2019-10-09 06:56:46 +00:00
|
|
|
import WebhookInfo from "../WebhookInfo";
|
|
|
|
import WebhookStatus from "../WebhookStatus";
|
2019-10-09 06:01:52 +00:00
|
|
|
|
|
|
|
export interface FormData {
|
2019-10-09 06:56:46 +00:00
|
|
|
id: string;
|
2019-10-10 11:40:31 +00:00
|
|
|
events: WebhookEventTypeEnum[];
|
2019-10-09 06:56:46 +00:00
|
|
|
isActive: boolean;
|
2019-10-09 20:50:03 +00:00
|
|
|
name: string;
|
2019-10-09 06:56:46 +00:00
|
|
|
secretKey: string | null;
|
|
|
|
targetUrl: string;
|
2019-10-09 20:50:03 +00:00
|
|
|
serviceAccount: string;
|
2019-10-10 11:40:31 +00:00
|
|
|
allEvents: boolean;
|
2019-10-09 06:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface WebhooksDetailsPageProps {
|
|
|
|
disabled: boolean;
|
|
|
|
errors: UserError[];
|
2019-10-09 06:56:46 +00:00
|
|
|
webhook: Webhook_webhook;
|
2019-10-09 20:50:03 +00:00
|
|
|
services: ServiceList_serviceAccounts_edges_node[];
|
2019-10-09 06:01:52 +00:00
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
|
|
onBack: () => void;
|
2019-10-10 05:38:21 +00:00
|
|
|
onDelete: () => void;
|
2019-10-09 06:01:52 +00:00
|
|
|
onSubmit: (data: FormData) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebhooksDetailsPage: React.StatelessComponent<
|
|
|
|
WebhooksDetailsPageProps
|
2019-10-09 20:50:03 +00:00
|
|
|
> = ({
|
|
|
|
disabled,
|
|
|
|
errors,
|
|
|
|
webhook,
|
|
|
|
saveButtonBarState,
|
|
|
|
services,
|
|
|
|
onBack,
|
2019-10-10 05:38:21 +00:00
|
|
|
onDelete,
|
2019-10-09 20:50:03 +00:00
|
|
|
onSubmit
|
|
|
|
}) => {
|
2019-10-09 06:01:52 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
const initialForm: FormData = {
|
2019-10-10 11:40:31 +00:00
|
|
|
allEvents: maybe(
|
|
|
|
() =>
|
2019-10-10 14:19:06 +00:00
|
|
|
maybe(() => webhook.events, [])[0].eventType ===
|
|
|
|
WebhookEventTypeEnum.ALL_EVENTS,
|
2019-10-10 11:40:31 +00:00
|
|
|
false
|
|
|
|
),
|
2019-10-10 05:38:21 +00:00
|
|
|
events: maybe(() => webhook.events, []).map(event => event.eventType),
|
2019-10-09 06:56:46 +00:00
|
|
|
id: maybe(() => webhook.id, null),
|
|
|
|
isActive: maybe(() => webhook.isActive, false),
|
2019-10-09 20:50:03 +00:00
|
|
|
name: maybe(() => webhook.name, ""),
|
2019-10-09 06:56:46 +00:00
|
|
|
secretKey: maybe(() => webhook.secretKey, ""),
|
2019-10-09 20:50:03 +00:00
|
|
|
serviceAccount: maybe(() => webhook.serviceAccount.id, ""),
|
2019-10-09 06:56:46 +00:00
|
|
|
targetUrl: maybe(() => webhook.targetUrl, "")
|
2019-10-09 06:01:52 +00:00
|
|
|
};
|
|
|
|
return (
|
|
|
|
<Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
|
2019-10-09 06:56:46 +00:00
|
|
|
{({ data, errors, hasChanged, submit, change }) => {
|
2019-10-09 06:01:52 +00:00
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<AppHeader onBack={onBack}>
|
|
|
|
{intl.formatMessage(sectionNames.plugins)}
|
|
|
|
</AppHeader>
|
|
|
|
<PageHeader
|
|
|
|
title={intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "{pluginName} Details",
|
|
|
|
description: "header"
|
|
|
|
},
|
|
|
|
{
|
2019-10-09 20:50:03 +00:00
|
|
|
pluginName: maybe(() => webhook.name, "...")
|
2019-10-09 06:01:52 +00:00
|
|
|
}
|
|
|
|
)}
|
|
|
|
/>
|
2019-10-09 20:50:03 +00:00
|
|
|
<Grid>
|
2019-10-09 06:56:46 +00:00
|
|
|
<div>
|
|
|
|
<WebhookInfo
|
|
|
|
data={data}
|
2019-10-09 20:50:03 +00:00
|
|
|
disabled={disabled}
|
|
|
|
services={maybe(() => services, [])}
|
2019-10-09 06:56:46 +00:00
|
|
|
errors={errors}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<WebhookEvents
|
|
|
|
data={data}
|
|
|
|
onChange={change}
|
2019-10-10 11:40:31 +00:00
|
|
|
disabled={disabled}
|
2019-10-09 06:56:46 +00:00
|
|
|
/>
|
2019-10-09 20:50:03 +00:00
|
|
|
<FormSpacer />
|
2019-10-09 06:56:46 +00:00
|
|
|
<WebhookStatus
|
|
|
|
data={data}
|
2019-10-09 20:50:03 +00:00
|
|
|
disabled={disabled}
|
2019-10-09 06:56:46 +00:00
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-10-09 06:01:52 +00:00
|
|
|
</Grid>
|
|
|
|
<SaveButtonBar
|
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
state={saveButtonBarState}
|
|
|
|
onCancel={onBack}
|
|
|
|
onSave={submit}
|
2019-10-10 05:38:21 +00:00
|
|
|
onDelete={onDelete}
|
2019-10-09 06:01:52 +00:00
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
WebhooksDetailsPage.displayName = "WebhooksDetailsPage";
|
|
|
|
export default WebhooksDetailsPage;
|