From 5cb27cb5c752f702370c82cf487d689aeca004f8 Mon Sep 17 00:00:00 2001 From: Tom Chapman Date: Tue, 17 Oct 2023 10:08:30 -0700 Subject: [PATCH 1/4] changed project form to have different background on location fields --- .../src/components/project/ProjectForm.tsx | 495 +++++++++--------- .../src/components/project/ProjectList.tsx | 49 +- 2 files changed, 299 insertions(+), 245 deletions(-) diff --git a/epictrack-web/src/components/project/ProjectForm.tsx b/epictrack-web/src/components/project/ProjectForm.tsx index 76dda729a..2a11e34ba 100644 --- a/epictrack-web/src/components/project/ProjectForm.tsx +++ b/epictrack-web/src/components/project/ProjectForm.tsx @@ -16,6 +16,7 @@ import { MasterContext } from "../shared/MasterContext"; import projectService from "../../services/projectService/projectService"; import LockClosed from "../../assets/images/lock-closed.svg"; import ControlledSwitch from "../shared/controlledInputComponents/ControlledSwitch"; +import { Palette } from "../../styles/theme"; const schema = yup.object().shape({ name: yup @@ -64,10 +65,6 @@ export default function ProjectForm({ ...props }) { const [disabled, setDisabled] = React.useState(); const ctx = React.useContext(MasterContext); - React.useEffect(() => { - ctx.setFormId("project-form"); - }, []); - React.useEffect(() => { setDisabled(props.projectId ? true : false); ctx.setId(props.projectId); @@ -92,12 +89,6 @@ export default function ProjectForm({ ...props }) { reset(ctx.item); }, [ctx.item]); - React.useEffect(() => { - const name = (ctx?.item as Project)?.name; - setDisabled(ctx?.item ? true : false); - ctx.setTitle(name || "Project"); - }, [ctx.title, ctx.item]); - const setRegions = (regions: Region[]) => { const envRegions = regions.filter((p) => p.entity === "ENV"); const nrsRegions = regions.filter((p) => p.entity === "FLNR"); @@ -151,6 +142,7 @@ export default function ProjectForm({ ...props }) { ctx.onSave(data, () => { reset(); }); + props.onSave(); }; return ( <> @@ -160,238 +152,273 @@ export default function ProjectForm({ ...props }) { id="project-form" container spacing={2} + sx={{ + margin: 0, + width: "100%", + }} onSubmit={handleSubmit(onSubmitHandler)} > - - - Name - - - - - - - - - Proponent - - - - - o?.id?.toString()} - getOptionLabel={(o: Proponent) => o.name} - {...register("proponent_id")} - > - - - Type - o?.id?.toString()} - getOptionLabel={(o: Type) => o.name} - {...register("type_id")} - > - - - Subtypes - o?.id?.toString()} - getOptionLabel={(o: SubType) => o.name} - {...register("sub_type_id")} - > - - - Project Description - - - - - Location Description - - - - Latitude - - - - Longitude - - - - ENV Region - o?.id?.toString()} - getOptionLabel={(o: Region) => o?.name} - {...register("region_id_env")} - > - - - NRS Region - o?.id?.toString()} - getOptionLabel={(o: Region) => o?.name} - {...register("region_id_flnro")} - > - - - Capital Investment - - - - EPIC GUID - - - - Est. FTE Positions in Construction - - - - Est. FTE Positions in Operation - - - - Certificate Number - - - - Abbreviation - + + + + Name + + + + + + + + + Proponent + + + + + o?.id?.toString()} + getOptionLabel={(o: Proponent) => o.name} + {...register("proponent_id")} + > + + + Type + o?.id?.toString()} + getOptionLabel={(o: Type) => o.name} + {...register("type_id")} + > + + + Subtypes + o?.id?.toString()} + getOptionLabel={(o: SubType) => o.name} + {...register("sub_type_id")} + > + + + Project Description + + - - Active + + Location Description + + + + Latitude + + + + Longitude + + + + ENV Region + o?.id?.toString()} + getOptionLabel={(o: Region) => o?.name} + {...register("region_id_env")} + > + + + NRS Region + o?.id?.toString()} + getOptionLabel={(o: Region) => o?.name} + {...register("region_id_flnro")} + > + - - - Closed + + + Capital Investment + + + + EPIC GUID + + + + Est. FTE Positions in Construction + + + + Est. FTE Positions in Operation + + + + Certificate Number + + + + Abbreviation + + + + + Active + + + + Closed + diff --git a/epictrack-web/src/components/project/ProjectList.tsx b/epictrack-web/src/components/project/ProjectList.tsx index bba8ff08e..dd1209e66 100644 --- a/epictrack-web/src/components/project/ProjectList.tsx +++ b/epictrack-web/src/components/project/ProjectList.tsx @@ -1,7 +1,7 @@ import React from "react"; import { MRT_ColumnDef } from "material-react-table"; import { Edit as EditIcon, Delete as DeleteIcon } from "@mui/icons-material"; -import { Box, Button, Chip, Grid, IconButton } from "@mui/material"; +import { Box, Button, Grid, IconButton } from "@mui/material"; import ProjectForm from "./ProjectForm"; import { Project } from "../../models/project"; import MasterTrackTable from "../shared/MasterTrackTable"; @@ -9,31 +9,25 @@ import { ETGridTitle, ETPageContainer } from "../shared"; import { MasterContext } from "../shared/MasterContext"; import projectService from "../../services/projectService/projectService"; import { ActiveChip, InactiveChip } from "../shared/chip/ETChip"; +import TrackDialog from "../shared/TrackDialog"; const ProjectList = () => { const [envRegions, setEnvRegions] = React.useState([]); const [subTypes, setSubTypes] = React.useState([]); const [types, setTypes] = React.useState([]); const [projectId, setProjectId] = React.useState(); + const [showProjectForm, setShowProjectForm] = React.useState(false); const ctx = React.useContext(MasterContext); - React.useEffect(() => { - ctx.setForm(); - }, [projectId]); - const onEdit = (id: number) => { setProjectId(id); - ctx.setShowModalForm(true); + setShowProjectForm(true); }; React.useEffect(() => { ctx.setService(projectService); }, []); - React.useEffect(() => { - ctx.setTitle("Project"); - }, [ctx.title]); - const projects = React.useMemo(() => ctx.data as Project[], [ctx.data]); React.useEffect(() => { @@ -51,6 +45,17 @@ const ProjectList = () => { setEnvRegions(envRegions); }, [projects]); + const onDialogClose = React.useCallback(() => { + setShowProjectForm(false); + setProjectId(undefined); + ctx.setItem(undefined); + ctx.setId(undefined); + }, [ctx.id]); + + const onCancelHandler = () => { + setShowProjectForm(false); + }; + const handleDelete = (id: string) => { ctx.setShowDeleteDialog(true); ctx.setId(id); @@ -145,7 +150,8 @@ const ProjectList = () => { >