25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

162 satır
4.4 KiB

  1. import {
  2. Box,
  3. Button,
  4. Dialog,
  5. DialogActions,
  6. DialogContent,
  7. DialogTitle,
  8. Stack,
  9. Typography,
  10. styled,
  11. } from "@mui/material";
  12. import PastEntryCalendar, {
  13. Props as PastEntryCalendarProps,
  14. } from "./PastEntryCalendar";
  15. import { useCallback, useState } from "react";
  16. import { useTranslation } from "react-i18next";
  17. import { ArrowBack } from "@mui/icons-material";
  18. import PastEntryList from "./PastEntryList";
  19. import { ProjectWithTasks } from "@/app/api/projects";
  20. import { LeaveType } from "@/app/api/timesheets";
  21. import useIsMobile from "@/app/utils/useIsMobile";
  22. import FullscreenModal from "../FullscreenModal";
  23. import MonthlySummary from "./MonthlySummary";
  24. import { HolidaysResult } from "@/app/api/holidays";
  25. import dayjs from "dayjs";
  26. interface Props
  27. extends Omit<PastEntryCalendarProps, "onDateSelect" | "onMonthChange"> {
  28. open: boolean;
  29. handleClose: () => void;
  30. leaveTypes: LeaveType[];
  31. allProjects: ProjectWithTasks[];
  32. companyHolidays: HolidaysResult[];
  33. }
  34. const Indicator = styled(Box)(() => ({
  35. borderRadius: "50%",
  36. width: "1rem",
  37. height: "1rem",
  38. }));
  39. const PastEntryCalendarModal: React.FC<Props> = ({
  40. handleClose,
  41. open,
  42. timesheet,
  43. leaves,
  44. leaveTypes,
  45. allProjects,
  46. }) => {
  47. const { t } = useTranslation("home");
  48. const [selectedDate, setSelectedDate] = useState("");
  49. const [currentMonth, setMonthChange] = useState(dayjs());
  50. const clearDate = useCallback(() => {
  51. setSelectedDate("");
  52. }, []);
  53. const onClose = useCallback(() => {
  54. handleClose();
  55. }, [handleClose]);
  56. const content = (
  57. <Box sx={{ display: "flex", flexDirection: { xs: "column", sm: "row" } }}>
  58. <Box>
  59. <Stack marginBlockEnd={2}>
  60. <Box display="flex" alignItems="center" gap={1}>
  61. <Indicator sx={{ backgroundColor: "info.light" }} />
  62. <Typography variant="caption">
  63. {t("Has timesheet entry")}
  64. </Typography>
  65. </Box>
  66. <Box display="flex" alignItems="center" gap={1}>
  67. <Indicator sx={{ backgroundColor: "warning.light" }} />
  68. <Typography variant="caption">{t("Has leave entry")}</Typography>
  69. </Box>
  70. <Box display="flex" alignItems="center" gap={1}>
  71. <Indicator sx={{ backgroundColor: "success.light" }} />
  72. <Typography variant="caption">
  73. {t("Has both timesheet and leave entry")}
  74. </Typography>
  75. </Box>
  76. </Stack>
  77. <PastEntryCalendar
  78. timesheet={timesheet}
  79. leaves={leaves}
  80. onDateSelect={setSelectedDate}
  81. onMonthChange={setMonthChange}
  82. />
  83. </Box>
  84. {selectedDate ? (
  85. <PastEntryList
  86. date={selectedDate}
  87. timesheet={timesheet}
  88. leaves={leaves}
  89. allProjects={allProjects}
  90. leaveTypes={leaveTypes}
  91. />
  92. ) : (
  93. <MonthlySummary
  94. currentMonth={currentMonth}
  95. timesheet={timesheet}
  96. leaves={leaves}
  97. companyHolidays={[]}
  98. onDateSelect={setSelectedDate}
  99. />
  100. )}
  101. </Box>
  102. );
  103. const isMobile = useIsMobile();
  104. return isMobile ? (
  105. <FullscreenModal open={open} onClose={onClose} closeModal={onClose}>
  106. <Box display="flex" flexDirection="column" gap={2} height="100%">
  107. <Typography variant="h6" flex="none" padding={2}>
  108. {t("Past Entries")}
  109. </Typography>
  110. <Box
  111. flex={1}
  112. paddingInline={2}
  113. overflow="hidden"
  114. display="flex"
  115. flexDirection="column"
  116. sx={{ overflow: "scroll" }}
  117. >
  118. {content}
  119. </Box>
  120. <Box padding={2} display="flex" justifyContent="flex-end">
  121. {selectedDate && (
  122. <Button
  123. variant="outlined"
  124. startIcon={<ArrowBack />}
  125. onClick={clearDate}
  126. >
  127. {t("Back to Monthly Summary")}
  128. </Button>
  129. )}
  130. </Box>
  131. </Box>
  132. </FullscreenModal>
  133. ) : (
  134. <Dialog onClose={onClose} open={open} maxWidth="md">
  135. <DialogTitle>{t("Past Entries")}</DialogTitle>
  136. <DialogContent>{content}</DialogContent>
  137. {selectedDate && (
  138. <DialogActions>
  139. <Button
  140. variant="outlined"
  141. startIcon={<ArrowBack />}
  142. onClick={clearDate}
  143. >
  144. {t("Back to Monthly Summary")}
  145. </Button>
  146. </DialogActions>
  147. )}
  148. </Dialog>
  149. );
  150. };
  151. export default PastEntryCalendarModal;