mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
* chore: added jsx-runtime plugin in eslint tsconfig Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * chore: updated react imports Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * chore: renamed redux dispatch Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * fix: build is fixed --------- Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> Co-authored-by: Palash Gupta <palashgdev@gmail.com>
137 lines
3.3 KiB
TypeScript
137 lines
3.3 KiB
TypeScript
import { Form, FormInstance, Input, Select, Typography } from 'antd';
|
|
import { Store } from 'antd/lib/form/interface';
|
|
import ROUTES from 'constants/routes';
|
|
import {
|
|
ChannelType,
|
|
PagerChannel,
|
|
PagerType,
|
|
SlackChannel,
|
|
SlackType,
|
|
WebhookChannel,
|
|
WebhookType,
|
|
} from 'container/CreateAlertChannels/config';
|
|
import history from 'lib/history';
|
|
import { Dispatch, ReactElement, SetStateAction } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import PagerSettings from './Settings/Pager';
|
|
import SlackSettings from './Settings/Slack';
|
|
import WebhookSettings from './Settings/Webhook';
|
|
import { Button } from './styles';
|
|
|
|
const { Option } = Select;
|
|
const { Title } = Typography;
|
|
|
|
function FormAlertChannels({
|
|
formInstance,
|
|
type,
|
|
setSelectedConfig,
|
|
onTypeChangeHandler,
|
|
onTestHandler,
|
|
onSaveHandler,
|
|
savingState,
|
|
testingState,
|
|
title,
|
|
initialValue,
|
|
editing = false,
|
|
}: FormAlertChannelsProps): JSX.Element {
|
|
const { t } = useTranslation('channels');
|
|
|
|
const renderSettings = (): ReactElement | null => {
|
|
switch (type) {
|
|
case SlackType:
|
|
return <SlackSettings setSelectedConfig={setSelectedConfig} />;
|
|
case WebhookType:
|
|
return <WebhookSettings setSelectedConfig={setSelectedConfig} />;
|
|
case PagerType:
|
|
return <PagerSettings setSelectedConfig={setSelectedConfig} />;
|
|
|
|
default:
|
|
return null;
|
|
}
|
|
};
|
|
return (
|
|
<>
|
|
<Title level={3}>{title}</Title>
|
|
|
|
<Form initialValues={initialValue} layout="vertical" form={formInstance}>
|
|
<Form.Item label={t('field_channel_name')} labelAlign="left" name="name">
|
|
<Input
|
|
disabled={editing}
|
|
onChange={(event): void => {
|
|
setSelectedConfig((state) => ({
|
|
...state,
|
|
name: event.target.value,
|
|
}));
|
|
}}
|
|
/>
|
|
</Form.Item>
|
|
|
|
<Form.Item label={t('field_channel_type')} labelAlign="left" name="type">
|
|
<Select disabled={editing} onChange={onTypeChangeHandler} value={type}>
|
|
<Option value="slack" key="slack">
|
|
Slack
|
|
</Option>
|
|
<Option value="webhook" key="webhook">
|
|
Webhook
|
|
</Option>
|
|
<Option value="pagerduty" key="pagerduty">
|
|
Pagerduty
|
|
</Option>
|
|
</Select>
|
|
</Form.Item>
|
|
|
|
<Form.Item>{renderSettings()}</Form.Item>
|
|
|
|
<Form.Item>
|
|
<Button
|
|
disabled={savingState}
|
|
loading={savingState}
|
|
type="primary"
|
|
onClick={(): void => onSaveHandler(type)}
|
|
>
|
|
{t('button_save_channel')}
|
|
</Button>
|
|
<Button
|
|
disabled={testingState}
|
|
loading={testingState}
|
|
onClick={(): void => onTestHandler(type)}
|
|
>
|
|
{t('button_test_channel')}
|
|
</Button>
|
|
<Button
|
|
onClick={(): void => {
|
|
history.replace(ROUTES.SETTINGS);
|
|
}}
|
|
>
|
|
{t('button_return')}
|
|
</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
</>
|
|
);
|
|
}
|
|
|
|
interface FormAlertChannelsProps {
|
|
formInstance: FormInstance;
|
|
type: ChannelType;
|
|
setSelectedConfig: Dispatch<
|
|
SetStateAction<Partial<SlackChannel & WebhookChannel & PagerChannel>>
|
|
>;
|
|
onTypeChangeHandler: (value: ChannelType) => void;
|
|
onSaveHandler: (props: ChannelType) => void;
|
|
onTestHandler: (props: ChannelType) => void;
|
|
testingState: boolean;
|
|
savingState: boolean;
|
|
title: string;
|
|
initialValue: Store;
|
|
// editing indicates if the form is opened in edit mode
|
|
editing?: boolean;
|
|
}
|
|
|
|
FormAlertChannels.defaultProps = {
|
|
editing: undefined,
|
|
};
|
|
|
|
export default FormAlertChannels;
|