- {firstPhone ? (
-
+ {contact.contactPhones?.length > 0 ? (
+ contact.contactPhones?.map((phone, index) => (
+
- {firstPhone.phoneNumber}
+ {phone.phoneNumber}
- ) : (
- NA
- )}
+ ))
+ ):(NA )}
@@ -94,6 +88,12 @@ const ListViewDirectory = ({
{contact.organization}
+ {/*
+
+ {contact?.contactCategory?.name || "Other"}
+
+ */}
+
{contact?.contactCategory?.name || "Other"}
@@ -118,10 +118,9 @@ const ListViewDirectory = ({
)}
{!IsActive && (
{
diff --git a/src/components/Directory/ManageDirectory.jsx b/src/components/Directory/ManageDirectory.jsx
index 5c858815..285b74f2 100644
--- a/src/components/Directory/ManageDirectory.jsx
+++ b/src/components/Directory/ManageDirectory.jsx
@@ -14,11 +14,7 @@ import useMaster, {
} from "../../hooks/masterHook/useMaster";
import { useDispatch, useSelector } from "react-redux";
import { changeMaster } from "../../slices/localVariablesSlice";
-import {
- useBuckets,
- useDesignation,
- useOrganization,
-} from "../../hooks/useDirectory";
+import { useBuckets, useOrganization } from "../../hooks/useDirectory";
import { useProjects } from "../../hooks/useProjects";
import SelectMultiple from "../common/SelectMultiple";
import { ContactSchema } from "./DirectorySchema";
@@ -37,11 +33,8 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
const { contactCategory, loading: contactCategoryLoading } =
useContactCategory();
const { organizationList, loading: orgLoading } = useOrganization();
- const { designationList, loading: designloading } = useDesignation();
const { contactTags, loading: Tagloading } = useContactTags();
const [IsSubmitting, setSubmitting] = useState(false);
- const [showSuggestions,setShowSuggestions] = useState(false);
- const [filteredDesignationList, setFilteredDesignationList] = useState([]);
const dispatch = useDispatch();
const methods = useForm({
@@ -52,7 +45,6 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
contactCategoryId: null,
address: "",
description: "",
- designation: "",
projectIds: [],
contactEmails: [],
contactPhones: [],
@@ -114,25 +106,6 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
const watchBucketIds = watch("bucketIds");
- // handle logic when input of desgination is changed
- const handleDesignationChange = (e) => {
- const val = e.target.value;
-
- const matches = designationList.filter((org) =>
- org.toLowerCase().includes(val.toLowerCase())
- );
- setFilteredDesignationList(matches);
- setShowSuggestions(true);
- setTimeout(() => setShowSuggestions(false), 5000);
- };
-
- // handle logic when designation is selected
- const handleSelectDesignation = (val) => {
- setShowSuggestions(false);
- setValue("designation", val);
- };
-
-
const toggleBucketId = (id) => {
const updated = watchBucketIds?.includes(id)
? watchBucketIds.filter((val) => val !== id)
@@ -195,55 +168,6 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
/>
-
-
-
Designation
-
- {showSuggestions && filteredDesignationList.length > 0 && (
-
- {filteredDesignationList.map((designation) => (
- handleSelectDesignation(designation)}
- onMouseEnter={(e) =>
- (e.currentTarget.style.backgroundColor = "#f8f9fa")
- }
- onMouseLeave={(e) =>
- (e.currentTarget.style.backgroundColor = "transparent")
- }
- >
- {designation}
-
- ))}
-
- )}
- {errors.designation && (
-
- {errors.designation.message}
-
- )}
-
-
{emailFields.map((field, index) => (
@@ -457,12 +381,13 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
))}
+
- {errors.bucketIds && (
-
- {errors.bucketIds.message}
-
- )}
+ {errors.bucketIds && (
+
+ {errors.bucketIds.message}
+
+ )}
diff --git a/src/components/Directory/NoteCardDirectoryEditable.jsx b/src/components/Directory/NoteCardDirectoryEditable.jsx
index 5ccfefdf..de91ad69 100644
--- a/src/components/Directory/NoteCardDirectoryEditable.jsx
+++ b/src/components/Directory/NoteCardDirectoryEditable.jsx
@@ -153,7 +153,7 @@ const NoteCardDirectoryEditable = ({
.utc(noteItem?.createdAt)
.add(5, "hours")
.add(30, "minutes")
- .format("DD MMMM, YYYY [at] hh:mm A")}
+ .format("MMMM DD, YYYY [at] hh:mm A")}
diff --git a/src/components/Directory/NotesDirectory.jsx b/src/components/Directory/NotesDirectory.jsx
index cccfd8ef..61908853 100644
--- a/src/components/Directory/NotesDirectory.jsx
+++ b/src/components/Directory/NotesDirectory.jsx
@@ -4,6 +4,7 @@ import Avatar from "../common/Avatar";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
+import { showText } from "pdf-lib";
import { DirectoryRepository } from "../../repositories/DirectoryRepository";
import moment from "moment";
import { cacheData, getCachedData } from "../../slices/apiDataManager";
@@ -18,17 +19,15 @@ const schema = z.object({
const NotesDirectory = ({
refetchProfile,
isLoading,
- contactProfile, // This contactProfile now reliably includes firstName, middleName, lastName, and fullName
+ contactProfile,
setProfileContact,
}) => {
const [IsActive, setIsActive] = useState(true);
- const { contactNotes, refetch } = useContactNotes(
- contactProfile?.id,
- IsActive
- );
+ const { contactNotes, refetch } = useContactNotes(contactProfile?.id, true);
+ const [NotesData, setNotesData] = useState();
const [IsSubmitting, setIsSubmitting] = useState(false);
- const [showEditor, setShowEditor] = useState(false);
+ const [addNote, setAddNote] = useState(true);
const {
register,
handleSubmit,
@@ -68,122 +67,102 @@ const NotesDirectory = ({
) {
const updatedProfile = {
...cached_contactProfile.data,
- notes: [...(cached_contactProfile.data.notes || []), createdNote],
+ notes: [...(cached_contactProfile.notes || []), createdNote],
};
- cacheData("Contact Profile", {
- contactId: contactProfile?.id,
- data: updatedProfile,
- });
+ cacheData("Contact Profile", updatedProfile);
}
setValue("note", "");
setIsSubmitting(false);
showToast("Note added successfully!", "success");
- setShowEditor(false);
+ setAddNote(true);
setIsActive(true);
- refetch(contactProfile?.id, true);
} catch (error) {
setIsSubmitting(false);
const msg =
- error.response?.data?.message ||
+ error.response.data.message ||
error.message ||
- "Error occurred during API calling";
+ "Error occured during API calling";
showToast(msg, "error");
}
};
const onCancel = () => {
- setValue("note", "");
- setShowEditor(false);
+ setValue( "note", "" );
+
};
-
const handleSwitch = () => {
- setIsActive((prevIsActive) => {
- const newState = !prevIsActive;
- refetch(contactProfile?.id, newState);
- return newState;
- });
+ setIsActive(!IsActive);
+ if (IsActive) {
+ refetch(contactProfile?.id, false);
+ }
};
- // Use the fullName from contactProfile, which now includes middle and last names if available
- const contactName =
- contactProfile?.fullName || contactProfile?.firstName || "Contact";
- const noNotesMessage = `Be the first to share your insights! ${contactName} currently has no notes.`;
-
- const notesToDisplay = IsActive
- ? contactProfile?.notes || []
- : contactNotes || [];
-
return (
-
+
-
- {showEditor && (
-
-
setShowEditor(false)}
- >
-
+
+
+
+
+ setAddNote(!addNote)}
+ >
+ {addNote ? "Hide Editor" : "Add a Note"}
+
+
+
+
+
+ {addNote && (
+
+
setAddNote(!addNote)}
+ >
+ {/*
+ setAddNote(!addNote)}
+ >
+ {addNote ? "Hide Editor" : "Add Note"}
+
+
*/}
)}
-
+
{isLoading && (
)}
- {!isLoading && notesToDisplay.length > 0
- ? notesToDisplay
- .slice()
- .reverse()
- .map((noteItem) => (
-
- ))
- : !isLoading &&
- !showEditor && (
-
{noNotesMessage}
+ {!isLoading &&
+ [...(IsActive ? contactProfile?.notes || [] : contactNotes || [])]
+ .reverse()
+ .map((noteItem) => (
+
+ ))}
+
+ {IsActive && (
+
+ {!isLoading && contactProfile?.notes.length == 0 && !addNote && (
+
No Notes Found
)}
+
+ )}
+ {!IsActive && (
+
+ {!isLoading && contactNotes.length == 0 && !addNote && (
+
No Notes Found
+ )}
+
+ )}
);
diff --git a/src/components/Directory/ProfileContactDirectory.jsx b/src/components/Directory/ProfileContactDirectory.jsx
index f7e8c456..256e2ea8 100644
--- a/src/components/Directory/ProfileContactDirectory.jsx
+++ b/src/components/Directory/ProfileContactDirectory.jsx
@@ -8,10 +8,9 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
const { contactProfile, loading, refetch } = useContactProfile(contact?.id);
const [copiedIndex, setCopiedIndex] = useState(null);
- const [profileContactState, setProfileContactState] = useState(null);
+ const [profileContact, setProfileContact] = useState();
const [expanded, setExpanded] = useState(false);
-
- const description = profileContactState?.description || "";
+ const description = contactProfile?.description || "";
const limit = 500;
const toggleReadMore = () => setExpanded(!expanded);
@@ -20,51 +19,14 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
const displayText = expanded
? description
: description.slice(0, limit) + (isLong ? "..." : "");
-
useEffect(() => {
- if (contactProfile) {
- const names = (contact?.name || "").trim().split(" ");
- let firstName = "";
- let middleName = "";
- let lastName = "";
- let fullName = contact?.name || "";
-
- // Logic to determine first, middle, and last names
- if (names.length === 1) {
- firstName = names[0];
- } else if (names.length === 2) {
- firstName = names[0];
- lastName = names[1];
- } else if (names.length >= 3) {
- firstName = names[0];
- middleName = names[1]; // This was an error in the original prompt, corrected to names[1]
- lastName = names[names.length - 1];
- // Reconstruct full name to be precise with spacing
- fullName = `${firstName} ${middleName ? middleName + ' ' : ''}${lastName}`;
- } else {
- // Fallback if no names or empty string
- firstName = "Contact";
- fullName = "Contact";
- }
-
-
- setProfileContactState({
- ...contactProfile,
- firstName: contactProfile.firstName || firstName,
- // Adding middleName and lastName to the state for potential future use or more granular access
- middleName: contactProfile.middleName || middleName,
- lastName: contactProfile.lastName || lastName,
- fullName: contactProfile.fullName || fullName, // Prioritize fetched fullName, fallback to derived
- });
- }
- }, [contactProfile, contact?.name]);
-
+ setProfileContact(contactProfile);
+ }, [contactProfile]);
const handleCopy = (email, index) => {
navigator.clipboard.writeText(email);
setCopiedIndex(index);
- setTimeout(() => setCopiedIndex(null), 2000);
+ setTimeout(() => setCopiedIndex(null), 2000); // Reset after 2 seconds
};
-
return (
@@ -85,35 +47,31 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
{contact?.name}
- {profileContactState?.designation}
+ {contactProfile?.tags?.map((tag) => tag.name).join(" | ")}
-
+
- {profileContactState?.contactEmails?.length > 0 && (
-
-
-
-
- Email
-
-
:
+ {contactProfile?.contactEmails?.length > 0 && (
+
+
-
- {profileContactState.contactEmails.map((email, idx) => (
+ {contactProfile.contactEmails.map((email, idx) => (
-
+
+
{email.emailAddress}
handleCopy(email.emailAddress, idx)}
@@ -125,22 +83,17 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
)}
- {profileContactState?.contactPhones?.length > 0 && (
-
-
-
-
- Phone
-
-
:
+ {contactProfile?.contactPhones?.length > 0 && (
+
+
-
- {profileContactState.contactPhones.map((phone, idx) => (
-
+ {contactProfile?.contactPhones.map((phone, idx) => (
+
+
{phone.phoneNumber}
- {idx < profileContactState.contactPhones.length - 1 && ","}
))}
@@ -148,93 +101,74 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
)}
- {profileContactState?.createdAt && (
-
-
-
-
- Created
-
-
:
+ {contactProfile?.createdAt && (
+
+
-
-
- {moment(profileContactState.createdAt).format("DD MMMM, YYYY")}
-
+
+
+ {moment(contactProfile.createdAt).format("MMMM, DD YYYY")}
+
)}
-
- {profileContactState?.address && (
-
-
-
-
- Location
-
-
:
+ {contactProfile?.address && (
+
+
-
-
{profileContactState.address}
+
+
+
+ {contactProfile.address}
+
)}
- {profileContactState?.organization && (
-
-
-
-
- Organization
-
-
:
+ {contactProfile?.organization && (
+
+
-
+
+
- {profileContactState.organization}
+ {contactProfile.organization}
)}
-
- {profileContactState?.contactCategory && (
-
-
-
-
- Category
-
-
:
+ {contactProfile?.contactCategory && (
+
+
-
- {profileContactState.contactCategory.name}
+
+ {contactProfile.contactCategory.name}
)}
-
- {profileContactState?.tags?.length > 0 && (
-
-
-
-
- Tags
-
-
:
+ {contactProfile?.tags?.length > 0 && (
+
+
-
- {profileContactState.tags.map((tag, index) => (
+ {contactProfile.tags.map((tag, index) => (
+
{tag.name}
))}
@@ -243,91 +177,75 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
)}
- {profileContactState?.buckets?.length > 0 && (
-
-
-
-
- Buckets
-
- :
-
-
-
-
- {profileContactState.buckets.map((bucket) => (
-
-
- {bucket.name}
-
-
- ))}
-
-
+ {contactProfile?.buckets?.length > 0 && (
+
+ {contactProfile?.contactEmails?.length > 0 && (
+
+
+
+
+ {contactProfile.buckets.map((bucket) => (
+
+
+ {bucket.name}
+
+
+ ))}
+
+
+
+ )}
)}
-
- {profileContactState?.projects?.length > 0 && (
-
-
-
-
- Projects
-
- :
-
-
-
-
- {profileContactState.projects.map((project, index) => (
-
- {project.name}
- {index < profileContactState.projects.length - 1 && ","}
-
- ))}
-
-
-
- )}
-
-
-
-
-
- Description
-
-
:
+ {contactProfile?.projects?.length > 0 && (
+
+
+
+
+ {contactProfile.projects.map((project, index) => (
+
+ {project.name}
+ {index < contactProfile.projects.length - 1 && ","}
+
+ ))}
+
+
+ )}
+
+
{displayText}
{isLong && (
- <>
-
-
- {expanded ? "Read less" : "Read more"}
-
- >
+
+ {expanded ? "Read less" : "Read more"}
+
)}
-
);
};
-export default ProfileContactDirectory;
\ No newline at end of file
+export default ProfileContactDirectory;
diff --git a/src/components/Directory/UpdateContact.jsx b/src/components/Directory/UpdateContact.jsx
index 9d74fc35..985229a3 100644
--- a/src/components/Directory/UpdateContact.jsx
+++ b/src/components/Directory/UpdateContact.jsx
@@ -14,11 +14,7 @@ import useMaster, {
} from "../../hooks/masterHook/useMaster";
import { useDispatch, useSelector } from "react-redux";
import { changeMaster } from "../../slices/localVariablesSlice";
-import {
- useBuckets,
- useDesignation,
- useOrganization,
-} from "../../hooks/useDirectory";
+import { useBuckets, useOrganization } from "../../hooks/useDirectory";
import { useProjects } from "../../hooks/useProjects";
import SelectMultiple from "../common/SelectMultiple";
import { ContactSchema } from "./DirectorySchema";
@@ -36,13 +32,10 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
const { contactCategory, loading: contactCategoryLoading } =
useContactCategory();
const { contactTags, loading: Tagloading } = useContactTags();
- const [IsSubmitting, setSubmitting] = useState(false);
+ const [ IsSubmitting, setSubmitting ] = useState( false );
const [isInitialized, setIsInitialized] = useState(false);
const dispatch = useDispatch();
- const { organizationList } = useOrganization();
- const { designationList } = useDesignation();
- const [showSuggestions, setShowSuggestions] = useState(false);
- const [filteredDesignationList, setFilteredDesignationList] = useState([]);
+ const {organizationList} = useOrganization()
const methods = useForm({
resolver: zodResolver(ContactSchema),
@@ -52,7 +45,6 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
contactCategoryId: null,
address: "",
description: "",
- designation: "",
projectIds: [],
contactEmails: [],
contactPhones: [],
@@ -103,24 +95,6 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
}
};
- // handle logic when input of desgination is changed
- const handleDesignationChange = (e) => {
- const val = e.target.value;
-
- const matches = designationList.filter((org) =>
- org.toLowerCase().includes(val.toLowerCase())
- );
- setFilteredDesignationList(matches);
- setShowSuggestions(true);
- setTimeout(() => setShowSuggestions(false), 5000);
- };
-
- // handle logic when designation is selected
- const handleSelectDesignation = (val) => {
- setShowSuggestions(false);
- setValue("designation", val);
- };
-
const watchBucketIds = watch("bucketIds");
const toggleBucketId = (id) => {
@@ -139,28 +113,33 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
};
const onSubmit = async (data) => {
- const cleaned = {
- ...data,
- contactEmails: (data.contactEmails || [])
- .filter((e) => e.emailAddress?.trim() !== "")
- .map((email, index) => {
- const existingEmail = existingContact.contactEmails?.[index];
- return existingEmail ? { ...email, id: existingEmail.id } : email;
- }),
- contactPhones: (data.contactPhones || [])
- .filter((p) => p.phoneNumber?.trim() !== "")
- .map((phone, index) => {
- const existingPhone = existingContact.contactPhones?.[index];
- return existingPhone ? { ...phone, id: existingPhone.id } : phone;
- }),
- };
+const cleaned = {
+ ...data,
+ contactEmails: (data.contactEmails || [])
+ .filter((e) => e.emailAddress?.trim() !== "")
+ .map((email, index) => {
+ const existingEmail = existingContact.contactEmails?.[index];
+ return existingEmail
+ ? { ...email, id: existingEmail.id }
+ : email;
+ }),
+ contactPhones: (data.contactPhones || [])
+ .filter((p) => p.phoneNumber?.trim() !== "")
+ .map((phone, index) => {
+ const existingPhone = existingContact.contactPhones?.[index];
+ return existingPhone
+ ? { ...phone, id: existingPhone.id }
+ : phone;
+ }),
+};
- setSubmitting(true);
- await submitContact({ ...cleaned, id: existingContact.id });
+setSubmitting(true);
+await submitContact({ ...cleaned, id: existingContact.id });
setSubmitting(false);
+
};
- const orgValue = watch("organization");
+ const orgValue = watch("organization")
const handleClosed = () => {
onCLosed();
};
@@ -170,7 +149,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
typeof existingContact === "object" &&
!Array.isArray(existingContact);
- if (!isInitialized && isValidContact && TagsData) {
+ if (!isInitialized &&isValidContact && TagsData) {
reset({
name: existingContact.name || "",
organization: existingContact.organization || "",
@@ -179,30 +158,24 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
contactCategoryId: existingContact.contactCategory?.id || null,
address: existingContact.address || "",
description: existingContact.description || "",
- designation: existingContact.designation || "",
projectIds: existingContact.projectIds || null,
tags: existingContact.tags || [],
bucketIds: existingContact.bucketIds || [],
- });
-
- if (
- !existingContact.contactPhones ||
- existingContact.contactPhones.length === 0
- ) {
- appendPhone({ label: "Office", phoneNumber: "" });
- }
-
- if (
- !existingContact.contactEmails ||
- existingContact.contactEmails.length === 0
- ) {
- appendEmail({ label: "Work", emailAddress: "" });
- }
- setIsInitialized(true);
+ } );
+
+ if (!existingContact.contactPhones || existingContact.contactPhones.length === 0) {
+ appendPhone({ label: "Office", phoneNumber: "" });
}
+ if (!existingContact.contactEmails || existingContact.contactEmails.length === 0) {
+ appendEmail({ label: "Work", emailAddress: "" });
+ }
+ setIsInitialized(true)
+ }
+
// return()=> reset()
- }, [existingContact, buckets, projects]);
+ }, [ existingContact, buckets, projects ] );
+
return (
@@ -222,14 +195,15 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
)}
+
Organization
setValue("organization", val)}
- error={errors.organization?.message}
- />
+ organizationList={organizationList}
+ value={getValues("organization") || ""}
+ onChange={(val) => setValue("organization", val)}
+ error={errors.organization?.message}
+ />
{errors.organization && (
{errors.organization.message}
@@ -237,55 +211,6 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
)}
-
-
-
Designation
-
- {showSuggestions && filteredDesignationList.length > 0 && (
-
- {filteredDesignationList.map((designation) => (
- handleSelectDesignation(designation)}
- onMouseEnter={(e) =>
- (e.currentTarget.style.backgroundColor = "#f8f9fa")
- }
- onMouseLeave={(e) =>
- (e.currentTarget.style.backgroundColor = "transparent")
- }
- >
- {designation}
-
- ))}
-
- )}
- {errors.designation && (
-
- {errors.designation.message}
-
- )}
-
-
{emailFields.map((field, index) => (
@@ -322,13 +247,11 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
//
-
+
+
) : (
// {
// onClick={() => removeEmail(index)}
// style={{ width: "24px", height: "24px" }}
// >
- removeEmail(index)}
- />
+ removeEmail(index)}/>
+
)}
{errors.contactEmails?.[index]?.emailAddress && (
@@ -389,10 +310,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
// onClick={handleAddPhone}
// style={{ width: "24px", height: "24px" }}
// >
-
+
) : (
//
{
// onClick={() => removePhone(index)}
// style={{ width: "24px", height: "24px" }}
// >
- removePhone(index)}
- />
+ removePhone(index)} />
)}
{errors.contactPhones?.[index]?.phoneNumber && (
@@ -433,7 +348,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
) : (
<>
-
+
Select Category
{contactCategory?.map((cate) => (
@@ -472,7 +387,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
)}
-
+
Select Label
@@ -530,11 +445,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
-
+
{IsSubmitting ? "Please Wait..." : "Update"}
-
Official Designation
+
Role
{
const navigate = useNavigate();
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
- const isDirectoryPath = /^\/directory$/.test(location.pathname);
- const isProjectPath = /^\/projects$/.test(location.pathname);
- const isDashboard =
- /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname);
-
- const allowedProjectStatusIds = [
- "603e994b-a27f-4e5d-a251-f3d69b0498ba",
- "cdad86aa-8a56-4ff4-b633-9c629057dfef",
- "b74da4c2-d07e-46f2-9919-e75e49b12731",
- ];
-
+ const isDirectoryPath = /^\/directory$/.test(location.pathname);
+ const isProjectPath = /^\/projects$/.test(location.pathname);
+ const isDashboard = /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname) ;
const getRole = (roles, joRoleId) => {
if (!Array.isArray(roles)) return "User";
let role = roles.find((role) => role.id === joRoleId);
@@ -46,7 +38,7 @@ const Header = () => {
};
const handleLogout = (e) => {
- e.preventDefault();
+ e.preventDefault();
logout();
};
@@ -57,7 +49,7 @@ const Header = () => {
};
AuthRepository.logout(data)
- .then(() => {
+ .then((response) => {
localStorage.removeItem("jwtToken");
localStorage.removeItem("refreshToken");
localStorage.removeItem("user");
@@ -65,11 +57,11 @@ const Header = () => {
clearAllCache();
window.location.href = "/auth/login";
})
- .catch(() => {
+ .catch((error) => {
+ // Even if logout API fails, clear local storage and redirect
localStorage.removeItem("jwtToken");
localStorage.removeItem("refreshToken");
localStorage.removeItem("user");
- localStorage.clear();
clearAllCache();
window.location.href = "/auth/login";
});
@@ -87,30 +79,22 @@ const Header = () => {
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
- const selectedProject = useSelectedproject();
+ const selectedProject = useSelector(
+ (store) => store.localVariables.projectId
+ );
- const projectsForDropdown = isDashboard
- ? projectNames
- : projectNames?.filter(project =>
- allowedProjectStatusIds.includes(project.projectStatusId)
- );
-
- let currentProjectDisplayName;
- if (projectLoading) {
- currentProjectDisplayName = "Loading...";
- } else if (!projectNames || projectNames.length === 0) {
- currentProjectDisplayName = "No Projects Assigned";
- } else if (projectNames.length === 1) {
- currentProjectDisplayName = projectNames[0].name;
- } else {
- if (selectedProject === null) {
- currentProjectDisplayName = "All Projects";
- } else {
- const selectedProjectObj = projectNames.find(
- (p) => p?.id === selectedProject
- );
- currentProjectDisplayName = selectedProjectObj ? selectedProjectObj.name : "All Projects";
- }
+ // Determine the display text for the project dropdown
+ let displayText = "All Projects";
+ if (selectedProject === null) {
+ displayText = "All Projects";
+ } else if (selectedProject) {
+ const selectedProjectObj = projectNames?.find(
+ (p) => p?.id === selectedProject
+ );
+ // Fallback to selectedProject ID if name not found during loading or mismatch
+ displayText = selectedProjectObj ? selectedProjectObj.name : selectedProject;
+ } else if (projectLoading) {
+ displayText = "Loading...";
}
const { openChangePassword } = useChangePassword();
@@ -122,18 +106,17 @@ const Header = () => {
selectedProject === undefined &&
!getCachedData("hasReceived")
) {
- if (projectNames.length === 1) {
- dispatch(setProjectId(projectNames[0]?.id || null));
- } else {
- if (isDashboard) {
- dispatch(setProjectId(null));
- } else {
- const firstAllowedProject = projectNames.find(project => allowedProjectStatusIds.includes(project.projectStatusId));
- dispatch(setProjectId(firstAllowedProject?.id || null));
- }
+ if(isDashboard){
+ dispatch(setProjectId(null));
+ }else{
+ dispatch(setProjectId(projectNames[0]?.id));
}
}
- }, [projectNames, selectedProject, dispatch, isDashboard]);
+ }, [projectNames, selectedProject, dispatch]);
+
+
+ /** Check if current page is project details page or directory page */
+ // const isProjectPath = /^\/projects\/[a-f0-9-]{36}$/.test(location.pathname);
const handler = useCallback(
@@ -177,15 +160,14 @@ const Header = () => {
};
}, [handler, newProjectHandler]);
- const handleProjectChange = (project) => {
- dispatch(setProjectId(project));
-
- if (isProjectPath && project !== null) {
- navigate("/projects/details");
+ const handleProjectChange =(project)=>{
+ if(isProjectPath){
+ dispatch(setProjectId(project))
+ navigate("/projects/details")
+ } else{
+ dispatch(setProjectId(project))
}
- };
-
- const shouldShowDropdown = projectNames && projectNames.length > 1;
+ }
return (
{