Complete Invite backend requests

This commit is contained in:
rui hildt 2020-08-28 16:07:27 +02:00
parent 545a265a27
commit 8dbe2185de
1 changed files with 95 additions and 76 deletions

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,47 +107,64 @@ 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'}>
<Message {status.error || status.success ? (
showIcon <Message
type='info' showIcon
description='Add emails of participants. (Optional)' type={status.success ? 'success' : 'error'}
/> description={status.message}
/>
) : (
<Message
showIcon
type='info'
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)}
/> />
<ButtonGroup justified> {!status.success && (
<Button <ButtonGroup justified>
appearance='ghost' <Button
block appearance='ghost'
size='lg' block
onClick={handleClear} size='lg'
> onClick={handleClear}
Clear selection >
</Button> Clear selection
<Button appearance='primary' size='lg' block onClick={() => console.log("boo")}> </Button>
Send invites <Button
</Button> appearance='primary'
</ButtonGroup> size='lg'
</div> block
<div className={'av-details'}> onClick={() => handleSubmit()}
<ButtonGroup justified> >
<Button Send invites
appearance='primary' </Button>
size='lg' </ButtonGroup>
block )}
onClick={() => { {status.success && (
history.push('availability'); <ButtonGroup justified>
}} <Button
> appearance='primary'
Add your availability size='lg'
</Button> block
</ButtonGroup> onClick={() => history.push('dashboard')}
>
Go to dashboard
</Button>
</ButtonGroup>
)}
</div> </div>
</Form> </Form>
</Panel> </Panel>