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.
 
 

64 lines
1.5 KiB

  1. import { serverFetchJson } from "@/app/utils/fetchUtil";
  2. import { BASE_API_URL } from "@/config/api";
  3. import { cache } from "react";
  4. import { RecordLeaveInput, RecordTimesheetInput } from "./actions";
  5. export interface LeaveType {
  6. id: number;
  7. name: string;
  8. }
  9. export type TeamTimeSheets = {
  10. [memberId: number]: {
  11. timeEntries: RecordTimesheetInput;
  12. staffId: string;
  13. name: string;
  14. employType: string | null;
  15. };
  16. };
  17. export type TeamLeaves = {
  18. [memberId: number]: {
  19. leaveEntries: RecordLeaveInput;
  20. staffId: string;
  21. name: string;
  22. employType: string | null;
  23. };
  24. };
  25. export const fetchTimesheets = cache(async () => {
  26. return serverFetchJson<RecordTimesheetInput>(`${BASE_API_URL}/timesheets`, {
  27. next: { tags: [`timesheets`] },
  28. });
  29. });
  30. export const fetchLeaves = cache(async () => {
  31. return serverFetchJson<RecordLeaveInput>(
  32. `${BASE_API_URL}/timesheets/leaves`,
  33. {
  34. next: { tags: [`leaves`] },
  35. },
  36. );
  37. });
  38. export const fetchLeaveTypes = cache(async () => {
  39. return serverFetchJson<LeaveType[]>(`${BASE_API_URL}/timesheets/leaveTypes`, {
  40. next: { tags: ["leaveTypes"] },
  41. });
  42. });
  43. export const fetchTeamMemberTimesheets = cache(async () => {
  44. return serverFetchJson<TeamTimeSheets>(
  45. `${BASE_API_URL}/timesheets/teamTimesheets`,
  46. {
  47. next: { tags: [`team_timesheets`] },
  48. },
  49. );
  50. });
  51. export const fetchTeamMemberLeaves = cache(async () => {
  52. return serverFetchJson<TeamLeaves>(`${BASE_API_URL}/timesheets/teamLeaves`, {
  53. next: { tags: [`team_leaves`] },
  54. });
  55. });