11// Libraries
22import React , { FC } from 'react'
3- import { withRouter , RouteComponentProps } from 'react-router-dom'
4- import { connect , ConnectedProps } from 'react-redux'
3+ import { useHistory } from 'react-router-dom'
4+ import { useDispatch , useSelector } from 'react-redux'
55
66// Actions
77import {
@@ -37,30 +37,20 @@ import {NotificationEndpoint, Label, AlertHistoryType} from 'src/types'
3737// Utilities
3838import { relativeTimestampFormatter } from 'src/shared/utils/relativeTimestampFormatter'
3939import ErrorBoundary from 'src/shared/components/ErrorBoundary'
40+ import { getOrg } from 'src/organizations/selectors'
4041
41- interface OwnProps {
42+ interface Props {
4243 endpoint : NotificationEndpoint
4344}
4445
45- type ReduxProps = ConnectedProps < typeof connector >
46- type Props = OwnProps & RouteComponentProps < { orgID : string } > & ReduxProps
47-
48- const EndpointCard : FC < Props > = ( {
49- history,
50- match : {
51- params : { orgID} ,
52- } ,
53- endpoint,
54- onUpdateEndpointProperties,
55- onCloneEndpoint,
56- onDeleteEndpoint,
57- onAddEndpointLabel,
58- onRemoveEndpointLabel,
59- } ) => {
46+ const EndpointCard : FC < Props > = ( { endpoint} ) => {
47+ const history = useHistory ( )
48+ const orgID = useSelector ( getOrg ) . id
49+ const dispatch = useDispatch ( )
6050 const { id, name, description, activeStatus} = endpoint
6151
6252 const handleUpdateName = ( name : string ) => {
63- onUpdateEndpointProperties ( id , { name} )
53+ dispatch ( updateEndpointProperties ( id , { name} ) )
6454 }
6555
6656 const handleClick = ( ) => {
@@ -69,7 +59,7 @@ const EndpointCard: FC<Props> = ({
6959
7060 const handleToggle = ( ) => {
7161 const toStatus = activeStatus === 'active' ? 'inactive' : 'active'
72- onUpdateEndpointProperties ( id , { status : toStatus } )
62+ dispatch ( updateEndpointProperties ( id , { status : toStatus } ) )
7363 }
7464
7565 const handleView = ( ) => {
@@ -83,10 +73,10 @@ const EndpointCard: FC<Props> = ({
8373 history . push ( `/orgs/${ orgID } /alert-history?${ queryParams } ` )
8474 }
8575 const handleDelete = ( ) => {
86- onDeleteEndpoint ( id )
76+ dispatch ( deleteEndpoint ( id ) )
8777 }
8878 const handleClone = ( ) => {
89- onCloneEndpoint ( endpoint )
79+ dispatch ( cloneEndpoint ( endpoint ) )
9080 }
9181 const contextMenu = (
9282 < EndpointCardMenu
@@ -97,14 +87,14 @@ const EndpointCard: FC<Props> = ({
9787 )
9888
9989 const handleAddEndpointLabel = ( label : Label ) => {
100- onAddEndpointLabel ( id , label )
90+ dispatch ( addEndpointLabel ( id , label ) )
10191 }
10292 const handleRemoveEndpointLabel = ( label : Label ) => {
103- onRemoveEndpointLabel ( id , label . id )
93+ dispatch ( deleteEndpointLabel ( id , label . id ) )
10494 }
10595
10696 const handleUpdateDescription = ( description : string ) => {
107- onUpdateEndpointProperties ( id , { description} )
97+ dispatch ( updateEndpointProperties ( id , { description} ) )
10898 }
10999
110100 return (
@@ -161,14 +151,4 @@ const EndpointCard: FC<Props> = ({
161151 )
162152}
163153
164- const mdtp = {
165- onDeleteEndpoint : deleteEndpoint ,
166- onAddEndpointLabel : addEndpointLabel ,
167- onRemoveEndpointLabel : deleteEndpointLabel ,
168- onUpdateEndpointProperties : updateEndpointProperties ,
169- onCloneEndpoint : cloneEndpoint ,
170- }
171-
172- const connector = connect ( null , mdtp )
173-
174- export default connector ( withRouter ( EndpointCard ) )
154+ export default EndpointCard
0 commit comments