diff --git a/src/app/(main)/projects/create/sub/not-found.tsx b/src/app/(main)/projects/create/sub/not-found.tsx
index 1cc4df3..9b28f5d 100644
--- a/src/app/(main)/projects/create/sub/not-found.tsx
+++ b/src/app/(main)/projects/create/sub/not-found.tsx
@@ -8,7 +8,7 @@ export default async function NotFound() {
return (
{t("Not Found")}
- {t("The sub project was not found or there was no any main projects!")}
+ {t("There was no any main projects!")}
{t("Return to all projects")}
diff --git a/src/app/(main)/projects/create/sub/page.tsx b/src/app/(main)/projects/create/sub/page.tsx
index 1a8fab7..3f474de 100644
--- a/src/app/(main)/projects/create/sub/page.tsx
+++ b/src/app/(main)/projects/create/sub/page.tsx
@@ -21,7 +21,7 @@ import { Metadata } from "next";
import { notFound } from "next/navigation";
export const metadata: Metadata = {
- title: "Create Project",
+ title: "Create Sub Project",
};
const Projects: React.FC = async () => {
diff --git a/src/app/(main)/projects/edit/sub/not-found.tsx b/src/app/(main)/projects/edit/sub/not-found.tsx
new file mode 100644
index 0000000..234e436
--- /dev/null
+++ b/src/app/(main)/projects/edit/sub/not-found.tsx
@@ -0,0 +1,17 @@
+import { getServerI18n } from "@/i18n";
+import { Stack, Typography, Link } from "@mui/material";
+import NextLink from "next/link";
+
+export default async function NotFound() {
+ const { t } = await getServerI18n("projects", "common");
+
+ return (
+
+ {t("Not Found")}
+ {t("The sub project was not found!")}
+
+ {t("Return to all projects")}
+
+
+ );
+}
diff --git a/src/app/(main)/projects/edit/sub/page.tsx b/src/app/(main)/projects/edit/sub/page.tsx
new file mode 100644
index 0000000..eb4f5c6
--- /dev/null
+++ b/src/app/(main)/projects/edit/sub/page.tsx
@@ -0,0 +1,76 @@
+import { fetchAllCustomers, fetchAllSubsidiaries } from "@/app/api/customer";
+import { fetchGrades } from "@/app/api/grades";
+import {
+ fetchMainProjects,
+ fetchProjectBuildingTypes,
+ fetchProjectCategories,
+ fetchProjectContractTypes,
+ fetchProjectDetails,
+ fetchProjectFundingTypes,
+ fetchProjectLocationTypes,
+ fetchProjectServiceTypes,
+ fetchProjectWorkNatures,
+} from "@/app/api/projects";
+import { preloadStaff, preloadTeamLeads } from "@/app/api/staff";
+import { fetchAllTasks, fetchTaskTemplates } from "@/app/api/tasks";
+import CreateProject from "@/components/CreateProject";
+import { I18nProvider, getServerI18n } from "@/i18n";
+import Typography from "@mui/material/Typography";
+import { isArray } from "lodash";
+import { Metadata } from "next";
+import { notFound } from "next/navigation";
+
+interface Props {
+ searchParams: { [key: string]: string | string[] | undefined };
+}
+
+export const metadata: Metadata = {
+ title: "Edit Sub Project",
+};
+
+const Projects: React.FC = async ({ searchParams }) => {
+ const { t } = await getServerI18n("projects");
+ const projectId = searchParams["id"];
+
+ if (!projectId || isArray(projectId)) {
+ notFound();
+ }
+
+ // Preload necessary dependencies
+ fetchAllTasks();
+ fetchTaskTemplates();
+ fetchProjectCategories();
+ fetchProjectContractTypes();
+ fetchProjectFundingTypes();
+ fetchProjectLocationTypes();
+ fetchProjectServiceTypes();
+ fetchProjectBuildingTypes();
+ fetchProjectWorkNatures();
+ fetchAllCustomers();
+ fetchAllSubsidiaries();
+ fetchGrades();
+ preloadTeamLeads();
+ preloadStaff();
+
+ try {
+ await fetchProjectDetails(projectId);
+ const data = await fetchMainProjects();
+
+ if (!Boolean(data) || data.length === 0) {
+ notFound();
+ }
+ } catch (e) {
+ notFound();
+ }
+
+ return (
+ <>
+ {t("Edit Sub Project")}
+
+
+
+ >
+ );
+};
+
+export default Projects;
diff --git a/src/app/api/projects/actions.ts b/src/app/api/projects/actions.ts
index 97cb34e..31ab2c9 100644
--- a/src/app/api/projects/actions.ts
+++ b/src/app/api/projects/actions.ts
@@ -36,8 +36,8 @@ export interface CreateProjectInputs {
// Client details
clientId: Customer["id"];
clientContactId?: number;
- clientSubsidiaryId?: number;
- subsidiaryContactId: number;
+ clientSubsidiaryId?: number | null;
+ subsidiaryContactId?: number;
isSubsidiaryContact?: boolean;
// Allocation
diff --git a/src/app/api/projects/index.ts b/src/app/api/projects/index.ts
index d25ba16..6833571 100644
--- a/src/app/api/projects/index.ts
+++ b/src/app/api/projects/index.ts
@@ -13,6 +13,7 @@ export interface ProjectResult {
team: string;
client: string;
status: string;
+ mainProject: string;
}
export interface MainProject {
diff --git a/src/components/ControlledAutoComplete/ControlledAutoComplete.tsx b/src/components/ControlledAutoComplete/ControlledAutoComplete.tsx
index e37f348..36e7542 100644
--- a/src/components/ControlledAutoComplete/ControlledAutoComplete.tsx
+++ b/src/components/ControlledAutoComplete/ControlledAutoComplete.tsx
@@ -1,6 +1,6 @@
"use client"
-import { Autocomplete, MenuItem, TextField, Checkbox } from "@mui/material";
+import { Autocomplete, MenuItem, TextField, Checkbox, Chip } from "@mui/material";
import { Controller, FieldValues, Path, Control, RegisterOptions } from "react-hook-form";
import { useTranslation } from "react-i18next";
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
@@ -18,6 +18,7 @@ interface Props
+ disabled?: boolean,
}
function ControlledAutoComplete<
@@ -27,11 +28,10 @@ function ControlledAutoComplete<
props: Props
) {
const { t } = useTranslation()
- const { control, options, name, label, noOptionsText, isMultiple, rules } = props;
+ const { control, options, name, label, noOptionsText, isMultiple, rules, disabled } = props;
// set default value if value is null
if (!Boolean(isMultiple) && !Boolean(control._formValues[name])) {
- console.log(name, control._formValues[name])
control._formValues[name] = options[0]?.id ?? undefined
} else if (Boolean(isMultiple) && !Boolean(control._formValues[name])) {
control._formValues[name] = []
@@ -42,7 +42,6 @@ function ControlledAutoComplete<
name={name}
control={control}
rules={rules}
-
render={({ field, fieldState, formState }) => {
return (
@@ -51,7 +50,8 @@ function ControlledAutoComplete<
multiple
disableClearable
disableCloseOnSelect
- disablePortal
+ // disablePortal
+ disabled={disabled}
noOptionsText={noOptionsText ?? t("No Options")}
value={options.filter(option => {
return field.value?.includes(option.id)
@@ -61,7 +61,7 @@ function ControlledAutoComplete<
isOptionEqualToValue={(option, value) => option.id === value.id}
renderOption={(params, option, { selected }) => {
return (
-
+
);
}}
+ // renderTags={(tagValue, getTagProps) => {
+ // return tagValue.map((option, index) => (
+ //
+ // ))
+ // }}
onChange={(event, value) => {
field.onChange(value?.map(v => v.id))
}}
@@ -80,7 +85,8 @@ function ControlledAutoComplete<
:
option.id === field.value) ?? options[0]}
options={options}
@@ -88,13 +94,18 @@ function ControlledAutoComplete<
isOptionEqualToValue={(option, value) => option?.id === value?.id}
renderOption={(params, option) => {
return (
-
-
+ {/*
} onClick={reset}>
{t("Reset")}
-
+ */}
{/* MUI X-Grid will throw an error if it is rendered without any dimensions; so not rendering when not active */}
diff --git a/src/components/CreateProject/TaskSetup.tsx b/src/components/CreateProject/TaskSetup.tsx
index fe02f37..759b05f 100644
--- a/src/components/CreateProject/TaskSetup.tsx
+++ b/src/components/CreateProject/TaskSetup.tsx
@@ -135,7 +135,7 @@ const TaskSetup: React.FC = ({
taskTemplate.id === selectedTaskTemplateId)}
options={[{id: "All", name: t("All tasks")}, ...taskTemplates.map(taskTemplate => ({id: taskTemplate.id, name: taskTemplate.name}))]}
@@ -207,11 +207,11 @@ const TaskSetup: React.FC = ({
allItemsLabel={t("Task Pool")}
selectedItemsLabel={t("Project Task List")}
/>
-
+ {/*
} onClick={onReset}>
{t("Reset")}
-
+ */}
);
diff --git a/src/components/ProjectSearch/ProjectSearch.tsx b/src/components/ProjectSearch/ProjectSearch.tsx
index 79ee51b..bbb1d67 100644
--- a/src/components/ProjectSearch/ProjectSearch.tsx
+++ b/src/components/ProjectSearch/ProjectSearch.tsx
@@ -20,7 +20,6 @@ type SearchParamNames = keyof SearchQuery;
const ProjectSearch: React.FC = ({ projects, projectCategories }) => {
const router = useRouter();
const { t } = useTranslation("projects");
- console.log(projects)
const [filteredProjects, setFilteredProjects] = useState(projects);
@@ -62,7 +61,9 @@ const ProjectSearch: React.FC = ({ projects, projectCategories }) => {
const onProjectClick = useCallback(
(project: ProjectResult) => {
- router.push(`/projects/edit?id=${project.id}`);
+ if (Boolean(project.mainProject)) {
+ router.push(`/projects/edit/sub?id=${project.id}`);
+ } else router.push(`/projects/edit?id=${project.id}`);
},
[router],
);