import { useEffect , useState } from 'react' ; import useAttempt from 'shared/hooks/useAttemptNext' ; import { Resource } from 'teleport/services/resources' ; import useTeleport from 'teleport/useTeleport' ; export default function useAuthConnectors ( ) { const ctx = useTeleport ( ) ; const [ items , setItems ] = useState < Resource < 'github' > [ ] > ( [ ] ) ; const { attempt , run } = useAttempt ( 'processing' ) ; function fetchData ( ) { return ctx . resourceService . fetchGithubConnectors ( ) . then ( response => { setItems ( response ) ; } ) ; } function save ( yaml , isNew ) { if ( isNew ) { return ctx . resourceService . createGithubConnector ( yaml ) . then ( fetchData ) ; } return ctx . resourceService . updateGithubConnector ( yaml ) . then ( fetchData ) ; } function remove ( name ) { return ctx . resourceService . deleteGithubConnector ( name ) . then ( fetchData ) ; } useEffect ( ( ) => { run ( ( ) => fetchData ( ) ) ; } , [ ] ) ; return { items , attempt , save , remove , } ; } export type State = ReturnType < typeof useAuthConnectors > ;