pramod_Task-#399 : Added Access Permission For 'Directory User' Role #160

Merged
pramod.mahajan merged 19 commits from pramod_Task-#399 into Feature_Directory 2025-05-29 17:49:56 +00:00
2 changed files with 83 additions and 51 deletions
Showing only changes of commit 25bd5550c6 - Show all commits

View File

@ -7,11 +7,12 @@ import showToast from "../../services/toastService";
import { cacheData, getCachedData } from "../../slices/apiDataManager"; import { cacheData, getCachedData } from "../../slices/apiDataManager";
import "../common/TextEditor/Editor.css"; import "../common/TextEditor/Editor.css";
const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact }) => { const NoteCardDirectory = ({refetchProfile,refetchNotes, noteItem, contactId, setProfileContact, }) => {
const [editing, setEditing] = useState(false); const [editing, setEditing] = useState(false);
const [editorValue, setEditorValue] = useState(noteItem.note); const [editorValue, setEditorValue] = useState(noteItem.note);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [isDeleting, setIsDeleting] = useState(false); const [ isDeleting, setIsDeleting ] = useState( false );
const [isActivProcess,setActiveProcessing]= useState(false)
const handleUpdateNote = async () => { const handleUpdateNote = async () => {
try { try {
setIsLoading(true); setIsLoading(true);
@ -63,10 +64,10 @@ const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact })
} }
}; };
const handleDeleteNote = async () => { const handleDeleteNote = async (activeStatue) => {
try { try {
setIsDeleting(true); activeStatue ? setActiveProcessing(true) : setIsDeleting(true)
const resp = await DirectoryRepository.DeleteNote(noteItem.id); const resp = await DirectoryRepository.DeleteNote(noteItem.id,activeStatue);
setProfileContact((prev) => ({ setProfileContact((prev) => ({
...prev, ...prev,
notes: prev.notes.filter((note) => note.id !== noteItem.id), notes: prev.notes.filter((note) => note.id !== noteItem.id),
@ -90,8 +91,11 @@ const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact })
cacheData("Contact Profile", updatedCache); cacheData("Contact Profile", updatedCache);
} }
setIsDeleting(false); setIsDeleting( false );
showToast("Note Deleted Successfully", "success"); setActiveProcessing( false )
refetchNotes( contactId, false )
refetchProfile(contactId)
showToast(`Note ${activeStatue ? "Restored":"Deleted"} Successfully`, "success");
} catch (error) { } catch (error) {
setIsDeleting(false); setIsDeleting(false);
const msg = const msg =
@ -101,13 +105,13 @@ const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact })
showToast(msg, "error"); showToast(msg, "error");
} }
}; };
return ( return (
<div <div
className="card p-1 shadow-sm border-1 mb-2 conntactNote" className="card p-1 shadow-sm border-1 mb-2 conntactNote"
style={{ width: "100%", minWidth: "300px", borderRadius: "0px", background: `${!IsActive ? "#f8f6f6" : ""}` }} style={{ width: "100%", minWidth: "300px", borderRadius: "0px", background: `${noteItem.isActive ? "": "#f8f6f6"}` }}
key={noteItem.id} key={noteItem.id}
> >
<div className="d-flex justify-content-between align-items-center mb-1"> <div className="d-flex justify-content-between align-items-center mb-1">
<div className="d-flex align-items-center"> <div className="d-flex align-items-center">
<Avatar <Avatar
@ -129,26 +133,39 @@ const NoteCardDirectory = ({ IsActive,noteItem, contactId, setProfileContact })
</span> </span>
</div> </div>
</div> </div>
<div className={`${IsActive ? " ":"d-none"}`}> <div>
<i {noteItem.isActive ? (
className="bx bxs-edit bx-sm me-1 text-primary cursor-pointer" <>
onClick={() => setEditing(true)} <i
></i> className="bx bxs-edit bx-sm me-1 text-primary cursor-pointer"
{!isDeleting && ( onClick={() => setEditing(true)}
<i ></i>
className="bx bx-trash bx-sm me-1 text-secondary cursor-pointer"
onClick={handleDeleteNote} {!isDeleting ? (
></i> <i
)} className="bx bx-trash bx-sm me-1 text-secondary cursor-pointer"
{isDeleting && ( onClick={() => handleDeleteNote(!noteItem.isActive)}
<div ></i>
class="spinner-border spinner-border-sm text-secondary" ) : (
role="status" <div
> className="spinner-border spinner-border-sm text-secondary"
<span class="visually-hidden">Loading...</span> role="status"
</div> >
)} <span className="visually-hidden">Loading...</span>
</div> </div>
)}
</>
) : isActivProcess ? (
< i className='bx bx-refresh text-primary bx-spin' ></i>
) : (
<i
className="bx bx-history me-1 text-primary cursor-pointer"
onClick={() => handleDeleteNote(!noteItem.isActive)}
title="Restore"
></i>
)}
</div>
</div> </div>
<hr className="mt-0" /> <hr className="mt-0" />

View File

@ -16,9 +16,9 @@ const schema = z.object({
note: z.string().min(1, { message: "Note is required" }), note: z.string().min(1, { message: "Note is required" }),
}); });
const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => { const NotesDirectory = ({refetchProfile, isLoading, contactProfile, setProfileContact }) => {
const [IsActive, setIsActive] = useState(true); const [IsActive, setIsActive] = useState(true);
const { contactNotes } = useContactNotes(contactProfile?.id, !IsActive); const {contactNotes,refetch} = useContactNotes( contactProfile?.id, true );
const [NotesData, setNotesData] = useState(); const [NotesData, setNotesData] = useState();
const [IsSubmitting, setIsSubmitting] = useState(false); const [IsSubmitting, setIsSubmitting] = useState(false);
@ -85,6 +85,14 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
const onCancel = () => { const onCancel = () => {
setValue("note", ""); setValue("note", "");
}; };
const handleSwitch = () =>
{
setIsActive( !IsActive )
if ( IsActive )
{
refetch(contactProfile?.id, false)
}
}
return ( return (
<div className="text-start"> <div className="text-start">
@ -95,7 +103,7 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
<input <input
type="checkbox" type="checkbox"
className="switch-input" className="switch-input"
onChange={() => setIsActive(!IsActive)} onChange={()=>handleSwitch(!IsActive)}
value={IsActive} value={IsActive}
/> />
<span className="switch-toggle-slider"> <span className="switch-toggle-slider">
@ -106,9 +114,13 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
{/* <i class="icon-base bx bx-x"></i> */} {/* <i class="icon-base bx bx-x"></i> */}
</span> </span>
</span> </span>
<span className="switch-label small-text">Show Inactive Notes</span> <span className="switch-label small-text">Show Including Inactive Notes</span>
</label> </label>
<span
</div>
</div>
<div className="d-flex justify-content-end px-2">
<span
className={`btn btn-xs ${addNote ? "btn-danger" : "btn-primary"}`} className={`btn btn-xs ${addNote ? "btn-danger" : "btn-primary"}`}
onClick={() => setAddNote(!addNote)} onClick={() => setAddNote(!addNote)}
> >
@ -119,7 +131,6 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
></i> */} ></i> */}
{addNote ? "close" : "Add Note"} {addNote ? "close" : "Add Note"}
</span> </span>
</div>
</div> </div>
{addNote && ( {addNote && (
<form onSubmit={handleSubmit(onSubmit)}> <form onSubmit={handleSubmit(onSubmit)}>
@ -143,30 +154,34 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
</div> </div>
)} )}
{!isLoading && {!isLoading &&
[...(IsActive ? contactProfile?.notes || [] : contactNotes || [])] [...(IsActive ? contactProfile?.notes || [] : contactNotes || [])]
.reverse() .reverse()
.map((noteItem) => ( .map((noteItem) => (
<NoteCardDirectory <NoteCardDirectory
IsActive={IsActive} refetchProfile={refetchProfile}
noteItem={noteItem} refetchNotes={refetch}
contactId={contactProfile?.id} refetchContact ={refetch}
setProfileContact={setProfileContact} noteItem={noteItem}
key={noteItem.id} contactId={contactProfile?.id}
/> setProfileContact={setProfileContact}
))} key={noteItem.id}
/>
))}
{IsActive && ( {IsActive && (
<p> <div>
{!isLoading && contactProfile?.notes.length == 0 && !addNote && ( {!isLoading && contactProfile?.notes.length == 0 && !addNote && (
<p className="text-center">No Notes Found</p> <div className="text-center">No Notes Found</div>
)} )}
</p> </div>
)} )}
{!IsActive && ( {!IsActive && (
<p> <div>
{!isLoading && contactNotes.length == 0 && !addNote && ( {!isLoading && contactNotes.length == 0 && !addNote && (
<p className="text-center">No Notes Found</p> <div className="text-center">No Notes Found</div>
)} )}
</p> </div>
)} )}
</div> </div>
</div> </div>