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.
 
 

144 satır
3.7 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. interface Props extends Omit<PastEntryCalendarProps, "onDateSelect"> {
  24. open: boolean;
  25. handleClose: () => void;
  26. leaveTypes: LeaveType[];
  27. allProjects: ProjectWithTasks[];
  28. }
  29. const Indicator = styled(Box)(() => ({
  30. borderRadius: "50%",
  31. width: "1rem",
  32. height: "1rem",
  33. }));
  34. const PastEntryCalendarModal: React.FC<Props> = ({
  35. handleClose,
  36. open,
  37. timesheet,
  38. leaves,
  39. leaveTypes,
  40. allProjects,
  41. }) => {
  42. const { t } = useTranslation("home");
  43. const [selectedDate, setSelectedDate] = useState("");
  44. const clearDate = useCallback(() => {
  45. setSelectedDate("");
  46. }, []);
  47. const onClose = useCallback(() => {
  48. handleClose();
  49. }, [handleClose]);
  50. const content = selectedDate ? (
  51. <>
  52. <PastEntryList
  53. date={selectedDate}
  54. timesheet={timesheet}
  55. leaves={leaves}
  56. allProjects={allProjects}
  57. leaveTypes={leaveTypes}
  58. />
  59. </>
  60. ) : (
  61. <>
  62. <Stack marginBlockEnd={2}>
  63. <Box display="flex" alignItems="center" gap={1}>
  64. <Indicator sx={{ backgroundColor: "info.light" }} />
  65. <Typography variant="caption">{t("Has timesheet entry")}</Typography>
  66. </Box>
  67. <Box display="flex" alignItems="center" gap={1}>
  68. <Indicator sx={{ backgroundColor: "warning.light" }} />
  69. <Typography variant="caption">{t("Has leave entry")}</Typography>
  70. </Box>
  71. <Box display="flex" alignItems="center" gap={1}>
  72. <Indicator sx={{ backgroundColor: "success.light" }} />
  73. <Typography variant="caption">
  74. {t("Has both timesheet and leave entry")}
  75. </Typography>
  76. </Box>
  77. </Stack>
  78. <PastEntryCalendar
  79. timesheet={timesheet}
  80. leaves={leaves}
  81. onDateSelect={setSelectedDate}
  82. />
  83. </>
  84. );
  85. const isMobile = useIsMobile();
  86. return isMobile ? (
  87. <FullscreenModal open={open} onClose={onClose} closeModal={onClose}>
  88. <Box display="flex" flexDirection="column" gap={2} height="100%">
  89. <Typography variant="h6" flex="none" padding={2}>
  90. {t("Past Entries")}
  91. </Typography>
  92. <Box
  93. flex={1}
  94. paddingInline={2}
  95. overflow="hidden"
  96. display="flex"
  97. flexDirection="column"
  98. sx={{ overflow: "scroll" }}
  99. >
  100. {content}
  101. </Box>
  102. <Box padding={2} display="flex" justifyContent="flex-end">
  103. {selectedDate && (
  104. <Button
  105. variant="outlined"
  106. startIcon={<ArrowBack />}
  107. onClick={clearDate}
  108. >
  109. {t("Back")}
  110. </Button>
  111. )}
  112. </Box>
  113. </Box>
  114. </FullscreenModal>
  115. ) : (
  116. <Dialog onClose={onClose} open={open}>
  117. <DialogTitle>{t("Past Entries")}</DialogTitle>
  118. <DialogContent>{content}</DialogContent>
  119. {selectedDate && (
  120. <DialogActions>
  121. <Button
  122. variant="outlined"
  123. startIcon={<ArrowBack />}
  124. onClick={clearDate}
  125. >
  126. {t("Back")}
  127. </Button>
  128. </DialogActions>
  129. )}
  130. </Dialog>
  131. );
  132. };
  133. export default PastEntryCalendarModal;