2021-11-22 11:49:09 +05:30
|
|
|
import { Form, FormInstance, Input, Select, Typography } from 'antd';
|
|
|
|
|
import FormItem from 'antd/lib/form/FormItem';
|
2022-03-24 12:06:57 +05:30
|
|
|
import { Store } from 'antd/lib/form/interface';
|
2022-03-22 12:10:31 +05:30
|
|
|
import ROUTES from 'constants/routes';
|
2021-11-22 11:49:09 +05:30
|
|
|
import {
|
|
|
|
|
ChannelType,
|
|
|
|
|
SlackChannel,
|
|
|
|
|
} from 'container/CreateAlertChannels/config';
|
|
|
|
|
import history from 'lib/history';
|
2022-03-22 12:10:31 +05:30
|
|
|
import React from 'react';
|
2021-11-22 11:49:09 +05:30
|
|
|
|
|
|
|
|
import SlackSettings from './Settings/Slack';
|
|
|
|
|
import { Button } from './styles';
|
|
|
|
|
|
2022-03-22 12:10:31 +05:30
|
|
|
const { Option } = Select;
|
|
|
|
|
const { Title } = Typography;
|
|
|
|
|
|
|
|
|
|
function FormAlertChannels({
|
2021-11-22 11:49:09 +05:30
|
|
|
formInstance,
|
|
|
|
|
type,
|
|
|
|
|
setSelectedConfig,
|
|
|
|
|
onTypeChangeHandler,
|
2021-12-02 20:32:08 +05:30
|
|
|
// onTestHandler,
|
2021-11-22 11:49:09 +05:30
|
|
|
onSaveHandler,
|
|
|
|
|
savingState,
|
|
|
|
|
NotificationElement,
|
|
|
|
|
title,
|
|
|
|
|
initialValue,
|
|
|
|
|
nameDisable = false,
|
2022-03-22 12:10:31 +05:30
|
|
|
}: FormAlertChannelsProps): JSX.Element {
|
2021-11-22 11:49:09 +05:30
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{NotificationElement}
|
|
|
|
|
|
|
|
|
|
<Title level={3}>{title}</Title>
|
|
|
|
|
|
|
|
|
|
<Form initialValues={initialValue} layout="vertical" form={formInstance}>
|
|
|
|
|
<FormItem label="Name" labelAlign="left" name="name">
|
|
|
|
|
<Input
|
|
|
|
|
disabled={nameDisable}
|
|
|
|
|
onChange={(event): void => {
|
|
|
|
|
setSelectedConfig((state) => ({
|
|
|
|
|
...state,
|
|
|
|
|
name: event.target.value,
|
|
|
|
|
}));
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem label="Type" labelAlign="left" name="type">
|
|
|
|
|
<Select onChange={onTypeChangeHandler} value={type}>
|
|
|
|
|
<Option value="slack" key="slack">
|
|
|
|
|
Slack
|
|
|
|
|
</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem>
|
|
|
|
|
{type === 'slack' && (
|
|
|
|
|
<SlackSettings setSelectedConfig={setSelectedConfig} />
|
|
|
|
|
)}
|
|
|
|
|
</FormItem>
|
|
|
|
|
|
|
|
|
|
<FormItem>
|
|
|
|
|
<Button
|
|
|
|
|
disabled={savingState}
|
|
|
|
|
loading={savingState}
|
|
|
|
|
type="primary"
|
|
|
|
|
onClick={(): void => onSaveHandler(type)}
|
|
|
|
|
>
|
|
|
|
|
Save
|
|
|
|
|
</Button>
|
|
|
|
|
{/* <Button onClick={onTestHandler}>Test</Button> */}
|
|
|
|
|
<Button
|
|
|
|
|
onClick={(): void => {
|
|
|
|
|
history.replace(ROUTES.SETTINGS);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Back
|
|
|
|
|
</Button>
|
|
|
|
|
</FormItem>
|
|
|
|
|
</Form>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-11-22 11:49:09 +05:30
|
|
|
|
|
|
|
|
interface FormAlertChannelsProps {
|
|
|
|
|
formInstance: FormInstance;
|
|
|
|
|
type: ChannelType;
|
|
|
|
|
setSelectedConfig: React.Dispatch<React.SetStateAction<Partial<SlackChannel>>>;
|
|
|
|
|
onTypeChangeHandler: (value: ChannelType) => void;
|
|
|
|
|
onSaveHandler: (props: ChannelType) => void;
|
|
|
|
|
savingState: boolean;
|
|
|
|
|
NotificationElement: React.ReactElement<
|
2021-12-02 20:32:08 +05:30
|
|
|
unknown,
|
|
|
|
|
string | React.JSXElementConstructor<unknown>
|
2021-11-22 11:49:09 +05:30
|
|
|
>;
|
|
|
|
|
title: string;
|
|
|
|
|
initialValue: Store;
|
|
|
|
|
nameDisable?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
FormAlertChannels.defaultProps = {
|
|
|
|
|
nameDisable: undefined,
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-22 11:49:09 +05:30
|
|
|
export default FormAlertChannels;
|