Complete Invite backend requests

This commit is contained in:
rui hildt 2020-08-28 16:07:27 +02:00
parent 545a265a27
commit 8dbe2185de

View File

@ -3,12 +3,18 @@ import { useHistory } from 'react-router-dom';
import { Panel, Form, Button, ButtonGroup, Message, TagPicker } from 'rsuite'; import { Panel, Form, Button, ButtonGroup, Message, TagPicker } from 'rsuite';
import { NavBar } from '../components'; import { NavBar } from '../components';
import { backend } from '../helpers/http-common';
import './styles/Invite.less'; import './styles/Invite.less';
import './styles/layout.less'; import './styles/layout.less';
export default function Invite() { export default function Invite({ currentMeeting }) {
const [participants, setParticipants] = useState([]); const [emailList, setEmailList] = useState([]);
const [contactDropdown, setContactDropdown] = useState([]); const [contactDropdown, setContactDropdown] = useState([]);
const [status, setStatus] = useState({
error: null,
success: null,
message: '',
});
const history = useHistory(); const history = useHistory();
@ -48,56 +54,52 @@ export default function Invite() {
}; };
const handleChange = (value) => { const handleChange = (value) => {
setParticipants(value); setEmailList(value);
}; };
const handleClear = () => { const handleClear = () => {
setContactDropdown([]); setContactDropdown([]);
setParticipants([]); setEmailList([]);
}; };
// const handleSubmit = () => { const handleSubmit = () => {
// // Create a list of participants to post // Create a list of participants to post
// const participantsList = participants.map((participant) => { 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 { // Create participants post request
// account_id: '', const postParticipant = (data) => {
// meeting_id: currentMeeting.id, return backend.post('/participants', data);
// 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 requests = participantsList.map((participant) =>
// const postAvailability = (data) => { postParticipant(participant),
// return backend.post('/participants', data); );
// };
// const requests = participantsList.map((event) => Promise.all(requests)
// postAvailability(event), .then(function (results) {
// ); setStatus({
success: true,
// Promise.all(requests) error: false,
// .then(function (results) { message: 'Participants successfully invited.',
// // Add confirmation message });
// setStatus({ })
// success: true, .catch((error) => {
// error: false, setStatus({
// message: 'Your availability has been added to the meeting.', error: true,
// }); success: false,
// }) message: "Participants couldn't be added.",
// .catch((error) => { });
// setStatus({ });
// error: true, };
// success: false,
// message:
// "Your availability couldn't be added to the meeting.",
// });
// });
// };
return ( return (
<> <>
@ -105,20 +107,33 @@ export default function Invite() {
<Panel className={'app-container'}> <Panel className={'app-container'}>
<Form className={'av-container'}> <Form className={'av-container'}>
<div className={'interval-selector'}> <div className={'interval-selector'}>
{status.error || status.success ? (
<Message
showIcon
type={status.success ? 'success' : 'error'}
description={status.message}
/>
) : (
<Message <Message
showIcon showIcon
type='info' type='info'
description='Add emails of participants. (Optional)' description='Add emails of participants.'
/> />
)}
{/* {!status.error && (
)} */}
<TagPicker <TagPicker
block block
creatable creatable
searchable searchable
data={contactDropdown} data={contactDropdown}
value={participants} value={emailList}
onSelect={(value) => handleSelect(value)} onSelect={(value) => handleSelect(value)}
onChange={(value) => handleChange(value)} onChange={(value) => handleChange(value)}
/> />
{!status.success && (
<ButtonGroup justified> <ButtonGroup justified>
<Button <Button
appearance='ghost' appearance='ghost'
@ -128,24 +143,28 @@ export default function Invite() {
> >
Clear selection Clear selection
</Button> </Button>
<Button appearance='primary' size='lg' block onClick={() => console.log("boo")}> <Button
appearance='primary'
size='lg'
block
onClick={() => handleSubmit()}
>
Send invites Send invites
</Button> </Button>
</ButtonGroup> </ButtonGroup>
</div> )}
<div className={'av-details'}> {status.success && (
<ButtonGroup justified> <ButtonGroup justified>
<Button <Button
appearance='primary' appearance='primary'
size='lg' size='lg'
block block
onClick={() => { onClick={() => history.push('dashboard')}
history.push('availability');
}}
> >
Add your availability Go to dashboard
</Button> </Button>
</ButtonGroup> </ButtonGroup>
)}
</div> </div>
</Form> </Form>
</Panel> </Panel>