Skip to content
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

Merged
merged 18 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/app/component/UsersAutocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@ const useStyles = makeStyles((theme) => ({
paddingRight: theme.spacing(1),
},
}));

/**
* This version get values from outside, this mean we already
* load in all relevant users from somewhere else
*/
const SearchUsers = ({ handleChange, users }) => {
const SearchUsers = ({ editable, handleChange, selected, users }) => {
const classes = useStyles();

const reducer = (options, user) => {
if (!user.displayName && !user.phoneNumber) return options;
let searchString = user.displayName + user.phoneNumber;
let searchString = user.displayName + " " + user.phoneNumber;
options.push({ ...user, searchString });
return options;
};
const options = users?.reduce(reducer, []) || [];
const optionSelected = options.find((option) => option && selected && option.id === selected.id);
const defaultValue = editable ? optionSelected : "";
const value = !editable ? optionSelected : "";

return (
<Autocomplete
Expand All @@ -38,6 +42,8 @@ const SearchUsers = ({ handleChange, users }) => {
classes={{ root: classes.root }}
getOptionLabel={(user) => user.searchString}
onChange={(event, newValue) => handleChange(newValue)}
value={value}
defaultValue={defaultValue}
renderInput={(params) => (
<TextField
{...params}
Expand Down
3 changes: 2 additions & 1 deletion src/app/dashboard/Missions/ListView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { makeStyles } from "@material-ui/core/styles";
import React, { useEffect, useState } from "react";
import GroupWorkIcon from "@material-ui/icons/GroupWork";
import Divider from "@material-ui/core/Divider";
import EditView from "./MissionEditView";

import MuiExpansionPanel from "@material-ui/core/ExpansionPanel";
import MuiExpansionPanelSummary from "@material-ui/core/ExpansionPanelSummary";
import MuiExpansionPanelDetails from "@material-ui/core/ExpansionPanelDetails";
import Card from "@material-ui/core/Card";
import Paper from "@material-ui/core/Paper";

import EditView from "./MissionEditView";
import DetailsView from "./DetailsView";
import ListItem from "./ListItem";
import { Mission } from "../../model";
Expand Down Expand Up @@ -188,6 +188,7 @@ const MissionsListView = ({
setSelectedMission={setSelectedMission}
toListView={() => setView(Views.list)}
toDetailsView={toDetailsView}
volunteers={volunteers}
/>
)}
</Box>
Expand Down
90 changes: 89 additions & 1 deletion src/app/dashboard/Missions/MissionEditView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -30,6 +33,9 @@ const useStyles = makeStyles((theme) => ({
missionTypeText: {
paddingTop: theme.spacing(0.5),
},
label: {
fontWeight: 600,
},
rowLabel: {
fontWeight: 600,
marginTop: theme.spacing(2),
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Copy link
Collaborator

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

function changeFormValue(name, value) {
handleChange({ target: { name, value } });
}
Expand All @@ -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);
Expand All @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const getVolunteerAttribute = (selectedVolunteer, status, attr) => {
    if(selectedVolunteer && status === MissionStatus.tentative){
        return selectedVolunteer[attr]
   }
   return ""
}

{...,
tentativeVolunteerUid = getVolunteerAttribute(selectedVolunteer, values.status, "volunteerUid")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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();
});
Expand Down Expand Up @@ -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
Expand Down