Skip to content

Commit

Permalink
Merge pull request #462 from bounswe/feature/victim_request
Browse files Browse the repository at this point in the history
Request creation is enhanced with the focus on recurrent needs, multiple victim needs, in-depth analysis of needs
  • Loading branch information
kubraaksux authored Nov 27, 2023
2 parents d4da772 + d974e8f commit 255988b
Show file tree
Hide file tree
Showing 7 changed files with 1,153 additions and 100 deletions.
1 change: 1 addition & 0 deletions resq/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@emotion/styled": "^11.11.0",
"@fontsource/inter": "^5.0.15",
"@mui/icons-material": "^5.14.14",
"@mui/joy": "^5.0.0-beta.15",
"@mui/material": "^5.14.14",
"@mui/styled-engine": "^5.14.14",
"@mui/x-data-grid": "^6.18.1",
Expand Down
62 changes: 0 additions & 62 deletions resq/frontend/src/components/RequestDetails.js

This file was deleted.

226 changes: 226 additions & 0 deletions resq/frontend/src/components/RequestDetails1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import * as React from 'react';
import { useState } from 'react';
import { styled } from '@mui/material/styles';
import NativeSelect from '@mui/material/NativeSelect';
import InputBase from '@mui/material/InputBase';
import { Typography, Grid, FormControlLabel, Checkbox, TextField, Chip, Box, FormControl, InputLabel, Select, MenuItem, OutlinedInput } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import { createTheme } from '@mui/material/styles';
import { FormHelperText } from '@mui/material';

const illnesses = [
'Diabetes',
'Gluten Allergy',
'Lactose Intolerance',
'Nut Allergy',
'Vegan',
// Add more as needed
];

const customTheme = createTheme({
palette: {
primary: {
main: '#FF0000',
},
},
});

// Function to get styles for menu items (from your MultipleSelectChip component)
function getStyles(name, selectedNames, customTheme) {
return {
fontWeight:
selectedNames.indexOf(name) === -1
? customTheme.typography.fontWeightRegular
: customTheme.typography.fontWeightMedium,
};
}

function CustomizedSelects() {
const [adults, setAdults] = useState('');
const [children, setChildren] = useState('');
const [baby, setBaby] = useState('');
const [totalPeople, setTotalPeople] = useState('');

const handleTotalPeopleChange = (event) => {
const newValue = Math.max(0, event.target.value); // Prevents values less than 0
setTotalPeople(newValue);
};

const handleAdultsChange = (event) => {
const newValue = Math.max(0, event.target.value); // Prevents values less than 0
setAdults(newValue);
};

const handleChildrenChange = (event) => {
const newValue = Math.max(0, event.target.value); // Prevents values less than 0
setChildren(newValue);
};

const handleBabyChange = (event) => {
const newValue = Math.max(0, event.target.value); // Prevents values less than 0
setBaby(newValue);
};


return (
<Box display="flex" flexDirection="row" justifyContent="center" alignItems="center">
<Box display="flex" flexDirection="row" justifyContent="center" alignItems="center">
<FormControl sx={{ m: 1 }} variant="standard">
<TextField
id="total-people"
label="Total People"
value={totalPeople}
onChange={handleTotalPeopleChange}
type="number"
margin="normal"
variant="outlined"
InputLabelProps={{
shrink: true,
}}
/>
</FormControl>
<FormControl sx={{ m: 1 }} variant="standard">
<TextField
id="adults-count"
label="Adults"
value={adults}
onChange={handleAdultsChange}
type="number"
margin="normal"
variant="outlined"
InputLabelProps={{
shrink: true,
}}
/>
</FormControl>
<FormControl sx={{ m: 1 }} variant="standard">
<TextField
id="children-count"
label="Children"
value={children}
onChange={handleChildrenChange}
type="number"
margin="normal"
variant="outlined"
InputLabelProps={{
shrink: true,
}}
/>
</FormControl>
<FormControl sx={{ m: 1 }} variant="standard">
<TextField
id="baby-count"
label="Baby"
value={baby}
onChange={handleBabyChange}
type="number"
margin="normal"
variant="outlined"
InputLabelProps={{
shrink: true,
}}
/>
</FormControl>
</Box>
</Box>
);
}

export default function RequestDetails() {

const [otherRestrictions, setOtherRestrictions] = useState('');
const [isWaterChecked, setIsWaterChecked] = useState(true);
const [isFoodChecked, setIsFoodChecked] = useState(true);
const [selectedIllnesses, setSelectedIllnesses] = useState([]);

const handleOtherRestrictionsChange = (event) => {
setOtherRestrictions(event.target.value);
};

const handleIllnessSelection = (illness) => {
// Toggle illness in the selected illnesses array
if (selectedIllnesses.includes(illness)) {
setSelectedIllnesses(selectedIllnesses.filter(item => item !== illness));
} else {
setSelectedIllnesses([...selectedIllnesses, illness]);
}
};

// Handle change in selected illnesses
const handleIllnessChange = (event) => {
setSelectedIllnesses(event.target.value);
};

// Menu properties
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};


return (
<React.Fragment>
<Typography variant="h6" gutterBottom>
Request Details
</Typography>
<Typography variant="h8" color="primary" font="bold" gutterBottom style={{ fontStyle: 'italic', fontWeight: 'bold' }}>
*Reccurrent Needs*
</Typography>
<CustomizedSelects />

<Grid container spacing={3}>
<Grid item xs={12} >
<FormControlLabel
control={<Checkbox color="primary" name="water" value="yes" checked={isWaterChecked} onChange={(e) => setIsWaterChecked(e.target.checked)} />}
label="Water"
/>
</Grid>
{/* Food Checkbox and Chip */}
<Grid item xs={12}>
<FormControlLabel
control={<Checkbox color="primary" name="food" value="yes" checked={isFoodChecked} onChange={(e) => setIsFoodChecked(e.target.checked)} />}
label="Food"
/>
{isFoodChecked && (
<FormControl sx={{ position: 'relative', top: '-10px', width: 300 }}>
<InputLabel id="demo-multiple-chip-label">Dietary Restrictions</InputLabel>
<Select
labelId="demo-multiple-chip-label"
id="demo-multiple-chip"
multiple
value={selectedIllnesses}
onChange={handleIllnessChange}
input={<OutlinedInput id="select-multiple-chip" label="Dietary Restrictions" />}
renderValue={(selected) => (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
{selected.map((value) => (
<Chip key={value} label={value} />
))}
</Box>
)}
MenuProps={MenuProps}
>
{illnesses.map((illness) => (
<MenuItem
key={illness}
value={illness}
style={getStyles(illness, selectedIllnesses, customTheme)}
>
{illness}
</MenuItem>
))}
</Select>
<FormHelperText style={{ color: 'red' }}>Multiple selection is allowed</FormHelperText>
</FormControl>
)}
</Grid>
</Grid>
</React.Fragment >
);
}
Loading

0 comments on commit 255988b

Please sign in to comment.