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

113 lines
3.6 KiB
TypeScript
Raw Normal View History

2019-10-09 06:01:52 +00:00
import Typography from "@material-ui/core/Typography";
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 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";
import { ConfigurationItemInput } from "@saleor/types/globalTypes";
import React from "react";
import { useIntl } from "react-intl";
2019-10-09 06:56:46 +00:00
import {
Webhook_webhook,
Webhook_webhook_events,
Webhook_webhook_serviceAccount
} 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;
events: Webhook_webhook_events;
isActive: boolean;
secretKey: string | null;
targetUrl: string;
serviceAccount: Webhook_webhook_serviceAccount;
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 06:01:52 +00:00
saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
onSubmit: (data: FormData) => void;
}
const WebhooksDetailsPage: React.StatelessComponent<
WebhooksDetailsPageProps
2019-10-09 06:56:46 +00:00
> = ({ disabled, errors, webhook, saveButtonBarState, onBack, onSubmit }) => {
2019-10-09 06:01:52 +00:00
const intl = useIntl();
const initialForm: FormData = {
2019-10-09 06:56:46 +00:00
events: maybe(() => webhook.events, []),
id: maybe(() => webhook.id, null),
isActive: maybe(() => webhook.isActive, false),
secretKey: maybe(() => webhook.secretKey, ""),
serviceAccount: maybe(() => webhook.serviceAccount, []),
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"
},
{
pluginName: maybe(() => plugin.name, "...")
}
)}
/>
<Grid variant="inverted">
2019-10-09 06:56:46 +00:00
<div>
<WebhookInfo
data={data}
description={maybe(() => plugin.description, "")}
errors={errors}
onChange={change}
/>
</div>
<div>
<WebhookEvents
data={data}
errors={errors}
name={maybe(() => plugin.name, "")}
onChange={change}
/>
<WebhookStatus
data={data}
errors={errors}
name={maybe(() => plugin.name, "")}
onChange={change}
/>
</div>
2019-10-09 06:01:52 +00:00
</Grid>
<SaveButtonBar
disabled={disabled || !hasChanged}
state={saveButtonBarState}
onCancel={onBack}
onSave={submit}
/>
</Container>
);
}}
</Form>
);
};
WebhooksDetailsPage.displayName = "WebhooksDetailsPage";
export default WebhooksDetailsPage;