-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding volunteer, ready-to-startinfo to organizer edit mission screen #613
Changes from all commits
842e1f2
49d37f6
47f350d
31c8b2f
c83ec02
3b27551
0f93e50
694fd47
2112c6d
c09cb8a
3d417fd
2eaeb0e
de18270
ded2f72
c72e256
8103481
f165a78
1e0cf18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,15 @@ import PersonIcon from "@material-ui/icons/Person"; | |
import React, { useState } from "react"; | ||
import { isEmpty, isLoaded } from "react-redux-firebase"; | ||
import { Button, Body2, H3 } from "../../component"; | ||
import Switch from "@material-ui/core/Switch"; | ||
import DateTimeInput from "../../component/DateTimeInput"; | ||
import ScheduleIcon from "@material-ui/icons/Schedule"; | ||
import { Mission } from "../../model"; | ||
import _ from "../../utils/lodash"; | ||
import AddressInput from "../../component/AddressInput"; | ||
import UsersAutocomplete from "../../component/UsersAutocomplete"; | ||
import { useForm } from "../../hooks"; | ||
import { MissionStatus } from "../../model/schema"; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
root: { | ||
|
@@ -30,6 +33,9 @@ const useStyles = makeStyles((theme) => ({ | |
missionTypeText: { | ||
paddingTop: theme.spacing(0.5), | ||
}, | ||
label: { | ||
fontWeight: 600, | ||
}, | ||
rowLabel: { | ||
fontWeight: 600, | ||
marginTop: theme.spacing(2), | ||
|
@@ -193,11 +199,20 @@ const MissionDetailsRow = ({ mission }) => { | |
return null; | ||
}; | ||
|
||
const volunteerStatus = [MissionStatus.unassigned, MissionStatus.tentative, MissionStatus.assigned]; | ||
|
||
const getVolunteerAttribute = (selectedVolunteer, status, attr, tentativeClause) => { | ||
if (selectedVolunteer && tentativeClause) { | ||
return selectedVolunteer[attr]; | ||
} | ||
return ""; | ||
}; | ||
|
||
/** | ||
* Component for editing mission details | ||
* @component | ||
*/ | ||
const MissionEditView = ({ mission, toDetailsView, toListView }) => { | ||
const MissionEditView = ({ mission, toDetailsView, toListView, volunteers }) => { | ||
const classes = useStyles(); | ||
|
||
const { handleChange, values } = useForm(mission); | ||
|
@@ -211,9 +226,14 @@ const MissionEditView = ({ mission, toDetailsView, toListView }) => { | |
date: values.deliveryWindow.startTime, | ||
location: "", | ||
}); | ||
const [selectedVolunteer, setSelectedVolunteer] = useState( | ||
volunteers.find((el) => el.id === mission.volunteerUid) | ||
); | ||
|
||
const props = { classes, mission }; | ||
|
||
const volunteerEditable = volunteerStatus.includes(mission.status); | ||
|
||
function changeFormValue(name, value) { | ||
handleChange({ target: { name, value } }); | ||
} | ||
|
@@ -223,6 +243,10 @@ const MissionEditView = ({ mission, toDetailsView, toListView }) => { | |
changeFormValue("location", location); | ||
} | ||
|
||
function handleChangeReadyToStart(e) { | ||
changeFormValue("readyToStart", e.target.checked); | ||
} | ||
|
||
function handleSave(e) { | ||
e.preventDefault(); | ||
const pickUpTime = new Date(pickUp.date); | ||
|
@@ -246,6 +270,43 @@ const MissionEditView = ({ mission, toDetailsView, toListView }) => { | |
deliveryWindow: { | ||
startTime: delivery.toString(), | ||
}, | ||
volunteerUid: getVolunteerAttribute( | ||
selectedVolunteer, | ||
values.status, | ||
"volunteerUid", | ||
values.status !== MissionStatus.tentative | ||
), | ||
volunteerDisplayname: getVolunteerAttribute( | ||
selectedVolunteer, | ||
values.status, | ||
"volunteerDisplayName", | ||
values.status !== MissionStatus.tentative | ||
), | ||
volunteerPhoneNumber: getVolunteerAttribute( | ||
selectedVolunteer, | ||
values.status, | ||
"volunteerPhoneNumber", | ||
values.status !== MissionStatus.tentative | ||
), | ||
tentativeVolunteerUid: getVolunteerAttribute( | ||
selectedVolunteer, | ||
values.status, | ||
"volunteerUid", | ||
values.status === MissionStatus.tentative | ||
), | ||
tentativeVolunteerDisplayName: getVolunteerAttribute( | ||
selectedVolunteer, | ||
values.status, | ||
"volunteerDisplayName", | ||
values.status === MissionStatus.tentative | ||
), | ||
tentativeVolunteerPhoneNumber: getVolunteerAttribute( | ||
selectedVolunteer, | ||
values.status, | ||
"volunteerPhoneNumber", | ||
values.status === MissionStatus.tentative | ||
), | ||
readyToStart: values.readyToStart, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to add one more param to the "getVolunteerAttribute" function but should capture what you are pointing out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It did not look as pretty as I had hope, my bad there, lets keep it for now |
||
}).then((result) => { | ||
toDetailsView(); | ||
}); | ||
|
@@ -384,6 +445,33 @@ const MissionEditView = ({ mission, toDetailsView, toListView }) => { | |
</Grid> | ||
</Grid> | ||
</Card> | ||
|
||
<Card label="Volunteer Information" classes={classes}> | ||
<UsersAutocomplete | ||
editable={volunteerEditable} | ||
handleChange={setSelectedVolunteer} | ||
users={volunteers} | ||
selected={selectedVolunteer} | ||
/> | ||
</Card> | ||
|
||
<Row classes={classes}> | ||
|
||
<Grid container direction="row" spacing={1} className={classes.rowBody}> | ||
<Grid item> | ||
<Switch | ||
size="normal" | ||
name="readyToStart" | ||
checked={values.readyToStart} | ||
onChange={handleChangeReadyToStart} | ||
/> | ||
</Grid> | ||
<Grid item className={classes.label}> | ||
Ready To Start? | ||
</Grid> | ||
</Grid> | ||
</Row> | ||
|
||
<Label classes={classes}>Delivery Notes</Label> | ||
<Row classes={classes}> | ||
<TextField | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outside of the class
const volunteerStatus = [MissionStatus.unassigned, MissionStatus.tentative, MissionStatus.assigned]
inside of the class
const volunteerEditable = volunteerStatus.includes(mission.status)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!