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 ( <>