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"; import { useDirectoryContext } from "../../pages/Directory/DirectoryPage"; 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 { mutate: UpdateNote, isPending: isUpatingNote } = useUpdateNote(() => setEditing(false) ); const { mutate: ActiveInactive, isPending: isUpdatingStatus } = useActiveInActiveNote(() => setIsDeleteModalOpen(false)); const { setContactOpen } = useDirectoryContext(); 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 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 ( <>