diff --git a/src/screens/Invite.js b/src/screens/Invite.js index 60c7487..8574e70 100644 --- a/src/screens/Invite.js +++ b/src/screens/Invite.js @@ -3,12 +3,18 @@ import { useHistory } from 'react-router-dom'; import { Panel, Form, Button, ButtonGroup, Message, TagPicker } from 'rsuite'; import { NavBar } from '../components'; +import { backend } from '../helpers/http-common'; import './styles/Invite.less'; import './styles/layout.less'; -export default function Invite() { - const [participants, setParticipants] = useState([]); +export default function Invite({ currentMeeting }) { + const [emailList, setEmailList] = useState([]); const [contactDropdown, setContactDropdown] = useState([]); + const [status, setStatus] = useState({ + error: null, + success: null, + message: '', + }); const history = useHistory(); @@ -48,56 +54,52 @@ export default function Invite() { }; const handleChange = (value) => { - setParticipants(value); + setEmailList(value); }; const handleClear = () => { setContactDropdown([]); - setParticipants([]); + setEmailList([]); }; - // const handleSubmit = () => { - // // Create a list of participants to post - // const participantsList = participants.map((participant) => { - // // + const handleSubmit = () => { + // Create a list of participants to post + const participantsList = emailList.map((email) => { + return { + email: email, + meeting_id: currentMeeting.id, + quorum: 0, // update when implementing functionality + mandatory: false, // update when implementing functionality + host: 0, // update when implementing functionality + answered: 0, + }; + }); - // return { - // account_id: '', - // meeting_id: currentMeeting.id, - // quorum: 0, // update when implementing functionality - // mandatory: false, // update when implementing functionality - // host: 0, // update when implementing functionality - // answered: 0, - // }; - // }); + // Create participants post request + const postParticipant = (data) => { + return backend.post('/participants', data); + }; - // // Create participants post request - // const postAvailability = (data) => { - // return backend.post('/participants', data); - // }; + const requests = participantsList.map((participant) => + postParticipant(participant), + ); - // const requests = participantsList.map((event) => - // postAvailability(event), - // ); - - // Promise.all(requests) - // .then(function (results) { - // // Add confirmation message - // setStatus({ - // success: true, - // error: false, - // message: 'Your availability has been added to the meeting.', - // }); - // }) - // .catch((error) => { - // setStatus({ - // error: true, - // success: false, - // message: - // "Your availability couldn't be added to the meeting.", - // }); - // }); - // }; + Promise.all(requests) + .then(function (results) { + setStatus({ + success: true, + error: false, + message: 'Participants successfully invited.', + }); + }) + .catch((error) => { + setStatus({ + error: true, + success: false, + message: "Participants couldn't be added.", + }); + }); + }; return ( <> @@ -105,47 +107,64 @@ export default function Invite() {
- + {status.error || status.success ? ( + + ) : ( + + )} + {/* {!status.error && ( + + )} */} + handleSelect(value)} onChange={(value) => handleChange(value)} /> - - - - -
-
- - - + {!status.success && ( + + + + + )} + {status.success && ( + + + + )}