import React, { useState } from "react"; import { useGetGroupsQuery } from '../features/api/apiSlice' import { setGroupFilter } from "../features/callPlayer/callPlayerSlice"; import { useSelector, useDispatch } from 'react-redux' import { Modal, Button, Icon, Dropdown } from "semantic-ui-react"; import "./FilterModal.css"; function GroupModal (props) { const { data, isError, isLoading, isSuccess,error } = useGetGroupsQuery(props.shortName); const [open, setOpen] = useState(false); const [selectedGroup, setSelectedGroup] = useState(false); const dispatch = useDispatch() const onClose = props.onClose; function handleDone(onClose) { if (selectedGroup) { dispatch(setGroupFilter(selectedGroup)) //dispatch({type: types.SET_GROUP_FILTER, groupId: selectedGroup }) onClose(true); } else { onClose(false); } } let groupOptions = [] if (isSuccess) { for (const num in data) { const group = data[num]; var obj = { key: group._id, value: group._id, text: group.groupName } groupOptions.push(obj); } } return ( setOpen(false)} onOpen={() => setOpen(true)} size='tiny'> Select a Group Choose the type of calls you want to listen to setSelectedGroup(data.value)} /> handleDone(onClose)} > Listen ) } /* class GroupModal extends Component { constructor(props) { super(props) this.handleInputChange = this.handleInputChange.bind(this); this.handleDone = this.handleDone.bind(this); this.handleClose = this.handleClose.bind(this); this.state = { open: false, selectedGroup: false } } handleInputChange = (e, { name, value }) => this.setState({ [name]: value }); handleClose = () => this.props.onClose(false); handleDone(event) { if (this.state.selectedGroup) { this.props.callActions.setGroupFilter(this.state.selectedGroup); this.props.onClose(true); } else { this.props.onClose(false); } } componentDidUpdate(prevProps) { const filterChanged = (prevProps.selectedGroup !== this.props.selectedGroup); if (filterChanged) { this.setState({ selectedGroup: this.props.selectedGroup}); } } render() { var groupList = []; if (this.props.groups) { for (const num in this.props.groups) { const group = this.props.groups[num]; var obj = { key: group._id, value: group._id, text: group.groupName } groupList.push(obj); } } return ( Select a Group Choose the type of calls you want to listen to Listen ) } }*/ export default GroupModal;
Choose the type of calls you want to listen to