Complete Invite backend requests
This commit is contained in:
parent
545a265a27
commit
8dbe2185de
@ -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,20 +107,33 @@ export default function Invite() {
|
||||
<Panel className={'app-container'}>
|
||||
<Form className={'av-container'}>
|
||||
<div className={'interval-selector'}>
|
||||
{status.error || status.success ? (
|
||||
<Message
|
||||
showIcon
|
||||
type={status.success ? 'success' : 'error'}
|
||||
description={status.message}
|
||||
/>
|
||||
) : (
|
||||
<Message
|
||||
showIcon
|
||||
type='info'
|
||||
description='Add emails of participants. (Optional)'
|
||||
description='Add emails of participants.'
|
||||
/>
|
||||
)}
|
||||
{/* {!status.error && (
|
||||
|
||||
)} */}
|
||||
|
||||
<TagPicker
|
||||
block
|
||||
creatable
|
||||
searchable
|
||||
data={contactDropdown}
|
||||
value={participants}
|
||||
value={emailList}
|
||||
onSelect={(value) => handleSelect(value)}
|
||||
onChange={(value) => handleChange(value)}
|
||||
/>
|
||||
{!status.success && (
|
||||
<ButtonGroup justified>
|
||||
<Button
|
||||
appearance='ghost'
|
||||
@ -128,24 +143,28 @@ export default function Invite() {
|
||||
>
|
||||
Clear selection
|
||||
</Button>
|
||||
<Button appearance='primary' size='lg' block onClick={() => console.log("boo")}>
|
||||
<Button
|
||||
appearance='primary'
|
||||
size='lg'
|
||||
block
|
||||
onClick={() => handleSubmit()}
|
||||
>
|
||||
Send invites
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
<div className={'av-details'}>
|
||||
)}
|
||||
{status.success && (
|
||||
<ButtonGroup justified>
|
||||
<Button
|
||||
appearance='primary'
|
||||
size='lg'
|
||||
block
|
||||
onClick={() => {
|
||||
history.push('availability');
|
||||
}}
|
||||
onClick={() => history.push('dashboard')}
|
||||
>
|
||||
Add your availability
|
||||
Go to dashboard
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
)}
|
||||
</div>
|
||||
</Form>
|
||||
</Panel>
|
||||
|
Loading…
Reference in New Issue
Block a user