|
1 | 1 | import * as React from 'react';
|
2 |
| -import Container from '@material-ui/core/Container'; |
3 |
| -import Typography from '@material-ui/core/Typography'; |
4 |
| -import Box from '@material-ui/core/Box'; |
5 |
| -import ProTip from '../src/ProTip'; |
6 |
| -import Link from '../src/Link'; |
7 |
| -import Copyright from '../src/Copyright'; |
| 2 | +import {Container, Typography, FormControl, Button, Grid, TextField, FormHelperText, FormControlLabel, Checkbox, FormGroup, FormLabel } from '@material-ui/core'; |
| 3 | +import {useState } from "react"; |
8 | 4 |
|
9 | 5 | export default function Index() {
|
| 6 | + |
| 7 | + const [formValues, setFormValues] = useState({customerName: "", loavesType: "", breadType: ""}); |
| 8 | + |
| 9 | + const [customerList, setCustomerList] = useState([]); |
| 10 | + const [loavesList, setLoavesList] = useState([]); |
| 11 | + const [breadsList, setBreadsList] = useState([]); |
| 12 | + |
| 13 | + const [pans, setPans] = useState(0); |
| 14 | + const [rounds, setRounds] = useState(0); |
| 15 | + |
| 16 | + const [dailyBreadTypes, setdailyBreadTypes] = useState({ |
| 17 | + sourdough: true, |
| 18 | + wholeGrain: true, |
| 19 | + banana: true, |
| 20 | + }); |
| 21 | + const [optimizationReportError, setOptimizationReportError] = useState(false) |
| 22 | + |
| 23 | + |
| 24 | + const handleCheckboxChange = (_event) => { |
| 25 | + setdailyBreadTypes({ ...dailyBreadTypes, [_event.target.name]: _event.target.checked }) |
| 26 | + } |
| 27 | + |
| 28 | + const handleSubmit = (_event) => { |
| 29 | + const {customerName:names, loavesType:loaves, breadType:breads} = formValues; |
| 30 | + setCustomerList(names.split(", ")) |
| 31 | + setLoavesList(() => { |
| 32 | + loaves.split(",").forEach(loaf => { |
| 33 | + if (loaf.replace(" ", "").includes("pan")) { |
| 34 | + setPans(p => p + 1) |
| 35 | + loaves.split(","); |
| 36 | + } else if ( loaf.replace(" ", "").includes("round") ) { |
| 37 | + setRounds(r=> r + 1) |
| 38 | + } |
| 39 | + }) |
| 40 | + return loaves.split(","); |
| 41 | + }) |
| 42 | + setBreadsList(() => { |
| 43 | + breads.split(", ").forEach((bread) => { |
| 44 | + if (bread === "whole grain" && !dailyBreadTypes.wholeGrain) { |
| 45 | + setOptimizationReportError(true) |
| 46 | + } |
| 47 | + else if (bread === "sourdough" && !dailyBreadTypes.sourdough) { |
| 48 | + setOptimizationReportError(true) |
| 49 | + } |
| 50 | + else if (bread === "banana" && !dailyBreadTypes.banana) { |
| 51 | + setOptimizationReportError(true); |
| 52 | + } |
| 53 | + }) |
| 54 | + return breads.split(",") |
| 55 | + }) |
| 56 | + } |
| 57 | + |
| 58 | + const handleFormInputChange = (e) => { |
| 59 | + const { name, value } = e.target; |
| 60 | + setFormValues({ |
| 61 | + ...formValues, |
| 62 | + [name]: value, |
| 63 | + }) |
| 64 | + } |
| 65 | + |
| 66 | + const clearReport = () => { |
| 67 | + setPans(0) |
| 68 | + setRounds(0) |
| 69 | + setOptimizationReportError(false) |
| 70 | + } |
| 71 | + |
| 72 | + |
10 | 73 | return (
|
11 |
| - <Container maxWidth="sm"> |
12 |
| - <Box sx={{ my: 4 }}> |
13 |
| - <Typography variant="h4" component="h1" gutterBottom> |
14 |
| - Next.js v5-alpha example |
15 |
| - </Typography> |
16 |
| - <Link href="/about" color="secondary"> |
17 |
| - Go to the about page |
18 |
| - </Link> |
19 |
| - <ProTip /> |
20 |
| - <Copyright /> |
21 |
| - </Box> |
| 74 | + <Container> |
| 75 | + <Grid style={{height: "100vh"}} container direction="column" alignItems="center" justifyContent="center" wrap="nowrap"> |
| 76 | + <Grid item style={{width: "50%"}} sx={{my: 2}}> |
| 77 | + { |
| 78 | + optimizationReportError |
| 79 | + ? <h4 style={{color: "tomato"}}>Call customers to sort out order error as 1 or more of the requested breads are not being served today.</h4> |
| 80 | + : |
| 81 | + <ul style={{flex: "0 0 1fr", margin: "0", padding: "0"}}> |
| 82 | + <h4>Report</h4> |
| 83 | + <li>Make <strong>{rounds}</strong> rounds for today</li> |
| 84 | + <li>Make <strong>{pans}</strong> pans for today</li> |
| 85 | + </ul> |
| 86 | + } |
| 87 | + </Grid> |
| 88 | + <Grid item style={{width: "50%"}} sx={{my: 2}}> |
| 89 | + <FormControl component="fieldset"> |
| 90 | + <FormLabel component="legend">Select Daily Breads</FormLabel> |
| 91 | + <FormGroup> |
| 92 | + <FormControlLabel |
| 93 | + control={<Checkbox checked={dailyBreadTypes.sourdough} onChange={handleCheckboxChange} name="sourdough" />} |
| 94 | + label="Sourdough Bread" |
| 95 | + /> |
| 96 | + <FormControlLabel |
| 97 | + control={<Checkbox checked={dailyBreadTypes.wholeGrain} onChange={handleCheckboxChange} name="wholeGrain" />} |
| 98 | + label="Whole Grain Bread" |
| 99 | + /> |
| 100 | + <FormControlLabel |
| 101 | + control={<Checkbox checked={dailyBreadTypes.banana} onChange={handleCheckboxChange} name="banana" />} |
| 102 | + label="Banana Bread" |
| 103 | + /> |
| 104 | + </FormGroup> |
| 105 | + <FormHelperText>Select the breads you intend on making for today's operations.</FormHelperText> |
| 106 | + </FormControl> |
| 107 | + </Grid> |
| 108 | + <Grid style={{width: '50%'}} sx={{my: 2}} item> |
| 109 | + <Typography variant="h3">Customer Information</Typography> |
| 110 | + <FormControl> |
| 111 | + <Grid style={{display: "flex", flexWrap: "wrap", width: 'contain-content'}} sx={{ my: 1}} item> |
| 112 | + <TextField style={{flex: "0 0 100%"}} sx={{my: 1}} id="customer-name" name="customerName" label="Customer Names" type="text" value={formValues.customerName} onChange={handleFormInputChange} /> |
| 113 | + <TextField style={{flex: "0 0 100%"}} sx={{my: 1}} id="customer-loaves" name="loavesType" label="pan or round?" type="text" value={formValues.loavesType} onChange={handleFormInputChange} /> |
| 114 | + <TextField style={{flex: "0 0 100%"}} sx={{my: 1}} id="customer-bread" name="breadType" label="banana, sourdough, or whole grain?" type="text" value={formValues.breadType} onChange={handleFormInputChange} /> |
| 115 | + <FormHelperText> |
| 116 | + Valid Values include: <strong>sourdough</strong>, <strong>whole grain</strong>, and <strong>banana</strong> for types of loaves |
| 117 | + </FormHelperText> |
| 118 | + </Grid> |
| 119 | + <FormHelperText> |
| 120 | + Enter data as a comma separated list |
| 121 | + </FormHelperText> |
| 122 | + </FormControl> |
| 123 | + </Grid> |
| 124 | + <Button onClick={handleSubmit} style={{width: "50%", height: '50px'}} sx={{my: 4}} variant="contained" color="primary" type="submit"> |
| 125 | + Add Orders |
| 126 | + </Button> |
| 127 | + <Button onClick={clearReport} style={{width: "50%", height: '50px'}} sx={{my: 1}} variant="contained" color="secondary" type="submit"> |
| 128 | + Clear Orders |
| 129 | + </Button> |
| 130 | + </Grid> |
22 | 131 | </Container>
|
23 | 132 | );
|
24 | 133 | }
|
0 commit comments