added view, upload,update and delete permissions
This commit is contained in:
parent
f72b7c62c8
commit
49b89f74ff
@ -16,6 +16,7 @@ import ManageDocument from "./ManageDocument";
|
|||||||
import ViewDocument from "./ViewDocument";
|
import ViewDocument from "./ViewDocument";
|
||||||
import DocumentViewerModal from "./DocumentViewerModal";
|
import DocumentViewerModal from "./DocumentViewerModal";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
|
|
||||||
// Context
|
// Context
|
||||||
export const DocumentContext = createContext();
|
export const DocumentContext = createContext();
|
||||||
@ -47,6 +48,7 @@ export const getDocuementsStatus = (status) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const Documents = ({ Document_Entity, Entity }) => {
|
const Documents = ({ Document_Entity, Entity }) => {
|
||||||
|
const [isSelf, setIsSelf] = useState(false);
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const [isActive, setIsActive] = useState(true);
|
const [isActive, setIsActive] = useState(true);
|
||||||
const [filters, setFilter] = useState();
|
const [filters, setFilter] = useState();
|
||||||
@ -63,8 +65,14 @@ const Documents = ({ Document_Entity, Entity }) => {
|
|||||||
document: null,
|
document: null,
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
});
|
});
|
||||||
|
const { profile } = useProfile();
|
||||||
|
|
||||||
const canUploadDocument = useHasUserPermission(UPLOAD_DOCUMENT)
|
useEffect(() => {
|
||||||
|
if (profile?.employeeInfo?.id) {
|
||||||
|
setIsSelf(profile.employeeInfo.id === employeeId);
|
||||||
|
}
|
||||||
|
}, [profile?.employeeInfo?.id, employeeId]);
|
||||||
|
const canUploadDocument = useHasUserPermission(UPLOAD_DOCUMENT);
|
||||||
|
|
||||||
const { setOffcanvasContent, setShowTrigger } = useFab();
|
const { setOffcanvasContent, setShowTrigger } = useFab();
|
||||||
|
|
||||||
@ -114,13 +122,16 @@ const Documents = ({ Document_Entity, Entity }) => {
|
|||||||
<div className="row align-items-center">
|
<div className="row align-items-center">
|
||||||
{/* Search */}
|
{/* Search */}
|
||||||
<div className="d-flex col-8 col-md-8 col-lg-4 mb-md-0 align-items-center">
|
<div className="d-flex col-8 col-md-8 col-lg-4 mb-md-0 align-items-center">
|
||||||
<div className="d-flex"> <input
|
<div className="d-flex">
|
||||||
type="search"
|
{" "}
|
||||||
value={searchText}
|
<input
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
type="search"
|
||||||
className="form-control form-control-sm"
|
value={searchText}
|
||||||
placeholder="Search Document"
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
/></div>
|
className="form-control form-control-sm"
|
||||||
|
placeholder="Search Document"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<label className="switch switch-sm mx-2">
|
<label className="switch switch-sm mx-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
@ -137,7 +148,6 @@ const Documents = ({ Document_Entity, Entity }) => {
|
|||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{/* Actions */}
|
{/* Actions */}
|
||||||
<div className="col-6 col-md-6 col-lg-8 text-end">
|
<div className="col-6 col-md-6 col-lg-8 text-end">
|
||||||
@ -157,21 +167,22 @@ const Documents = ({ Document_Entity, Entity }) => {
|
|||||||
}`}
|
}`}
|
||||||
></i>
|
></i>
|
||||||
</span> */}
|
</span> */}
|
||||||
|
|
||||||
|
|
||||||
{canUploadDocument && (<button
|
{(isSelf || canUploadDocument) && (
|
||||||
type="button"
|
<button
|
||||||
title="Add New Document"
|
type="button"
|
||||||
className="p-1 bg-primary rounded-circle cursor-pointer"
|
title="Add New Document"
|
||||||
onClick={() =>
|
className="p-1 bg-primary rounded-circle cursor-pointer"
|
||||||
setManageDoc({
|
onClick={() =>
|
||||||
document: null,
|
setManageDoc({
|
||||||
isOpen: true,
|
document: null,
|
||||||
})
|
isOpen: true,
|
||||||
}
|
})
|
||||||
>
|
}
|
||||||
<i className="bx bx-plus fs-4 text-white"></i>
|
>
|
||||||
</button>)}
|
<i className="bx bx-plus fs-4 text-white"></i>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DocumentsList
|
<DocumentsList
|
||||||
|
@ -17,6 +17,8 @@ import Pagination from "../common/Pagination";
|
|||||||
import ConfirmModal from "../common/ConfirmModal";
|
import ConfirmModal from "../common/ConfirmModal";
|
||||||
import { isPending } from "@reduxjs/toolkit";
|
import { isPending } from "@reduxjs/toolkit";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
const DocumentsList = ({
|
const DocumentsList = ({
|
||||||
Document_Entity,
|
Document_Entity,
|
||||||
@ -27,13 +29,22 @@ const DocumentsList = ({
|
|||||||
setRefetchFn,
|
setRefetchFn,
|
||||||
isActive,
|
isActive,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { employeeId } = useParams();
|
||||||
|
const [isSelf, setIsSelf] = useState(false);
|
||||||
|
const { profile } = useProfile();
|
||||||
|
const canDeleteDocument = useHasUserPermission(DELETE_DOCUMENT);
|
||||||
|
const canModifyDocument = useHasUserPermission(MODIFY_DOCUMENT);
|
||||||
|
useEffect(() => {
|
||||||
|
if (profile?.employeeInfo?.id && employeeId) {
|
||||||
|
setIsSelf(String(profile.employeeInfo.id) === String(employeeId));
|
||||||
|
}
|
||||||
|
}, [profile?.employeeInfo?.id, employeeId]);
|
||||||
const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
const [deletingId, setDeletingId] = useState(null);
|
const [deletingId, setDeletingId] = useState(null);
|
||||||
const [restoringIds, setRestoringIds] = useState([]);
|
const [restoringIds, setRestoringIds] = useState([]);
|
||||||
const debouncedSearch = useDebounce(searchText, 500);
|
const debouncedSearch = useDebounce(searchText, 500);
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const canDeleteDocument = useHasUserPermission(DELETE_DOCUMENT);
|
|
||||||
const canModifyDocument = useHasUserPermission(MODIFY_DOCUMENT);
|
|
||||||
const { data, isError, isLoading, error, refetch, isFetching } =
|
const { data, isError, isLoading, error, refetch, isFetching } =
|
||||||
useDocumentListByEntityId(
|
useDocumentListByEntityId(
|
||||||
Document_Entity,
|
Document_Entity,
|
||||||
@ -205,7 +216,7 @@ const DocumentsList = ({
|
|||||||
}
|
}
|
||||||
></i>
|
></i>
|
||||||
|
|
||||||
{canModifyDocument && (
|
{(isSelf || canModifyDocument) && (
|
||||||
<i
|
<i
|
||||||
className="bx bx-edit text-secondary cursor-pointer"
|
className="bx bx-edit text-secondary cursor-pointer"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
@ -214,7 +225,7 @@ const DocumentsList = ({
|
|||||||
></i>
|
></i>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{canDeleteDocument && (
|
{(isSelf || canDeleteDocument) && (
|
||||||
<i
|
<i
|
||||||
className="bx bx-trash text-danger cursor-pointer"
|
className="bx bx-trash text-danger cursor-pointer"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -1,19 +1,31 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import { VIEW_DOCUMENT } from "../../utils/constants";
|
import { VIEW_DOCUMENT } from "../../utils/constants";
|
||||||
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
const EmployeeNav = ({ onPillClick, activePill }) => {
|
const EmployeeNav = ({ onPillClick, activePill }) => {
|
||||||
const canViewDocuments = useHasUserPermission(VIEW_DOCUMENT)
|
const { employeeId } = useParams();
|
||||||
const tabs = [
|
const [isAbleToViewDocuments, setIsAbleToViewDocuments] = useState(false);
|
||||||
|
|
||||||
|
const canViewDocuments = useHasUserPermission(VIEW_DOCUMENT);
|
||||||
|
const { profile } = useProfile();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (profile?.employeeInfo?.id) {
|
||||||
|
setIsAbleToViewDocuments(profile.employeeInfo.id === employeeId);
|
||||||
|
}
|
||||||
|
}, [profile?.employeeInfo?.id, employeeId]);
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
{ key: "profile", icon: "bx bx-user", label: "Profile" },
|
{ key: "profile", icon: "bx bx-user", label: "Profile" },
|
||||||
{ key: "attendance", icon: "bx bx-group", label: "Attendances" },
|
{ key: "attendance", icon: "bx bx-group", label: "Attendances" },
|
||||||
canViewDocuments && {
|
(isAbleToViewDocuments || canViewDocuments) && {
|
||||||
key: "documents",
|
key: "documents",
|
||||||
icon: "bx bx-file",
|
icon: "bx bx-file",
|
||||||
label: "Documents",
|
label: "Documents",
|
||||||
},
|
},
|
||||||
{ key: "activities", icon: "bx bx-grid-alt", label: "Activities" },
|
{ key: "activities", icon: "bx bx-grid-alt", label: "Activities" },
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="col-md-12">
|
<div className="col-md-12">
|
||||||
<div className="nav-align-top">
|
<div className="nav-align-top">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user