No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

108 líneas
2.7 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 interface CreateStaffInputs {
  16. name: string;
  17. staffId: string;
  18. companyId: number;
  19. salaryId: number;
  20. skillSetId?: number[];
  21. joinDate?: string;
  22. currentPositionId: number;
  23. joinPositionId?: number;
  24. gradeId: number;
  25. teamId?: number
  26. departmentId?: number;
  27. phone1: string;
  28. phone2?: string;
  29. email: string;
  30. emergContactName?: string;
  31. emergContactPhone?: string;
  32. employType: string;
  33. departDate?: string;
  34. departReason?: string;
  35. remark?: string;
  36. }
  37. export interface records {
  38. id: number;
  39. name: string;
  40. // team: Team[];
  41. }
  42. export interface salaryEffectiveInfo {
  43. id: number;
  44. date: string;
  45. salaryPoint: number;
  46. }
  47. export const saveStaff = async (data: CreateStaffInputs) => {
  48. // try {
  49. const newStaffList = await serverFetchJson(`${BASE_API_URL}/staffs/save`, {
  50. method: "POST",
  51. body: JSON.stringify(data),
  52. headers: { "Content-Type": "application/json" },
  53. });
  54. console.log(newStaffList)
  55. revalidateTag("staffs");
  56. return newStaffList
  57. // } catch (e: any) {
  58. // console.log(e.response)
  59. // throw new ServerFetchError(
  60. // "Something went wrong fetching data in serverssssss.",
  61. // e.response,
  62. // );
  63. // }
  64. };
  65. export const testing = async (data: CreateStaffInputs) => {
  66. return serverFetchJson(`${BASE_API_URL}/staffs/testing`, {
  67. method: "POST",
  68. body: JSON.stringify(data),
  69. headers: { "Content-Type": "application/json" },
  70. });
  71. };
  72. export const deleteStaff = async (id: number) => {
  73. const newStaffList = await serverFetchWithNoContent(`${BASE_API_URL}/staffs/delete/${id}`, {
  74. method: "DELETE",
  75. // body: JSON.stringify(data),
  76. headers: { "Content-Type": "application/json" },
  77. });
  78. revalidateTag("staffs");
  79. return newStaffList
  80. };
  81. export const fetchStaffEdit = cache(async (id: number) => {
  82. return serverFetchJson<data>(`${BASE_API_URL}/staffs/${id}`, {
  83. next: { tags: ["staffs"] },
  84. });
  85. });
  86. // export const preloadStaffEdit = (id: number) => {
  87. // fetchStaffEdit(id);
  88. // };
  89. export const fetchStaffCombo = cache(async () => {
  90. return serverFetchJson<records[]>(`${BASE_API_URL}/staffs/combo`, {
  91. next: { tags: ["staffs"] },
  92. });
  93. });