import React, { useState } from "react"; import ReactQuill from "react-quill"; import moment from "moment"; import Avatar from "../common/Avatar"; import { DirectoryRepository } from "../../repositories/DirectoryRepository"; import showToast from "../../services/toastService"; import { cacheData, getCachedData } from "../../slices/apiDataManager"; import ConfirmModal from "../common/ConfirmModal"; // Make sure path is correct import "../common/TextEditor/Editor.css"; import GlobalModel from "../common/GlobalModel"; import { useActiveInActiveNote, useUpdateNote } from "../../hooks/useDirectory"; const NoteCardDirectoryEditable = ({ noteItem, contactId, onNoteUpdate, onNoteDelete, }) => { const [editing, setEditing] = useState(false); const [editorValue, setEditorValue] = useState(noteItem.note); const [isLoading, setIsLoading] = useState(false); const [isDeleting, setIsDeleting] = useState(false); const [isRestoring, setIsRestoring] = useState(false); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [open_contact, setOpen_contact] = useState(null); const [isOpenModalNote, setIsOpenModalNote] = useState(false); const { mutate: UpdateNote, isPending: isUpatingNote } = useUpdateNote(() => setEditing(false) ); const { mutate: ActiveInactive, isPending: isUpdatingStatus } = useActiveInActiveNote(() => setIsDeleteModalOpen(false)); const handleUpdateNote = async () => { const payload = { id: noteItem.id, note: editorValue, contactId, }; UpdateNote({ noteId: noteItem.id, notePayload: payload }); }; const ActiveInActive = (noteItem) => { ActiveInactive({ noteId: noteItem.id, noteStatus: !noteItem.isActive }); }; const contactProfile = (contactId) => { DirectoryRepository.GetContactProfile(contactId).then((res) => { setOpen_contact(res?.data); setIsOpenModalNote(true); }); }; const handleRestore = async () => { try { setIsRestoring(true); await DirectoryRepository.DeleteNote(noteItem.id, true); onNoteDelete?.(noteItem.id); showToast("Note restored successfully", "success"); } catch (error) { showToast("Failed to restore note", "error"); } finally { setIsRestoring(false); } }; return ( <>
{/* Header */}
contactProfile(noteItem.contactId)} > {noteItem?.contactName} {" "} ({noteItem?.organizationName})
by{" "} {" "} {noteItem?.createdBy?.firstName}{" "} {noteItem?.createdBy?.lastName}{" "}  {" "} on{" "} {moment .utc(noteItem?.createdAt) .add(5, "hours") .add(30, "minutes") .format("DD MMMM, YYYY [at] hh:mm A")}
{/* Action Icons */}
{noteItem.isActive ? ( <> setEditing(true)} title="Edit" > {!isDeleting ? ( setIsDeleteModalOpen(true)} title="Delete" > ) : (
)} ) : isUpdatingStatus ? ( ) : ( ActiveInActive(noteItem)} title="Restore" > )}

{/* Editor or Content */} {editing ? ( <>
) : (
)}
setIsDeleteModalOpen(false)} loading={isUpdatingStatus} paramData={noteItem} isOpen={isDeleteModalOpen} /> ); }; export default NoteCardDirectoryEditable;