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 ; case WebhookType: return ; case PagerType: return ; default: return null; } }; return ( <> {title}
{ setSelectedConfig((state) => ({ ...state, name: event.target.value, })); }} /> {renderSettings()}
); } interface FormAlertChannelsProps { formInstance: FormInstance; type: ChannelType; setSelectedConfig: Dispatch< SetStateAction> >; 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;