From 52ee059f1b701b75fde91f6212354462e25ff89a Mon Sep 17 00:00:00 2001 From: Wayne Date: Thu, 7 Mar 2024 22:17:22 +0900 Subject: [PATCH] Small fixes --- .../CreateProject/CreateProject.tsx | 59 +++++++++--- .../CreateProject/ProjectClientDetails.tsx | 16 +++- .../CreateProject/ResourceCapacity.tsx | 90 +++++++++---------- .../CreateProject/ResourceMilestone.tsx | 14 +-- .../CreateProject/StaffAllocation.tsx | 14 ++- src/components/CreateProject/TaskSetup.tsx | 5 +- .../ProjectSearch/ProjectSearch.tsx | 22 ++++- .../TaskTemplateSearch/TaskTemplateSearch.tsx | 4 +- src/theme/devias-material-kit/components.ts | 1 + 9 files changed, 143 insertions(+), 82 deletions(-) diff --git a/src/components/CreateProject/CreateProject.tsx b/src/components/CreateProject/CreateProject.tsx index 326ea02..39adc96 100644 --- a/src/components/CreateProject/CreateProject.tsx +++ b/src/components/CreateProject/CreateProject.tsx @@ -14,13 +14,32 @@ import TaskSetup from "./TaskSetup"; import StaffAllocation from "./StaffAllocation"; import ResourceMilestone from "./ResourceMilestone"; import { Task } from "@/app/api/tasks"; -import { FormProvider, SubmitHandler, useForm } from "react-hook-form"; +import { + FieldErrors, + FormProvider, + SubmitErrorHandler, + SubmitHandler, + useForm, +} from "react-hook-form"; import { CreateProjectInputs } from "@/app/api/projects/actions"; +import { Error } from "@mui/icons-material"; export interface Props { allTasks: Task[]; } +const hasErrorsInTab = ( + tabIndex: number, + errors: FieldErrors, +) => { + switch (tabIndex) { + case 0: + return errors.projectName; + default: + false; + } +}; + const CreateProject: React.FC = ({ allTasks }) => { const [tabIndex, setTabIndex] = useState(0); const { t } = useTranslation(); @@ -41,6 +60,16 @@ const CreateProject: React.FC = ({ allTasks }) => { console.log(data); }, []); + const onSubmitError = useCallback>( + (errors) => { + // Set the tab so that the focus will go there + if (errors.projectName) { + setTabIndex(0); + } + }, + [], + ); + const formProps = useForm({ defaultValues: { tasks: {}, @@ -49,23 +78,33 @@ const CreateProject: React.FC = ({ allTasks }) => { }, }); + const errors = formProps.formState.errors; + return ( - - - - + + ) : undefined + } + iconPosition="end" + /> + + + - {tabIndex === 0 && } - {tabIndex === 1 && } - {tabIndex === 2 && } - {tabIndex === 3 && } + {} + {} + {} + {}