Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

87 rindas
2.4 KiB

  1. import React, { useEffect } from "react";
  2. import {
  3. Card,
  4. CardContent,
  5. Grid,
  6. IconButton,
  7. InputAdornment,
  8. Stack,
  9. TextField,
  10. Typography,
  11. } from "@mui/material";
  12. import { useTranslation } from "react-i18next";
  13. import { Clear, Search } from "@mui/icons-material";
  14. import ProjectGrid from "./ProjectGrid";
  15. import { Props as UserWorkspaceProps } from "./UserWorkspacePage";
  16. interface Props {
  17. assignedProjects: UserWorkspaceProps["assignedProjects"];
  18. }
  19. const AssignedProjects: React.FC<Props> = ({ assignedProjects }) => {
  20. const { t } = useTranslation("home");
  21. // Projects
  22. const [filteredProjects, setFilterProjects] =
  23. React.useState(assignedProjects);
  24. // Query related
  25. const [query, setQuery] = React.useState("");
  26. const onQueryInputChange = React.useCallback<
  27. React.ChangeEventHandler<HTMLInputElement>
  28. >((e) => {
  29. setQuery(e.target.value);
  30. }, []);
  31. const clearQueryInput = React.useCallback(() => {
  32. setQuery("");
  33. }, []);
  34. useEffect(() => {
  35. setFilterProjects(
  36. assignedProjects.filter(
  37. (p) =>
  38. p.code.toLowerCase().includes(query.toLowerCase()) ||
  39. p.name.toLowerCase().includes(query.toLowerCase()),
  40. ),
  41. );
  42. }, [assignedProjects, query]);
  43. return (
  44. <>
  45. <Card>
  46. <CardContent>
  47. <Stack gap={2}>
  48. <Typography variant="overline" display="block">
  49. {t("Assigned Projects")}
  50. </Typography>
  51. <Grid container spacing={2} columns={{ xs: 6, sm: 12 }}>
  52. <Grid item xs={6} display="flex" alignItems="center">
  53. <Search sx={{ marginInlineEnd: 1 }} />
  54. <TextField
  55. variant="standard"
  56. fullWidth
  57. onChange={onQueryInputChange}
  58. value={query}
  59. placeholder={t("Search projects by name or code")}
  60. InputProps={{
  61. endAdornment: query && (
  62. <InputAdornment position="end">
  63. <IconButton onClick={clearQueryInput}>
  64. <Clear />
  65. </IconButton>
  66. </InputAdornment>
  67. ),
  68. }}
  69. />
  70. </Grid>
  71. </Grid>
  72. </Stack>
  73. </CardContent>
  74. </Card>
  75. <ProjectGrid projects={filteredProjects} />
  76. </>
  77. );
  78. };
  79. export default AssignedProjects;