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.
 
 

135 lines
3.3 KiB

  1. "use server";
  2. import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  3. import { BASE_API_URL } from "@/config/api";
  4. import { StaffResult, data } from ".";
  5. import { cache } from "react";
  6. import { Team, staff } from "../team/actions";
  7. import { revalidateTag } from "next/cache";
  8. export interface CreateCustomInputs {
  9. // Project details
  10. projectCode: string;
  11. projectName: string;
  12. // Miscellaneous
  13. expectedProjectFee: string;
  14. }
  15. export type teamHistory = {
  16. id: number,
  17. team: string | number,
  18. from: Date | string,
  19. to?: Date | string
  20. }
  21. export type gradeHistory = {
  22. id: number,
  23. grade: string | number,
  24. from: Date | string,
  25. to?: Date | string
  26. }
  27. export type positionHistory = {
  28. id: number,
  29. position: string | number,
  30. from: Date | string,
  31. to?: Date | string
  32. }
  33. export interface CreateStaffInputs {
  34. id?: number
  35. name: string;
  36. staffId: string;
  37. companyId: number;
  38. salaryId: number;
  39. skillSetId?: number[];
  40. joinDate?: string | null;
  41. currentPositionId: number;
  42. joinPositionId?: number | null;
  43. gradeId: number;
  44. teamId?: number
  45. departmentId?: number;
  46. phone1: string;
  47. phone2?: string;
  48. email: string;
  49. emergContactName?: string;
  50. emergContactPhone?: string;
  51. employType: string;
  52. departDate?: string | null;
  53. departReason?: string;
  54. remark?: string;
  55. salaryEffectiveInfo?: any;
  56. teamHistory: teamHistory[];
  57. delTeamHistory: number[];
  58. gradeHistory: gradeHistory[];
  59. delGradeHistory: number[];
  60. positionHistory: positionHistory[];
  61. delPositionHistory: number[];
  62. }
  63. export interface records {
  64. id: number;
  65. name: string;
  66. // team: Team[];
  67. }
  68. export interface salaryEffectiveInfo {
  69. id: number;
  70. date: string;
  71. salaryPoint: number;
  72. }
  73. export const saveStaff = async (data: CreateStaffInputs) => {
  74. // try {
  75. const newStaffList = await serverFetchJson(`${BASE_API_URL}/staffs/save`, {
  76. method: "POST",
  77. body: JSON.stringify(data),
  78. headers: { "Content-Type": "application/json" },
  79. });
  80. console.log(newStaffList)
  81. revalidateTag("staffs");
  82. return newStaffList
  83. // } catch (e: any) {
  84. // console.log(e.response)
  85. // throw new ServerFetchError(
  86. // "Something went wrong fetching data in serverssssss.",
  87. // e.response,
  88. // );
  89. // }
  90. };
  91. export const testing = async (data: CreateStaffInputs) => {
  92. return serverFetchJson(`${BASE_API_URL}/staffs/testing`, {
  93. method: "POST",
  94. body: JSON.stringify(data),
  95. headers: { "Content-Type": "application/json" },
  96. });
  97. };
  98. export const deleteStaff = async (id: number) => {
  99. const newStaffList = await serverFetchWithNoContent(`${BASE_API_URL}/staffs/delete/${id}`, {
  100. method: "DELETE",
  101. // body: JSON.stringify(data),
  102. headers: { "Content-Type": "application/json" },
  103. });
  104. revalidateTag("staffs");
  105. return newStaffList
  106. };
  107. export const fetchStaffEdit = cache(async (id: number) => {
  108. return serverFetchJson<data>(`${BASE_API_URL}/staffs/${id}`, {
  109. next: { tags: ["staffs"] },
  110. });
  111. });
  112. // export const preloadStaffEdit = (id: number) => {
  113. // fetchStaffEdit(id);
  114. // };
  115. export const fetchStaffCombo = cache(async () => {
  116. return serverFetchJson<records[]>(`${BASE_API_URL}/staffs/combo`, {
  117. next: { tags: ["staffs"] },
  118. });
  119. });