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.
 
 

107 lines
2.6 KiB

  1. import { fetchAllTasks, fetchTaskTemplates } from "@/app/api/tasks";
  2. import CreateProject from "./CreateProject";
  3. import {
  4. fetchMainProjects,
  5. fetchProjectBuildingTypes,
  6. fetchProjectCategories,
  7. fetchProjectContractTypes,
  8. fetchProjectDetails,
  9. fetchProjectFundingTypes,
  10. fetchProjectLocationTypes,
  11. fetchProjectServiceTypes,
  12. fetchProjectWorkNatures,
  13. } from "@/app/api/projects";
  14. import { fetchStaff, fetchTeamLeads } from "@/app/api/staff";
  15. import {
  16. fetchAllCustomers,
  17. fetchAllSubsidiaries,
  18. fetchCustomerTypes,
  19. } from "@/app/api/customer";
  20. import { fetchGrades } from "@/app/api/grades";
  21. import { getUserAbilities } from "@/app/utils/commonUtil";
  22. type CreateProjectProps = {
  23. isEditMode: false;
  24. isSubProject?: boolean;
  25. };
  26. interface EditProjectProps {
  27. isEditMode: true;
  28. projectId?: string;
  29. isSubProject?: boolean;
  30. }
  31. type Props = CreateProjectProps | EditProjectProps;
  32. const CreateProjectWrapper: React.FC<Props> = async (props) => {
  33. const [
  34. tasks,
  35. taskTemplates,
  36. projectCategories,
  37. teamLeads,
  38. allCustomers,
  39. allSubsidiaries,
  40. contractTypes,
  41. fundingTypes,
  42. locationTypes,
  43. serviceTypes,
  44. buildingTypes,
  45. workNatures,
  46. allStaffs,
  47. grades,
  48. customerTypes,
  49. abilities,
  50. ] = await Promise.all([
  51. fetchAllTasks(),
  52. fetchTaskTemplates(),
  53. fetchProjectCategories(),
  54. fetchTeamLeads(),
  55. fetchAllCustomers(),
  56. fetchAllSubsidiaries(),
  57. fetchProjectContractTypes(),
  58. fetchProjectFundingTypes(),
  59. fetchProjectLocationTypes(),
  60. fetchProjectServiceTypes(),
  61. fetchProjectBuildingTypes(),
  62. fetchProjectWorkNatures(),
  63. fetchStaff(),
  64. fetchGrades(),
  65. fetchCustomerTypes(),
  66. getUserAbilities(),
  67. ]);
  68. const projectInfo = props.isEditMode
  69. ? await fetchProjectDetails(props.projectId!)
  70. : undefined;
  71. const mainProjects = Boolean(props.isSubProject)
  72. ? await fetchMainProjects()
  73. : undefined;
  74. return (
  75. <CreateProject
  76. isEditMode={props.isEditMode}
  77. isSubProject={Boolean(props.isSubProject)}
  78. defaultInputs={projectInfo}
  79. allTasks={tasks}
  80. projectCategories={projectCategories}
  81. taskTemplates={taskTemplates}
  82. teamLeads={teamLeads}
  83. allSubsidiaries={allSubsidiaries}
  84. allCustomers={allCustomers}
  85. contractTypes={contractTypes}
  86. fundingTypes={fundingTypes}
  87. locationTypes={locationTypes}
  88. serviceTypes={serviceTypes}
  89. buildingTypes={buildingTypes}
  90. workNatures={workNatures}
  91. allStaffs={allStaffs}
  92. grades={grades}
  93. customerTypes={customerTypes}
  94. mainProjects={mainProjects}
  95. abilities={abilities}
  96. />
  97. );
  98. };
  99. export default CreateProjectWrapper;