You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

75 rivejä
2.0 KiB

  1. import { fetchAllCustomers, fetchAllSubsidiaries } from "@/app/api/customer";
  2. import { fetchGrades } from "@/app/api/grades";
  3. import {
  4. fetchProjectBuildingTypes,
  5. fetchProjectCategories,
  6. fetchProjectContractTypes,
  7. fetchProjectDetails,
  8. fetchProjectFundingTypes,
  9. fetchProjectLocationTypes,
  10. fetchProjectServiceTypes,
  11. fetchProjectWorkNatures,
  12. } from "@/app/api/projects";
  13. import { preloadStaff, preloadTeamLeads } from "@/app/api/staff";
  14. import { fetchAllTasks, fetchTaskTemplates } from "@/app/api/tasks";
  15. import { ServerFetchError } from "@/app/utils/fetchUtil";
  16. import CreateProject from "@/components/CreateProject";
  17. import { I18nProvider, getServerI18n } from "@/i18n";
  18. import Typography from "@mui/material/Typography";
  19. import { isArray } from "lodash";
  20. import { Metadata } from "next";
  21. import { notFound } from "next/navigation";
  22. interface Props {
  23. searchParams: { [key: string]: string | string[] | undefined };
  24. }
  25. export const metadata: Metadata = {
  26. title: "Edit Project",
  27. };
  28. const Projects: React.FC<Props> = async ({ searchParams }) => {
  29. const { t } = await getServerI18n("projects");
  30. // Assume projectId is string here
  31. const projectId = searchParams["id"];
  32. if (!projectId || isArray(projectId)) {
  33. notFound();
  34. }
  35. // Preload necessary dependencies
  36. fetchAllTasks();
  37. fetchTaskTemplates();
  38. fetchProjectCategories();
  39. fetchProjectContractTypes();
  40. fetchProjectFundingTypes();
  41. fetchProjectLocationTypes();
  42. fetchProjectServiceTypes();
  43. fetchProjectBuildingTypes();
  44. fetchProjectWorkNatures();
  45. fetchAllCustomers();
  46. fetchAllSubsidiaries();
  47. fetchGrades();
  48. preloadTeamLeads();
  49. preloadStaff();
  50. try {
  51. await fetchProjectDetails(projectId);
  52. } catch (e) {
  53. if (e instanceof ServerFetchError && e.response?.status === 404) {
  54. notFound();
  55. }
  56. }
  57. return (
  58. <>
  59. <Typography variant="h4">{t("Edit Project")}</Typography>
  60. <I18nProvider namespaces={["projects"]}>
  61. <CreateProject isEditMode projectId={projectId} />
  62. </I18nProvider>
  63. </>
  64. );
  65. };
  66. export default Projects;