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