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

50 行
1.3 KiB

  1. import { LeaveEntry, TimeEntry } from "./actions";
  2. /**
  3. * @param entry - the time entry
  4. * @returns the field where there is an error, or an empty string if there is none
  5. */
  6. export const isValidTimeEntry = (entry: Partial<TimeEntry>): string => {
  7. // Test for errors
  8. let error: keyof TimeEntry | "" = "";
  9. // Either normal or other hours need to be inputted
  10. if (!entry.inputHours && !entry.otHours) {
  11. error = "inputHours";
  12. } else if (entry.inputHours && entry.inputHours <= 0) {
  13. error = "inputHours";
  14. } else if (entry.otHours && entry.otHours <= 0) {
  15. error = "otHours";
  16. }
  17. // If there is a project id, there should also be taskGroupId, taskId, inputHours
  18. if (entry.projectId) {
  19. if (!entry.taskGroupId) {
  20. error = "taskGroupId";
  21. } else if (!entry.taskId) {
  22. error = "taskId";
  23. }
  24. } else {
  25. if (!entry.remark) {
  26. error = "remark";
  27. }
  28. }
  29. return error;
  30. };
  31. export const isValidLeaveEntry = (entry: Partial<LeaveEntry>): string => {
  32. // Test for errrors
  33. let error: keyof LeaveEntry | "" = "";
  34. if (!entry.leaveTypeId) {
  35. error = "leaveTypeId";
  36. } else if (!entry.inputHours || !(entry.inputHours >= 0)) {
  37. error = "inputHours";
  38. }
  39. return error;
  40. };
  41. export const LEAVE_DAILY_MAX_HOURS = 8;
  42. export const TIMESHEET_DAILY_MAX_HOURS = 20;