Files
ScoutingApp2022/webserver/src/Pages/InputPage.jsx
T

260 lines
9.9 KiB
React
Raw Normal View History

2022-01-28 13:40:10 +00:00
import React from "react";
import { useLocalDb } from "../DbContext";
2022-01-29 14:05:28 +00:00
import "./InputPage.css"
2022-01-28 13:40:10 +00:00
// import { Button, Intent, Spinner } from "@blueprintjs/core";
import FormRenderer from "@data-driven-forms/react-form-renderer/form-renderer";
import componentTypes from "@data-driven-forms/react-form-renderer/component-types";
import componentMapper from "@data-driven-forms/blueprint-component-mapper/component-mapper";
import FormTemplate from "@data-driven-forms/blueprint-component-mapper/form-template";
2022-02-02 05:48:35 +00:00
import { Formik, FastField, Form } from "formik";
2022-01-28 13:40:10 +00:00
import InputNumberField from "../components/InputNumberField.jsx";
import {
TextField,
Button,
Grid,
FormRow,
2022-02-02 05:37:10 +00:00
Divider,
2022-01-28 13:40:10 +00:00
Checkbox,
Radio,
FormControlLabel,
FormControl,
FormLabel,
RadioGroup,
IconButton,
InputAdornment,
} from "@material-ui/core";
import { AddCircleOutline, RemoveCircleOutline } from "@material-ui/icons";
const InputPage = () => {
const localdb = useLocalDb();
return (
2022-02-02 05:37:10 +00:00
<div>
2022-01-29 14:05:28 +00:00
<br />
2022-01-28 13:40:10 +00:00
<Formik
initialValues={{
team_number: "",
match_number: "",
team_abilities_well: "",
team_abilities_struggle: "",
team_abilities_cant: "",
fouls: "0",
fouls_tech: "0",
2022-02-02 05:37:10 +00:00
flipped: false,
2022-01-28 13:40:10 +00:00
red_cards: "0",
yellow_cards: "0",
disabled: false,
2022-02-02 05:37:10 +00:00
taxi_auto: false,
2022-01-28 13:40:10 +00:00
upper_hub_auto: "0",
lower_hub_auto: "0",
2022-02-02 05:37:10 +00:00
upper_hub_teleop: "0",
lower_hub_teleop: "0",
2022-01-28 13:40:10 +00:00
climb_level: "",
alliance: "",
2022-02-02 05:37:10 +00:00
defence: "0",
disabled: false
2022-01-28 13:40:10 +00:00
}}
2022-02-02 05:48:35 +00:00
validateOnChange="false"
2022-01-28 13:40:10 +00:00
onSubmit={(values, { setSubmitting, resetForm }) => {
setTimeout(() => {
localdb
.put({
_id: new Date().toISOString(),
...values,
})
.then((result) => {
alert("Input Saved Successfully!");
console.log(result);
2022-01-29 14:05:28 +00:00
console.log(localdb);
2022-01-28 13:40:10 +00:00
})
.catch((err) => {
console.log("Failed To Save Input!");
alert(err);
});
// alert(JSON.stringify(values, null, 2));
2022-01-29 14:05:28 +00:00
// resetForm(); //Hah tobad
2022-01-28 13:40:10 +00:00
setSubmitting(false);
}, 400);
2022-01-29 14:05:28 +00:00
}}>
2022-01-28 13:40:10 +00:00
{({
values,
setValues,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (
2022-01-29 14:05:28 +00:00
<Form >
2022-02-02 05:37:10 +00:00
<Grid container direction="row" justifyContent="center" alignItems="flex-end" spacing={3}>
2022-01-28 13:40:10 +00:00
<Grid item>
2022-02-02 05:48:35 +00:00
<FastField type="input" as={TextField} name="team_number" label="Team #" />
2022-01-28 13:40:10 +00:00
</Grid>
<Grid item>
2022-02-02 05:48:35 +00:00
<FastField type="input" as={TextField} name="match_number" label="Match Number" />
2022-01-28 13:40:10 +00:00
</Grid>
<Grid item>
<FormControl component="fieldset">
<FormLabel component="legend">Alliance</FormLabel>
<RadioGroup aria-label="Alliance" name="alliance" row>
<FormControlLabel
control={
2022-02-02 05:48:35 +00:00
<FastField as={Radio} type="radio" name="alliance" value="red" style={{ fontSize: 50 }} />
2022-01-28 13:40:10 +00:00
}
label="Red"
/>
<FormControlLabel
control={
2022-02-02 05:48:35 +00:00
<FastField as={Radio} type="radio" name="alliance" value="blue" />
2022-01-28 13:40:10 +00:00
}
label="Blue"
/>
</RadioGroup>
</FormControl>
</Grid>
</Grid>
<div />
2022-02-02 05:37:10 +00:00
<Grid container direction="row" justifyContent="center" alignItems="flex-end" spacing={3}>
2022-01-28 13:40:10 +00:00
<Grid item>
2022-02-02 05:37:10 +00:00
<Grid container direction="column" justifyContent="flex-end" alignItems="center" spacing={3}>
2022-01-28 13:40:10 +00:00
<Grid item>
2022-02-02 05:37:10 +00:00
<InputNumberField name="upper_hub_auto" label="Upper Hub Auto" />
2022-01-28 13:40:10 +00:00
</Grid>
<Grid item>
2022-02-02 05:37:10 +00:00
<InputNumberField name="lower_hub_auto" label="Lower Hub Auto" />
2022-01-28 13:40:10 +00:00
</Grid>
</Grid>
</Grid>
<Grid item>
2022-02-02 05:37:10 +00:00
<Grid container direction="column" justifyContent="flex-end" alignItems="center" spacing={3}>
2022-01-28 13:40:10 +00:00
<Grid item>
2022-02-02 05:37:10 +00:00
<InputNumberField name="upper_hub_teleop" label="Upper Hub Teleop" />
2022-01-28 13:40:10 +00:00
</Grid>
<Grid item>
2022-02-02 05:37:10 +00:00
<InputNumberField name="lower_hub_teleop" label="Lower Hub Teleop" />
2022-01-28 13:40:10 +00:00
</Grid>
2022-02-02 05:37:10 +00:00
</Grid>
2022-01-28 13:40:10 +00:00
</Grid>
</Grid>
<div />
2022-02-02 05:37:10 +00:00
<Grid container direction="row" justifyContent="center" alignItems="flex-end" spacing={3}>
2022-01-28 13:40:10 +00:00
<Grid item>
<FormControl component="fieldset">
<FormLabel component="legend">Climbing</FormLabel>
<RadioGroup aria-label="Climbing" name="climb_level" row>
<FormControlLabel
control={
2022-02-02 05:48:35 +00:00
<FastField as={Radio} type="radio" name="climb_level" value="0" />
2022-01-28 13:40:10 +00:00
}
label="None"
/>
<FormControlLabel
control={
2022-02-02 05:48:35 +00:00
<FastField as={Radio} type="radio" name="climb_level" value="1" />
2022-01-28 13:40:10 +00:00
}
label="Low"
/>
<FormControlLabel
control={
2022-02-02 05:48:35 +00:00
<FastField as={Radio} type="radio" name="climb_level" value="2" />
2022-01-28 13:40:10 +00:00
}
label="Mid"
/>
<FormControlLabel
control={
2022-02-02 05:48:35 +00:00
<FastField as={Radio} type="radio" name="climb_level" value="3" />
2022-01-28 13:40:10 +00:00
}
label="High"
/>
<FormControlLabel
control={
2022-02-02 05:48:35 +00:00
<FastField as={Radio} type="radio" name="climb_level" value="4" />
2022-01-28 13:40:10 +00:00
}
label="Traversal"
/>
</RadioGroup>
</FormControl>
</Grid>
</Grid>
<div />
2022-02-02 05:37:10 +00:00
<Grid container direction="row" justifyContent="center" alignItems="flex-end" spacing={3}>
2022-01-28 13:40:10 +00:00
<Grid item>
2022-02-02 05:37:10 +00:00
<Grid container direction="column" justifyContent="flex-end" alignItems="center" spacing={3}>
2022-01-29 14:05:28 +00:00
<Grid item>
2022-02-02 05:37:10 +00:00
<InputNumberField name="fouls" label="Fouls" />
</Grid>
2022-01-29 14:05:28 +00:00
<Grid item>
2022-02-02 05:37:10 +00:00
<InputNumberField name="fouls_tech" label="Tech Fouls" />
</Grid>
2022-01-29 14:05:28 +00:00
</Grid>
2022-01-28 13:40:10 +00:00
</Grid>
<Grid item>
2022-02-02 05:37:10 +00:00
<Grid container direction="column" justifyContent="flex-end" alignItems="center" spacing={3}>
2022-01-29 14:05:28 +00:00
<Grid item>
2022-02-02 05:37:10 +00:00
<InputNumberField name="red_cards" label="Red Cards" />
2022-01-29 14:05:28 +00:00
</Grid>
<Grid item>
2022-02-02 05:37:10 +00:00
<InputNumberField name="yellow_cards" label="Yellow Cards" />
</Grid>
2022-01-28 13:40:10 +00:00
</Grid>
</Grid>
</Grid>
2022-01-29 14:05:28 +00:00
<div />
2022-02-02 05:37:10 +00:00
<Grid container direction="row" justifyContent="center" alignItems="flex-end" spacing={3}>
2022-01-29 14:05:28 +00:00
<Grid item>
<FormControl component="fieldset">
<FormLabel component="legend">Defense</FormLabel>
<RadioGroup aria-label="Defense" name="defence" row>
<FormControlLabel
2022-02-02 05:48:35 +00:00
control={<FastField as={Radio} type="radio" name="defence" value="0" />}
2022-02-02 05:37:10 +00:00
label="None"
2022-01-29 14:05:28 +00:00
/>
2022-02-02 05:37:10 +00:00
{/* <Divider orientation="vertical" flexItem middle /> */}
2022-01-29 14:05:28 +00:00
<FormControlLabel
2022-02-02 05:48:35 +00:00
control={<FastField as={Radio} type="radio" name="defence" value="1" />}
2022-01-29 14:05:28 +00:00
label="Poor"
/>
<FormControlLabel
2022-02-02 05:48:35 +00:00
control={<FastField as={Radio} type="radio" name="defence" value="2" />}
2022-01-29 14:05:28 +00:00
label="Good"
2022-02-02 05:37:10 +00:00
/> <FormControlLabel
2022-02-02 05:48:35 +00:00
control={<FastField as={Radio} type="radio" name="defence" value="3" />}
2022-01-29 14:05:28 +00:00
label="Exceptional"
/>
</RadioGroup>
</FormControl>
</Grid>
2022-02-02 05:37:10 +00:00
<Grid item>
<FormControlLabel
2022-02-02 05:48:35 +00:00
control={<FastField as={Checkbox} type="checkbox" name="disabled" />}
2022-02-02 05:37:10 +00:00
label="Disabled"
/>
</Grid>
2022-01-29 14:05:28 +00:00
</Grid>
2022-01-28 13:40:10 +00:00
<div />
2022-02-02 05:37:10 +00:00
<Grid container direction="row" justifyContent="center" alignItems="flex-end" spacing={3}>
2022-01-28 13:40:10 +00:00
<Grid item>
2022-02-02 05:48:35 +00:00
<FastField type="input" as={TextField} multiline rows={3} name="team_abilities_well" label="What they did Well" />
2022-01-28 13:40:10 +00:00
</Grid>
<Grid item>
2022-02-02 05:48:35 +00:00
<FastField type="input" as={TextField} multiline rows={3} name="team_abilities_struggle" label="What they struggled with" />
2022-01-28 13:40:10 +00:00
</Grid>
<Grid item>
2022-02-02 05:48:35 +00:00
<FastField type="input" as={TextField} multiline rows={3} name="team_abilities_cant" label="What they can't do" />
2022-01-28 13:40:10 +00:00
</Grid>
</Grid>
<div />
2022-02-02 05:37:10 +00:00
<Grid container direction="row" justifyContent="center" alignItems="flex-end" spacing={3}>
2022-01-28 13:40:10 +00:00
<Button type="submit" disabled={isSubmitting}>
2022-02-02 05:37:10 +00:00
Submit
2022-01-28 13:40:10 +00:00
</Button>
</Grid>
</Form>
)}
</Formik>
</div>
);
};
export default InputPage;