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

125 行
2.8 KiB

  1. "use server";
  2. import { serverFetchJson } from "@/app/utils/fetchUtil";
  3. import { ProjectResult } from "../projects";
  4. import { Task, TaskGroup } from "../tasks";
  5. import { BASE_API_URL } from "@/config/api";
  6. import { revalidatePath, revalidateTag } from "next/cache";
  7. export interface TimeEntry {
  8. id: number;
  9. projectId?: ProjectResult["id"];
  10. taskGroupId?: TaskGroup["id"];
  11. taskId?: Task["id"];
  12. inputHours?: number;
  13. otHours?: number;
  14. remark?: string;
  15. }
  16. export interface RecordTimesheetInput {
  17. [date: string]: TimeEntry[];
  18. }
  19. export interface LeaveEntry {
  20. id: number;
  21. inputHours: number;
  22. leaveTypeId: number;
  23. remark?: string;
  24. }
  25. export interface RecordLeaveInput {
  26. [date: string]: LeaveEntry[];
  27. }
  28. export const saveTimesheet = async (data: RecordTimesheetInput) => {
  29. const savedRecords = await serverFetchJson<RecordTimesheetInput>(
  30. `${BASE_API_URL}/timesheets/save`,
  31. {
  32. method: "POST",
  33. body: JSON.stringify(data),
  34. headers: { "Content-Type": "application/json" },
  35. },
  36. );
  37. revalidateTag(`timesheets`);
  38. return savedRecords;
  39. };
  40. export const saveLeave = async (data: RecordLeaveInput) => {
  41. const savedRecords = await serverFetchJson<RecordLeaveInput>(
  42. `${BASE_API_URL}/timesheets/saveLeave`,
  43. {
  44. method: "POST",
  45. body: JSON.stringify(data),
  46. headers: { "Content-Type": "application/json" },
  47. },
  48. );
  49. revalidateTag(`leaves`);
  50. return savedRecords;
  51. };
  52. export const saveMemberEntry = async (data: {
  53. staffId: number;
  54. entry: TimeEntry;
  55. recordDate?: string;
  56. }) => {
  57. return serverFetchJson<RecordTimesheetInput>(
  58. `${BASE_API_URL}/timesheets/saveMemberEntry`,
  59. {
  60. method: "POST",
  61. body: JSON.stringify(data),
  62. headers: { "Content-Type": "application/json" },
  63. },
  64. );
  65. };
  66. export const saveMemberLeave = async (data: {
  67. staffId: number;
  68. entry: LeaveEntry;
  69. recordDate?: string;
  70. }) => {
  71. return serverFetchJson<RecordLeaveInput>(
  72. `${BASE_API_URL}/timesheets/saveMemberLeave`,
  73. {
  74. method: "POST",
  75. body: JSON.stringify(data),
  76. headers: { "Content-Type": "application/json" },
  77. },
  78. );
  79. };
  80. export const deleteMemberEntry = async (data: {
  81. staffId: number;
  82. entryId: number;
  83. }) => {
  84. return serverFetchJson<RecordTimesheetInput>(
  85. `${BASE_API_URL}/timesheets/deleteMemberEntry`,
  86. {
  87. method: "POST",
  88. body: JSON.stringify(data),
  89. headers: { "Content-Type": "application/json" },
  90. },
  91. );
  92. };
  93. export const deleteMemberLeave = async (data: {
  94. staffId: number;
  95. entryId: number;
  96. }) => {
  97. return serverFetchJson<RecordLeaveInput>(
  98. `${BASE_API_URL}/timesheets/deleteMemberLeave`,
  99. {
  100. method: "POST",
  101. body: JSON.stringify(data),
  102. headers: { "Content-Type": "application/json" },
  103. },
  104. );
  105. };
  106. export const revalidateCacheAfterAmendment = () => {
  107. revalidatePath("/(main)/home");
  108. };