diff --git a/epictrack-web/src/components/project/ProjectForm.tsx b/epictrack-web/src/components/project/ProjectForm.tsx index b128603ba..1bc5118a3 100644 --- a/epictrack-web/src/components/project/ProjectForm.tsx +++ b/epictrack-web/src/components/project/ProjectForm.tsx @@ -5,7 +5,7 @@ import * as yup from "yup"; import { yupResolver } from "@hookform/resolvers/yup"; import { ETFormLabel } from "../shared/index"; import codeService, { Code } from "../../services/codeService"; -import { Project } from "../../models/project"; +import { Project, defaultProject } from "../../models/project"; import { Proponent } from "../../models/proponent"; import { Region } from "../../models/region"; import { Type } from "../../models/type"; @@ -66,7 +66,6 @@ export default function ProjectForm({ ...props }) { React.useEffect(() => { ctx.setFormId("project-form"); - reset({ is_active: true }); }, []); React.useEffect(() => { @@ -90,7 +89,7 @@ export default function ProjectForm({ ...props }) { const formValues = useWatch({ control }); React.useEffect(() => { - reset(ctx.item); + reset(ctx.item ?? defaultProject); }, [ctx.item]); React.useEffect(() => { diff --git a/epictrack-web/src/components/proponent/ProponentForm.tsx b/epictrack-web/src/components/proponent/ProponentForm.tsx index 61951ba97..735fe9dd9 100644 --- a/epictrack-web/src/components/proponent/ProponentForm.tsx +++ b/epictrack-web/src/components/proponent/ProponentForm.tsx @@ -5,7 +5,7 @@ import * as yup from "yup"; import { yupResolver } from "@hookform/resolvers/yup"; import { ETFormLabel } from "../shared/index"; import { Staff } from "../../models/staff"; -import { Proponent } from "../../models/proponent"; +import { Proponent, defaultProponent } from "../../models/proponent"; import staffService from "../../services/staffService/staffService"; import ControlledSelectV2 from "../shared/controlledInputComponents/ControlledSelectV2"; import { MasterContext } from "../shared/MasterContext"; @@ -40,7 +40,6 @@ export default function ProponentForm({ ...props }) { React.useEffect(() => { ctx.setFormId("proponent-form"); - reset({ is_active: true }); }, []); React.useEffect(() => { const name = (ctx?.item as Proponent)?.name; @@ -65,7 +64,7 @@ export default function ProponentForm({ ...props }) { } = methods; React.useEffect(() => { - reset(ctx.item); + reset(ctx.item ?? defaultProponent); }, [ctx.item]); const getStaffs = async () => { diff --git a/epictrack-web/src/components/shared/MasterContext.tsx b/epictrack-web/src/components/shared/MasterContext.tsx index 1d565c833..6a555ccf6 100644 --- a/epictrack-web/src/components/shared/MasterContext.tsx +++ b/epictrack-web/src/components/shared/MasterContext.tsx @@ -135,6 +135,7 @@ export const MasterProvider = ({ type: "success", }); setItem(undefined); + setId(undefined); setBackdrop(false); callback(); } diff --git a/epictrack-web/src/models/project.ts b/epictrack-web/src/models/project.ts index 81bbbf806..b0ae8f21e 100644 --- a/epictrack-web/src/models/project.ts +++ b/epictrack-web/src/models/project.ts @@ -29,3 +29,7 @@ export interface Project { fte_positions_construction: number; fte_positions_operation: number; } + +export const defaultProject = { + is_active: true, +}; diff --git a/epictrack-web/src/models/proponent.ts b/epictrack-web/src/models/proponent.ts index a1dcafd28..47aac2b02 100644 --- a/epictrack-web/src/models/proponent.ts +++ b/epictrack-web/src/models/proponent.ts @@ -7,3 +7,7 @@ export interface Proponent extends ListType, MasterBase { relationship_holder_id?: number; relationship_holder?: Staff; } + +export const defaultProponent = { + is_active: true, +};