Advertisement
Guest User

Complete file

a guest
Apr 21st, 2022
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useEffect, useState } from "react";
  2. import { useParams } from "react-router-dom";
  3. import Box from "@mui/material/Box";
  4. import Container from "@mui/material/Container";
  5. import TextField from "@mui/material/TextField";
  6. import MenuItem from "@mui/material/MenuItem";
  7. import Paper from "@mui/material/Paper";
  8. import Button from "@mui/material/Button";
  9. import PropTypes from "prop-types";
  10. import Tabs from "@mui/material/Tabs";
  11. import Tab from "@mui/material/Tab";
  12. import Typography from "@mui/material/Typography";
  13. import Sizing from "./Sizing";
  14. import Questions from "./Questions";
  15. import Taxonomy from "./Taxonomy";
  16. import CircularProgress from "@mui/material/CircularProgress";
  17. import Grid from "@mui/material/Grid";
  18. import "../App.css";
  19.  
  20. function TabPanel(props) {
  21.     const { children, value, index, ...other } = props;
  22.     return (
  23.         <div
  24.             role="tabpanel"
  25.             hidden={value !== index}
  26.             id={`simple-tabpanel-${index}`}
  27.             aria-labelledby={`simple-tab-${index}`}
  28.             {...other}
  29.         >
  30.             {value === index && (
  31.                 <Box sx={{ p: 3 }}>
  32.                     <Typography>{children}</Typography>
  33.                 </Box>
  34.             )}
  35.         </div>
  36.     );
  37. }
  38.  
  39. TabPanel.propTypes = {
  40.     children: PropTypes.node,
  41.     index: PropTypes.number.isRequired,
  42.     value: PropTypes.number.isRequired,
  43. };
  44.  
  45. function a11yProps(index) {
  46.     return {
  47.         id: `simple-tab-${index}`,
  48.         "aria-controls": `simple-tabpanel-${index}`,
  49.     };
  50. }
  51.  
  52. function IntakeDetails() {
  53.     const [details, setDetails] = useState("");
  54.     const params = useParams();
  55.     const [busy, setBusy] = useState(false);
  56.     const [value, setValue] = React.useState(0);
  57.  
  58.     const fetchDetails = async () => {
  59.         setBusy(true);
  60.         setDetails(await fetch(`/fiscalyears/FY2023/intakes/${params.id}/details`).then((response) => response.json()));
  61.         setBusy(false);
  62.     };
  63.  
  64.     const handleChange = (event, newValue) => {
  65.         setValue(newValue);
  66.     };
  67.  
  68.     useEffect(() => {
  69.         fetchDetails();
  70.     }, []);
  71.  
  72.     const TextDetails = ({ head, val, index }) => {
  73.         return (
  74.             <TextField
  75.                 value={val || ""}
  76.                 onChange={(e) => {
  77.                     setDetails((prev) => {
  78.                         const update = [...prev.fields];
  79.                         update[index] = {
  80.                             ...update[index],
  81.                             Value: e.target.value,
  82.                         };
  83.                         return { ...prev, fields: update };
  84.                     });
  85.                 }}
  86.                 multiline
  87.                 variant="outlined"
  88.                 margin="normal"
  89.                 label={head}
  90.                 style={{
  91.                     margin: "10px",
  92.                     minHeight: "10px",
  93.                     minWidth: "200px",
  94.                 }}
  95.             />
  96.         );
  97.     };
  98.  
  99.     const SelectDetails = ({ head, val, choices, index }) => {
  100.         return (
  101.             <TextField
  102.                 value={val || ""}
  103.                 onChange={(e) => {
  104.                     setDetails((prev) => {
  105.                         const update = [...prev.fields];
  106.                         update[index] = {
  107.                             ...update[index],
  108.                             Value: e.target.value,
  109.                         };
  110.                         return { ...prev, fields: update };
  111.                     });
  112.                 }}
  113.                 variant="outlined"
  114.                 margin="normal"
  115.                 select
  116.                 label={head}
  117.                 style={{
  118.                     margin: "10px",
  119.                     minHeight: "10px",
  120.                     minWidth: "200px",
  121.                 }}
  122.             >
  123.                 {choices.map((choice) => (
  124.                     <MenuItem key={choice} value={choice}>
  125.                         {choice}
  126.                     </MenuItem>
  127.                 ))}
  128.             </TextField>
  129.         );
  130.     };
  131.  
  132.     const detailsComps = details["fields"]?.map((row, i) => {
  133.         return row["FieldType"] === "Text" ||
  134.             row["FieldType"] === "Decimal" ||
  135.             row["FieldType"] === "Number" ||
  136.             row["FieldType"] === "Date" ? (
  137.             <TextDetails head={row?.FieldName} val={row?.Value} index={i} />
  138.         ) : (
  139.             <SelectDetails head={row.FieldName} val={row?.Value} choices={row?.Choices} index={i} />
  140.         );
  141.     });
  142.  
  143.     if (busy) {
  144.         return (
  145.             <Grid container justifyContent="center">
  146.                 <CircularProgress
  147.                     size={68}
  148.                     sx={{
  149.                         color: "blue",
  150.                     }}
  151.                 />
  152.             </Grid>
  153.         );
  154.     }
  155.  
  156.     return (
  157.         <Container maxWidth="xl">
  158.             <Box>
  159.                 <h3> Intake Details </h3>
  160.                 <label> {details["ModifiedBy"] || ""} </label>
  161.                 <label> {details["UpdateDate"] || ""} </label>
  162.             </Box>
  163.             <Box className="details-header">
  164.                 <TextField
  165.                     className="text-field"
  166.                     value={details["IntakeID"] || ""}
  167.                     variant="outlined"
  168.                     margin="normal"
  169.                     label="IntakeID"
  170.                     style={{
  171.                         margin: "10px",
  172.                     }}
  173.                 />
  174.                 <TextField
  175.                     className="text-field"
  176.                     value={details?.Title || ""}
  177.                     onChange={(e) => {
  178.                         setDetails((prev) => {
  179.                             return { ...prev, Title: e.target.value };
  180.                         });
  181.                     }}
  182.                     variant="outlined"
  183.                     margin="normal"
  184.                     label="Title"
  185.                     style={{
  186.                         margin: "10px",
  187.                         minWidth: "750px",
  188.                     }}
  189.                 />
  190.                 <TextField
  191.                     className="text-field"
  192.                     value={details["Status"] || ""}
  193.                     variant="outlined"
  194.                     margin="normal"
  195.                     label="Status"
  196.                     style={{
  197.                         margin: "10px",
  198.                     }}
  199.                 />
  200.             </Box>
  201.             <Paper>
  202.                 <Box sx={{ width: "100%" }}>
  203.                     <Box sx={{ borderBottom: 1, borderColor: "divider" }}>
  204.                         <Tabs value={value} onChange={handleChange} aria-label="basic tabs example">
  205.                             <Tab label="Intake Details" {...a11yProps(0)} />
  206.                             <Tab label="Sizing" {...a11yProps(1)} />
  207.                             <Tab label="Questions" {...a11yProps(2)} />
  208.                         </Tabs>
  209.                     </Box>
  210.                     <TabPanel value={value} index={0}>
  211.                         <Box>
  212.                             {/* {details["fields"]?.map((row, index) => (
  213.                                 <TextField
  214.                                     className="text-field"
  215.                                     value={row?.Value || ""}
  216.                                     onChange={(e) => {
  217.                                         setDetails((prev) => {
  218.                                             const update = [...prev.fields];
  219.                                             update[index] = {
  220.                                                 ...update[index],
  221.                                                 Value: e.target.value,
  222.                                             };
  223.                                             return { ...prev, fields: update };
  224.                                         });
  225.                                     }}
  226.                                     multiline
  227.                                     variant="outlined"
  228.                                     margin="normal"
  229.                                     label={row["FieldName"]}
  230.                                 />
  231.                             ))} */}
  232.                             {detailsComps}
  233.                         </Box>
  234.                         <Button
  235.                             variant="contained"
  236.                             style={{
  237.                                 background: "red",
  238.                                 marginTop: "10px",
  239.                                 minWidth: "400px",
  240.                             }}
  241.                         >
  242.                             Save
  243.                         </Button>
  244.                     </TabPanel>
  245.                     <TabPanel value={value} index={1}>
  246.                         <Sizing />
  247.                         <Button
  248.                             variant="contained"
  249.                             style={{
  250.                                 background: "red",
  251.                                 marginTop: "10px",
  252.                                 minWidth: "400px",
  253.                             }}
  254.                         >
  255.                             Save
  256.                         </Button>
  257.                     </TabPanel>
  258.                     <TabPanel value={value} index={2}>
  259.                         <Questions />
  260.                         <Button
  261.                             variant="contained"
  262.                             style={{
  263.                                 background: "red",
  264.                                 marginTop: "10px",
  265.                                 minWidth: "400px",
  266.                             }}
  267.                         >
  268.                             Save
  269.                         </Button>
  270.                     </TabPanel>
  271.                 </Box>
  272.             </Paper>
  273.         </Container>
  274.     );
  275. }
  276.  
  277. export default IntakeDetails;
  278.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement