diff --git a/src/components/Documents/Documents.jsx b/src/components/Documents/Documents.jsx
index 488023ae..b1dbe493 100644
--- a/src/components/Documents/Documents.jsx
+++ b/src/components/Documents/Documents.jsx
@@ -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 }) => {
{/* Search */}
-
{/* Actions */}
@@ -157,21 +167,22 @@ const Documents = ({ Document_Entity, Entity }) => {
}`}
>
*/}
-
- {canUploadDocument && ()}
+ {(isSelf || canUploadDocument) && (
+
+ )}
{
+ 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 = ({
}
>
- {canModifyDocument && (
+ {(isSelf || canModifyDocument) && (
@@ -214,7 +225,7 @@ const DocumentsList = ({
>
)}
- {canDeleteDocument && (
+ {(isSelf || canDeleteDocument) && (
{
diff --git a/src/components/Employee/EmployeeNav.jsx b/src/components/Employee/EmployeeNav.jsx
index f5356ffe..8c25aa22 100644
--- a/src/components/Employee/EmployeeNav.jsx
+++ b/src/components/Employee/EmployeeNav.jsx
@@ -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 (