You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FilesPage.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React, { useEffect, useState } from "react";
  2. import PropTypes from "prop-types";
  3. import { useSelector, useDispatch } from "react-redux";
  4. import IconButton from "../../components/IconButton/IconButton";
  5. import { setCategoriesReq } from "../../store/actions/categories/categoriesAction";
  6. import {
  7. selectCategories,
  8. selectChildParentRelations,
  9. } from "../../store/selectors/categoriesSelector";
  10. import table from "../../assets/images/table.png";
  11. import { FILES_PAGE } from "../../constants/pages";
  12. import FileTable from "./FileTable";
  13. import { useParams } from "react-router-dom";
  14. const FilesPage = ({ history }) => {
  15. const categories = useSelector(selectCategories);
  16. const childParentRelations = useSelector(selectChildParentRelations);
  17. const dispatch = useDispatch();
  18. const [trigger, setTrigger] = useState(0);
  19. let { id } = useParams();
  20. useEffect(() => {
  21. if (id === undefined) {
  22. dispatch(setCategoriesReq(undefined));
  23. } else {
  24. dispatch(setCategoriesReq({ parentCategoryId: id }));
  25. }
  26. }, [id]);
  27. const getNameHandler = (name) => {
  28. if (name.length > 15) return name.substr(0, 15) + "...";
  29. return name;
  30. };
  31. return (
  32. <>
  33. <div className="l-t-rectangle"></div>
  34. <div className="r-b-rectangle"></div>
  35. <div
  36. className="pl-144"
  37. style={{ paddingTop: "36px" }}
  38. onClick={() => {
  39. setTrigger((trigger) => trigger + 1);
  40. }}
  41. >
  42. <div style={{ marginBottom: "50px" }}>
  43. <div style={{ marginBottom: "30px" }}>
  44. <h1 className="page-heading">Folderi</h1>
  45. <div className="page-navigation-buttons">
  46. <IconButton
  47. className="c-btn c-btn--primary-outlined files-view-page-delete-btn"
  48. onClick={() => history.push({ pathname: FILES_PAGE })}
  49. >
  50. <p>Root</p>
  51. </IconButton>
  52. {childParentRelations.map((relation) => (
  53. <IconButton
  54. className="c-btn c-btn--primary-outlined files-view-page-delete-btn"
  55. key={relation.id}
  56. onClick={() => history.push({ pathname: relation.id })}
  57. >
  58. <p>{relation.name}</p>
  59. </IconButton>
  60. ))}
  61. </div>
  62. </div>
  63. <div className="files-page-categories">
  64. {categories &&
  65. categories.map((category) => (
  66. <div
  67. className="files-page-categories-category"
  68. key={category.id}
  69. >
  70. <IconButton
  71. className="c-btn c-btn--primary-outlined files-page-category-button"
  72. data-testid="pattern-details-send-email"
  73. onClick={() =>
  74. history.push({
  75. pathname: FILES_PAGE + "/" + category.id,
  76. })
  77. }
  78. >
  79. <img
  80. style={{
  81. marginRight: "5px",
  82. width: "12px",
  83. height: "12px",
  84. }}
  85. src={table}
  86. />
  87. {getNameHandler(category.name)}
  88. </IconButton>
  89. </div>
  90. ))}
  91. </div>
  92. </div>
  93. <div style={{ marginBottom: "50px" }}>
  94. <div style={{ marginBottom: "30px" }}>
  95. <h1 className="page-heading">Fajlovi</h1>
  96. </div>
  97. <div className="files-page-categories">
  98. <FileTable trigger={trigger} />
  99. </div>
  100. </div>
  101. </div>
  102. </>
  103. );
  104. };
  105. FilesPage.propTypes = {
  106. history: PropTypes.shape({
  107. replace: PropTypes.func,
  108. push: PropTypes.func,
  109. location: PropTypes.shape({
  110. pathname: PropTypes.string,
  111. }),
  112. }),
  113. };
  114. export default FilesPage;