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

155 行
3.8 KiB

  1. import { CreateProjectInputs } from "@/app/api/projects/actions";
  2. import { TaskGroup } from "@/app/api/tasks";
  3. import { Add, Delete } from "@mui/icons-material";
  4. import {
  5. Stack,
  6. Typography,
  7. Grid,
  8. FormControl,
  9. Box,
  10. Button,
  11. } from "@mui/material";
  12. import {
  13. GridColDef,
  14. GridActionsCellItem,
  15. GridToolbarContainer,
  16. } from "@mui/x-data-grid";
  17. import { LocalizationProvider, DatePicker } from "@mui/x-date-pickers";
  18. import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
  19. import dayjs from "dayjs";
  20. import "dayjs/locale/zh-hk";
  21. import React, { useMemo } from "react";
  22. import { useFormContext } from "react-hook-form";
  23. import { useTranslation } from "react-i18next";
  24. import StyledDataGrid from "../StyledDataGrid";
  25. interface Props {
  26. taskGroupId: TaskGroup["id"];
  27. }
  28. interface FooterToolbarProps {
  29. onAdd: () => void;
  30. }
  31. const MilestoneSection: React.FC<Props> = ({ taskGroupId }) => {
  32. const { t } = useTranslation();
  33. const {} = useFormContext<CreateProjectInputs>();
  34. const columns = useMemo<GridColDef[]>(
  35. () => [
  36. {
  37. type: "actions",
  38. field: "actions",
  39. headerName: t("Actions"),
  40. getActions: () => [
  41. <GridActionsCellItem
  42. key="delete-action"
  43. icon={<Delete />}
  44. label={t("Remove")}
  45. onClick={() => {}}
  46. />,
  47. ],
  48. },
  49. {
  50. field: "description",
  51. headerName: t("Payment Milestone Description"),
  52. width: 300,
  53. editable: true,
  54. },
  55. {
  56. field: "date",
  57. headerName: t("Payment Milestone Date"),
  58. width: 200,
  59. type: "date",
  60. editable: true,
  61. },
  62. {
  63. field: "amount",
  64. headerName: t("Payment Milestone Amount"),
  65. width: 300,
  66. editable: true,
  67. type: "number",
  68. },
  69. ],
  70. [t],
  71. );
  72. return (
  73. <Stack gap={1}>
  74. <Typography variant="overline" display="block" marginBlockEnd={1}>
  75. {t("Milestone")}
  76. </Typography>
  77. <LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="zh-hk">
  78. <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
  79. <Grid item xs>
  80. <FormControl fullWidth>
  81. <DatePicker
  82. label={t("Stage Start Date")}
  83. defaultValue={dayjs()}
  84. />
  85. </FormControl>
  86. </Grid>
  87. <Grid item xs>
  88. <FormControl fullWidth>
  89. <DatePicker label={t("Stage End Date")} defaultValue={dayjs()} />
  90. </FormControl>
  91. </Grid>
  92. </Grid>
  93. </LocalizationProvider>
  94. <Box
  95. sx={(theme) => ({
  96. marginBlockStart: 1,
  97. marginInline: -3,
  98. borderBottom: `1px solid ${theme.palette.divider}`,
  99. })}
  100. >
  101. <StyledDataGrid
  102. autoHeight
  103. sx={{ "--DataGrid-overlayHeight": "100px" }}
  104. disableColumnMenu
  105. rows={[]}
  106. columns={columns}
  107. slots={{
  108. footer: FooterToolbar,
  109. noRowsOverlay: NoRowsOverlay,
  110. }}
  111. slotProps={{
  112. footer: undefined,
  113. }}
  114. />
  115. </Box>
  116. </Stack>
  117. );
  118. };
  119. const NoRowsOverlay: React.FC = () => {
  120. const { t } = useTranslation();
  121. return (
  122. <Box
  123. display="flex"
  124. justifyContent="center"
  125. alignItems="center"
  126. height="100%"
  127. >
  128. <Typography variant="caption">{t("Add some milestones!")}</Typography>
  129. </Box>
  130. );
  131. };
  132. const FooterToolbar: React.FC<FooterToolbarProps> = ({ onAdd }) => {
  133. const { t } = useTranslation();
  134. return (
  135. <GridToolbarContainer sx={{ p: 2 }}>
  136. <Button
  137. variant="outlined"
  138. startIcon={<Add />}
  139. onClick={onAdd}
  140. size="small"
  141. >
  142. {t("Add Milestone")}
  143. </Button>
  144. </GridToolbarContainer>
  145. );
  146. };
  147. export default MilestoneSection;