2019-10-09 20:50:03 +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";
|
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
|
|
|
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-10 11:40:31 +00:00
|
|
|
import { WebhookEventTypeEnum } from "@saleor/types/globalTypes";
|
2019-10-09 20:50:03 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
import { ServiceList_serviceAccounts_edges_node } from "../../types/ServiceList";
|
|
|
|
import WebhookEvents from "../WebhookEvents";
|
|
|
|
import WebhookInfo from "../WebhookInfo";
|
|
|
|
import WebhookStatus from "../WebhookStatus";
|
|
|
|
|
|
|
|
export interface FormData {
|
|
|
|
id: string;
|
2019-10-10 11:40:31 +00:00
|
|
|
events: WebhookEventTypeEnum[];
|
2019-10-09 20:50:03 +00:00
|
|
|
isActive: boolean;
|
|
|
|
name: string;
|
|
|
|
secretKey: string | null;
|
|
|
|
targetUrl: string;
|
|
|
|
serviceAccount: string;
|
2019-10-10 11:40:31 +00:00
|
|
|
allEvents: boolean;
|
2019-10-09 20:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface WebhookCreatePageProps {
|
|
|
|
disabled: boolean;
|
|
|
|
errors: UserError[];
|
|
|
|
services: ServiceList_serviceAccounts_edges_node[];
|
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
|
|
onBack: () => void;
|
|
|
|
onSubmit: (data: FormData) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WebhookCreatePage: React.StatelessComponent<WebhookCreatePageProps> = ({
|
|
|
|
disabled,
|
|
|
|
errors,
|
|
|
|
saveButtonBarState,
|
|
|
|
services,
|
|
|
|
onBack,
|
|
|
|
onSubmit
|
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
const initialForm: FormData = {
|
2019-10-10 11:40:31 +00:00
|
|
|
allEvents: false,
|
2019-10-10 05:38:21 +00:00
|
|
|
events: [],
|
|
|
|
id: null,
|
|
|
|
isActive: false,
|
|
|
|
name: null,
|
|
|
|
secretKey: "",
|
|
|
|
serviceAccount: "",
|
|
|
|
targetUrl: ""
|
2019-10-09 20:50:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
|
|
|
|
{({ data, errors, hasChanged, submit, change }) => {
|
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<AppHeader onBack={onBack}>
|
|
|
|
{intl.formatMessage(sectionNames.plugins)}
|
|
|
|
</AppHeader>
|
|
|
|
<PageHeader
|
2019-10-10 05:38:21 +00:00
|
|
|
title={intl.formatMessage({
|
|
|
|
defaultMessage: "Create Webhook",
|
|
|
|
description: "header"
|
|
|
|
})}
|
2019-10-09 20:50:03 +00:00
|
|
|
/>
|
|
|
|
<Grid>
|
|
|
|
<div>
|
|
|
|
<WebhookInfo
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
services={maybe(() => services, [])}
|
|
|
|
errors={errors}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<WebhookEvents
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<FormSpacer />
|
|
|
|
<WebhookStatus
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Grid>
|
|
|
|
<SaveButtonBar
|
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
state={saveButtonBarState}
|
|
|
|
onCancel={onBack}
|
|
|
|
onSave={submit}
|
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
WebhookCreatePage.displayName = "WebhookCreatePage";
|
|
|
|
export default WebhookCreatePage;
|