您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

199 行
4.3 KiB

  1. import { serverFetchJson } from "@/app/utils/fetchUtil";
  2. import { BASE_API_URL } from "@/config/api";
  3. import { cache } from "react";
  4. import "server-only";
  5. import { Task, TaskGroup } from "../tasks";
  6. import { CreateProjectInputs } from "./actions";
  7. export interface ProjectResult {
  8. id: number;
  9. code: string;
  10. name: string;
  11. category: string;
  12. team: string;
  13. client: string;
  14. status: string;
  15. mainProject: string;
  16. }
  17. export interface MainProject {
  18. projectId: number;
  19. projectCode: string;
  20. projectName: string;
  21. projectCategoryId: number;
  22. projectDescription: string;
  23. projectLeadId: number;
  24. projectStatus: string;
  25. isClpProject: boolean;
  26. serviceTypeId: number;
  27. fundingTypeId: number;
  28. contractTypeId: number;
  29. locationId: number;
  30. buildingTypeIds: number[];
  31. workNatureIds: number[];
  32. clientId: number;
  33. clientContactId: number;
  34. clientSubsidiaryId: number;
  35. expectedProjectFee: number;
  36. }
  37. export interface ProjectCategory {
  38. id: number;
  39. name: string;
  40. }
  41. export interface ServiceType {
  42. id: number;
  43. name: string;
  44. }
  45. export interface FundingType {
  46. id: number;
  47. name: string;
  48. }
  49. export interface ContractType {
  50. id: number;
  51. name: string;
  52. }
  53. export interface LocationType {
  54. id: number;
  55. name: string;
  56. }
  57. export interface BuildingType {
  58. id: number;
  59. name: string;
  60. }
  61. export interface WorkNature {
  62. id: number;
  63. name: string;
  64. }
  65. export interface ProjectWithTasks {
  66. id: number;
  67. code: string;
  68. status?: string;
  69. name: string;
  70. tasks: Task[];
  71. milestones: {
  72. [taskGroupId: TaskGroup["id"]]: {
  73. startDate?: string;
  74. endDate?: string;
  75. };
  76. };
  77. }
  78. export interface AssignedProject extends ProjectWithTasks {
  79. // Manhour info
  80. hoursSpent: number;
  81. hoursSpentOther: number;
  82. hoursAllocated: number;
  83. }
  84. export const preloadProjects = () => {
  85. fetchProjectCategories();
  86. fetchProjects();
  87. };
  88. export const fetchProjects = cache(async () => {
  89. return serverFetchJson<ProjectResult[]>(`${BASE_API_URL}/projects`, {
  90. next: { tags: ["projects"] },
  91. });
  92. });
  93. export const fetchMainProjects = cache(async () => {
  94. return serverFetchJson<MainProject[]>(`${BASE_API_URL}/projects/main`, {
  95. next: { tags: ["projects"] },
  96. });
  97. });
  98. export const fetchProjectCategories = cache(async () => {
  99. return serverFetchJson<ProjectCategory[]>(
  100. `${BASE_API_URL}/projects/categories`,
  101. {
  102. next: { tags: ["projectCategories"] },
  103. },
  104. );
  105. });
  106. export const fetchProjectServiceTypes = cache(async () => {
  107. return serverFetchJson<ServiceType[]>(
  108. `${BASE_API_URL}/projects/serviceTypes`,
  109. {
  110. next: { tags: ["projectServiceTypes"] },
  111. },
  112. );
  113. });
  114. export const fetchProjectFundingTypes = cache(async () => {
  115. return serverFetchJson<FundingType[]>(
  116. `${BASE_API_URL}/projects/fundingTypes`,
  117. {
  118. next: { tags: ["projectFundingTypes"] },
  119. },
  120. );
  121. });
  122. export const fetchProjectContractTypes = cache(async () => {
  123. return serverFetchJson<ContractType[]>(
  124. `${BASE_API_URL}/projects/contractTypes`,
  125. {
  126. next: { tags: ["projectContractTypes"] },
  127. },
  128. );
  129. });
  130. export const fetchProjectLocationTypes = cache(async () => {
  131. return serverFetchJson<LocationType[]>(
  132. `${BASE_API_URL}/projects/locationTypes`,
  133. {
  134. next: { tags: ["projectLocationTypes"] },
  135. },
  136. );
  137. });
  138. export const fetchProjectBuildingTypes = cache(async () => {
  139. return serverFetchJson<BuildingType[]>(
  140. `${BASE_API_URL}/projects/buildingTypes`,
  141. {
  142. next: { tags: ["projectBuildingTypes"] },
  143. },
  144. );
  145. });
  146. export const fetchProjectWorkNatures = cache(async () => {
  147. return serverFetchJson<WorkNature[]>(`${BASE_API_URL}/projects/workNatures`, {
  148. next: { tags: ["projectWorkNatures"] },
  149. });
  150. });
  151. export const fetchAssignedProjects = cache(async () => {
  152. return serverFetchJson<AssignedProject[]>(
  153. `${BASE_API_URL}/projects/assignedProjects`,
  154. {
  155. next: { tags: [`assignedProjects`] },
  156. },
  157. );
  158. });
  159. export const fetchProjectWithTasks = cache(async () => {
  160. return serverFetchJson<ProjectWithTasks[]>(
  161. `${BASE_API_URL}/projects/allProjectWithTasks`,
  162. {
  163. next: { tags: ["allProjectWithTasks"] },
  164. },
  165. );
  166. });
  167. export const fetchProjectDetails = cache(async (projectId: string) => {
  168. return serverFetchJson<CreateProjectInputs>(
  169. `${BASE_API_URL}/projects/projectDetails/${projectId}`,
  170. {
  171. next: { tags: [`projectDetails_${projectId}`] },
  172. },
  173. );
  174. });