import React, { PureComponent } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { config } from '@grafana/runtime'; import { Form } from '@grafana/ui'; import Page from 'app/core/components/Page/Page'; import { getNavModel } from 'app/core/selectors/navModel'; import { NotificationChannelDTO, StoreState } from '../../types'; import { NotificationChannelForm } from './components/NotificationChannelForm'; import { createNotificationChannel, loadNotificationTypes, testNotificationChannel } from './state/actions'; import { resetSecureField } from './state/reducers'; import { defaultValues, mapChannelsToSelectableValue, transformSubmitData, transformTestData, } from './utils/notificationChannels'; class NewNotificationChannelPage extends PureComponent { componentDidMount() { this.props.loadNotificationTypes(); } onSubmit = (data: NotificationChannelDTO) => { this.props.createNotificationChannel(transformSubmitData({ ...defaultValues, ...data })); }; onTestChannel = (data: NotificationChannelDTO) => { this.props.testNotificationChannel(transformTestData({ ...defaultValues, ...data })); }; render() { const { navModel, notificationChannelTypes } = this.props; return (

New notification channel

{({ register, errors, control, getValues, watch }) => { const selectedChannel = notificationChannelTypes.find((c) => c.value === getValues().type.value); return ( ); }}
); } } const mapStateToProps = (state: StoreState) => ({ navModel: getNavModel(state.navIndex, 'channels'), notificationChannelTypes: state.notificationChannel.notificationChannelTypes, }); const mapDispatchToProps = { createNotificationChannel, loadNotificationTypes, testNotificationChannel, resetSecureField, }; const connector = connect(mapStateToProps, mapDispatchToProps); type Props = ConnectedProps; export default connector(NewNotificationChannelPage);