Compare commits

..

No commits in common. "ad0be799435b4c92a9ce6281c985a1a9cceba896" and "83ec0ec5ddca97cbc8fbefa326d8bc9d40208a4c" have entirely different histories.

6 changed files with 230 additions and 320 deletions

View File

@ -4,109 +4,43 @@ import moment from "moment";
import Avatar from "../common/Avatar"; import Avatar from "../common/Avatar";
import { DirectoryRepository } from "../../repositories/DirectoryRepository"; import { DirectoryRepository } from "../../repositories/DirectoryRepository";
import showToast from "../../services/toastService"; import showToast from "../../services/toastService";
import { cacheData, getCachedData } from "../../slices/apiDataManager"; import {getCachedData} from "../../slices/apiDataManager";
import "../common/TextEditor/Editor.css"; import "../common/TextEditor/Editor.css"
const NoteCardDirectory = ({ noteItem, contactId, setProfileContact }) => { const NoteCardDirectory = ({ 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 handleUpdateNote= async () => {
const handleUpdateNote = async () => { try
try { {
setIsLoading(true); console.log(editorValue)
const payload = { setIsLoading(true)
id: noteItem.id, const payload ={id:noteItem.id,note:editorValue,contactId:contactId}
note: editorValue,
contactId: contactId, const response = await DirectoryRepository.UpdateNote(noteItem.id, payload);
}; setProfileContact((prev) => ({
...prev,
notes: prev.notes.map((note) =>
note.id === noteItem.id ? response?.data : note
),
const response = await DirectoryRepository.UpdateNote( }));
noteItem.id, setEditing( false );
payload setIsLoading(false)
); showToast("Note Updated successfully", "success")
setProfileContact((prev) => ({ } catch ( error )
...prev, {
notes: prev.notes.map((note) => setIsLoading(false)
note.id === noteItem.id ? response?.data : note const msg = error.reponse.data.message || error.message || "Error occured during API calling."
), showToast("Failed to update note", "error");
}));
const cached_contactProfile = getCachedData("Contact Profile");
if (
cached_contactProfile &&
cached_contactProfile.contactId === contactId
) {
const updatedProfile = {
...cached_contactProfile,
data: {
...cached_contactProfile?.data,
notes: cached_contactProfile?.data?.notes.map((note) =>
note.id === noteItem.id ? response?.data : note
),
},
};
cacheData("Contact Profile", updatedProfile);
}
setEditing(false);
setIsLoading(false);
showToast("Note Updated successfully", "success");
} catch (error) {
setIsLoading(false);
const msg =
error.reponse.data.message ||
error.message ||
"Error occured during API calling.";
showToast("Failed to update note", "error");
} }
}; };
const handleDeleteNote = async () => {
try {
setIsDeleting(true);
const resp = await DirectoryRepository.DeleteNote(noteItem.id);
setProfileContact((prev) => ({
...prev,
notes: prev.notes.filter((note) => note.id !== noteItem.id),
}));
const cachedContactProfile = getCachedData("Contact Profile");
if (
cachedContactProfile &&
cachedContactProfile.contactId === contactId
) {
const updatedCache = {
...cachedContactProfile,
data: {
...cachedContactProfile?.data,
notes: (cachedContactProfile?.data?.notes || []).filter(
(note) => note.id !== noteItem.id
),
},
};
cacheData("Contact Profile", updatedCache);
}
setIsDeleting(false);
showToast("Note Deleted Successfully", "success");
} catch (error) {
setIsDeleting(false);
const msg =
error.response?.data?.message ||
error.message ||
"Error occured during API calling";
showToast(msg, "error");
}
};
return ( return (
<div <div className="card p-1 shadow-sm border-1 mb-2" style={{ width: "fit-content", minWidth: "300px", borderRadius:"0px" }} key={noteItem.id} >
className="card p-1 shadow-sm border-1 mb-2 conntactNote"
style={{ width: "100%", minWidth: "300px", borderRadius: "0px" }}
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
@ -124,25 +58,38 @@ const NoteCardDirectory = ({ noteItem, contactId, setProfileContact }) => {
</span> </span>
</div> </div>
</div> </div>
<div>
<div className="dropdown">
<i <i
className="bx bxs-edit bx-sm me-1 text-primary cursor-pointer" className="bx bx-dots-vertical bx-xs cursor-pointer"
onClick={() => setEditing(true)} role="button"
id={`dropdownMenuIcon-${noteItem.id}`}
data-bs-toggle="dropdown"
aria-expanded="false"
></i> ></i>
{!isDeleting && (
<i <ul
className="bx bx-trash bx-sm me-1 text-secondary cursor-pointer" className="dropdown-menu dropdown-menu-end p-1"
onClick={handleDeleteNote} aria-labelledby={`dropdownMenuIcon-${noteItem.id}`}
></i> style={{ minWidth: "120px", fontSize: "0.85rem" }}
)} >
{isDeleting && ( <li>
<div <button
class="spinner-border spinner-border-sm text-secondary" className="dropdown-item py-1 px-2 small text-primary"
role="status" onClick={() => setEditing(true)}
> >
<span class="visually-hidden">Loading...</span> <i className="bx bxs-edit bx-sm me-1"></i> Edit
</div> </button>
)} </li>
<li>
<button
className="dropdown-item py-1 px-2 text-danger small"
onClick={()=>{}}
>
<i className="bx bx-trash bx-sm me-1"></i> Delete
</button>
</li>
</ul>
</div> </div>
</div> </div>
@ -155,21 +102,14 @@ const NoteCardDirectory = ({ noteItem, contactId, setProfileContact }) => {
onChange={setEditorValue} onChange={setEditorValue}
theme="snow" theme="snow"
className="compact-editor" className="compact-editor"
/> />
<div className="d-flex justify-content-end gap-2"> <div className="d-flex justify-content-end gap-2">
<span <span className="text-secondary cursor-pointer" aria-disabled={isLoading} onClick={() => setEditing(false)}>
className="text-secondary cursor-pointer"
aria-disabled={isLoading}
onClick={() => setEditing(false)}
>
Cancel Cancel
</span> </span>
<span <span className="text-primary cursor-pointer" aria-disabled={isLoading} onClick={handleUpdateNote}>
className="text-primary cursor-pointer" {isLoading ? "Please Wait...":"Submit"}
aria-disabled={isLoading}
onClick={handleUpdateNote}
>
{isLoading ? "Please Wait..." : "Submit"}
</span> </span>
</div> </div>
</> </>

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react"; import React, {useEffect, useState} from "react";
import Editor from "../common/TextEditor/Editor"; import Editor from "../common/TextEditor/Editor";
import Avatar from "../common/Avatar"; import Avatar from "../common/Avatar";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
@ -7,7 +7,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { showText } from "pdf-lib"; import { showText } from "pdf-lib";
import { DirectoryRepository } from "../../repositories/DirectoryRepository"; import { DirectoryRepository } from "../../repositories/DirectoryRepository";
import moment from "moment"; import moment from "moment";
import { cacheData, getCachedData } from "../../slices/apiDataManager"; import {getCachedData} from "../../slices/apiDataManager";
import NoteCardDirectory from "./NoteCardDirectory"; import NoteCardDirectory from "./NoteCardDirectory";
import showToast from "../../services/toastService"; import showToast from "../../services/toastService";
@ -15,10 +15,10 @@ 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 = ( {isLoading,contactProfile, setProfileContact} ) =>
const [NotesData, setNotesData] = useState(); {
const [IsSubmitting, setIsSubmitting] = useState(false); const [ NotesData, setNotesData ] = useState()
const [addNote, setAddNote] = useState(false); const[IsSubmitting,setIsSubmitting] = useState(false)
const { const {
register, register,
handleSubmit, handleSubmit,
@ -40,35 +40,27 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
const onSubmit = async (data) => { const onSubmit = async (data) => {
const newNote = { ...data, contactId: contactProfile?.id }; const newNote = { ...data, contactId: contactProfile?.id };
try { try
setIsSubmitting(true); {
const response = await DirectoryRepository.CreateNote(newNote); setIsSubmitting(true)
const response = await DirectoryRepository.CreateNote( newNote );
const createdNote = response.data; const createdNote = response.data;
setProfileContact((prev) => ({ setProfileContact((prev) => ({
...prev, ...prev,
notes: [...(prev.notes || []), createdNote], notes: [...(prev.notes || []), createdNote],
})); }));
const cached_contactProfile = getCachedData("Contact Profile");
if (
cached_contactProfile &&
cached_contactProfile.contactId === contactProfile?.id
) {
const updatedProfile = {
...cached_contactProfile.data,
notes: [...(cached_contactProfile.notes || []), createdNote],
};
cacheData("Contact Profile", updatedProfile);
}
setValue("note", ""); setValue("note", "");
setIsSubmitting(false); const result = response.data
showToast("Note added successfully!", "success"); const cache_notes = getCachedData( "Contact Note" )
setAddNote(false);
} catch (error) { setIsSubmitting(false)
setIsSubmitting(false); showToast("Note added successfully!", "success")
} catch ( error )
{
setIsSubmitting(false)
const msg = const msg =
error.response.data.message || error.response.data.message ||
error.message || error.message ||
@ -83,63 +75,26 @@ const NotesDirectory = ({ isLoading, contactProfile, setProfileContact }) => {
return ( return (
<div className="text-start"> <div className="text-start">
<div <form onSubmit={handleSubmit(onSubmit)}>
className={`${ <Editor
contactProfile?.notes?.length > 0 value={noteValue}
? "d-flex justify-content-between" loading={IsSubmitting}
: "d-flex justify-content-end" onChange={handleEditorChange}
}`} onCancel={onCancel}
> onSubmit={handleSubmit(onSubmit)}
{contactProfile?.notes.length > 0 && ( />
<p className="fw-semibold m-0">Notes :</p> {errors.notes && (
<p className="text-danger small mt-1">{errors.note.message}</p>
)} )}
<a </form>
className="small-text m-0 cursor-pointer"
onClick={() => setAddNote(!addNote)}
>
<u>
{addNote ? "" : "Add Note"}
<i
className={`bx ${addNote ? "bx-x" : "bx-pencil"} bx-xs`}
></i>{" "}
</u>{" "}
</a>
</div>
{addNote && (
<form onSubmit={handleSubmit(onSubmit)}>
<Editor
value={noteValue}
loading={IsSubmitting}
onChange={handleEditorChange}
onCancel={onCancel}
onSubmit={handleSubmit(onSubmit)}
/>
{errors.notes && (
<p className="text-danger small mt-1">{errors.note.message}</p>
)}
</form>
)}
<div <div
className=" justify-content-start overflow-auto px-1" className=" justify-content-start overflow-auto px-1"
style={{ maxHeight: "300px" }} style={{ maxHeight: "300px", minHeight: "100px" }}
> >
{isLoading && ( {isLoading && <div className="text-center"> <p>Loading...</p> </div>}
<div className="text-center"> {!isLoading && contactProfile?.notes?.map((noteItem) => (
{" "} <NoteCardDirectory noteItem={noteItem} contactId={contactProfile?.id} setProfileContact={setProfileContact} key={noteItem.id} />
<p>Loading...</p>{" "} ))}
</div>
)}
{!isLoading &&
[...(contactProfile?.notes || [])]
.reverse()
.map((noteItem) => (
<NoteCardDirectory
noteItem={noteItem}
contactId={contactProfile?.id}
setProfileContact={setProfileContact}
key={noteItem.id}
/>
))}
</div> </div>
</div> </div>
); );

View File

@ -5,7 +5,7 @@ import moment from "moment";
import NotesDirectory from "./NotesDirectory"; import NotesDirectory from "./NotesDirectory";
const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => { const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
const { conatProfile, loading } = useContactProfile(contact?.id); const { conatProfile ,loading} = useContactProfile(contact?.id);
const [activeTab, setActiveTab] = useState("profile"); const [activeTab, setActiveTab] = useState("profile");
const [profileContact, setProfileContact] = useState(); const [profileContact, setProfileContact] = useState();
@ -14,7 +14,7 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
}, [conatProfile]); }, [conatProfile]);
return ( return (
<div className="p-1"> <div className="p-1">
<div className="text-center m-0 p-0"> <div className="text-center m-0 p-0">
<p className="fw-semibold fs-6 m-0">Contact Profile</p> <p className="fw-semibold fs-6 m-0">Contact Profile</p>
</div> </div>
<div> <div>
@ -36,65 +36,106 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
</span> </span>
</div> </div>
</div> </div>
<div className="d-flex flex-column text-start">
{conatProfile?.contactEmails?.length > 0 && (
<div className="d-flex mb-2">
<div style={{ width: "100px", minWidth: "100px" }}>
<p className="m-0">Email</p>
</div>
<div>
<ul className="list-inline mb-0">
{conatProfile.contactEmails.map((email, idx) => (
<li className="list-inline-item me-3" key={idx}>
<i className="bx bx-envelope bx-xs me-1"></i>
{email.emailAddress}
</li>
))}
</ul>
</div>
</div>
)}
{conatProfile?.contactPhones?.length > 0 && (
<div className="d-flex mb-2">
<div style={{ width: "100px", minWidth: "100px" }}>
<p className="m-0">Phone</p>
</div>
<div>
<ul className="list-inline mb-0">
{conatProfile.contactPhones.map((phone, idx) => (
<li className="list-inline-item me-3" key={idx}>
<i className="bx bx-phone bx-xs me-1"></i>
{phone.phoneNumber}
</li>
))}
</ul>
</div>
</div>
)}
{conatProfile?.createdAt && ( <hr className="my-1" />
<div className="d-flex mb-2">
<div style={{ width: "100px", minWidth: "100px" }}> {/* Tabs */}
<p className="m-0">Created</p>
</div> {loading && <div className="text-center"> <p>Loading...</p> </div>}
<div> {!loading && (
<ul className="list-inline mb-0"> <ul className="nav nav-tabs mb-1 p0">
<li className="list-inline-item"> <li className="nav-item">
<i className="bx bx-calendar-week bx-xs me-1"></i> <button
{moment(conatProfile.createdAt).format("MMMM, DD YYYY")} className={`nav-link p-1 me-2 ${
</li> activeTab === "profile" ? "active" : ""
</ul> }`}
onClick={() => setActiveTab("profile")}
>
Profile
</button>
</li>
<li className="nav-item ">
<button
className={`nav-link text-start p-1 ${
activeTab === "notes" ? "active" : ""
}`}
onClick={() => setActiveTab("notes")}
>
Notes<i className="bx bx-pencil bx-xs"></i>
</button>
</li>
</ul>
)}
{/* Tab Content */}
<div>
{activeTab === "notes" && (
<NotesDirectory
isLoading={loading}
contactProfile={profileContact}
setProfileContact={setProfileContact}
/>
)}
{activeTab === "profile" && (
<div>
<div className="d-flex flex-column text-start">
{conatProfile?.contactEmails?.length > 0 && (
<div className="d-flex mb-2">
<div style={{ width: "100px", minWidth: "100px" }}>
<p className="m-0">Email</p>
</div>
<div>
<ul className="list-inline mb-0">
{conatProfile.contactEmails.map((email, idx) => (
<li className="list-inline-item me-3" key={idx}>
<i className="bx bx-envelope bx-xs me-1"></i>
{email.emailAddress}
</li>
))}
</ul>
</div>
</div>
)}
{conatProfile?.contactPhones?.length > 0 && (
<div className="d-flex mb-2">
<div style={{ width: "100px", minWidth: "100px" }}>
<p className="m-0">Phone</p>
</div>
<div>
<ul className="list-inline mb-0">
{conatProfile.contactPhones.map((phone, idx) => (
<li className="list-inline-item me-3" key={idx}>
<i className="bx bx-phone bx-xs me-1"></i>
{phone.phoneNumber}
</li>
))}
</ul>
</div>
</div>
)}
{conatProfile?.createdAt && (
<div className="d-flex mb-2">
<div style={{ width: "100px", minWidth: "100px" }}>
<p className="m-0">Created</p>
</div>
<div>
<ul className="list-inline mb-0">
<li className="list-inline-item">
<i className="bx bx-calendar-week bx-xs me-1"></i>
{moment(conatProfile.createdAt).format(
"MMMM, DD YYYY"
)}
</li>
</ul>
</div>
</div>
)}
</div> </div>
</div> </div>
)} )}
</div> </div>
<hr className="my-1" />
<NotesDirectory
isLoading={loading}
contactProfile={profileContact}
setProfileContact={setProfileContact}
/>
</div> </div>
</div> </div>
); );

View File

@ -1,6 +1,6 @@
.editor-wrapper { .editor-wrapper {
max-width: 800px; max-width: 800px;
margin: 1px auto; margin: 20px auto;
background: #fff; background: #fff;
overflow: hidden; overflow: hidden;
@ -69,64 +69,40 @@
cursor: pointer; cursor: pointer;
display: inline-block; display: inline-block;
float: left; float: left;
font-size: 15px; height: 24px;
padding: 2px 2px; padding: 2px 2px;
width: 28px; width: 28px;
} }
.ql-toolbar.ql-snow{
padding: 4px;
}
@media (max-width: 768px) { @media (max-width: 768px) {
.ql-toolbar.ql-snow .ql-formats { .ql-toolbar.ql-snow .ql-formats {
margin-right: 1px; margin-right: 1px;
align-items: center;
} }
} }
/* for small editor */
.ql-snow.ql-toolbar button, /* Editor height and text */
.ql-snow .ql-toolbar button { .compact-editor .ql-editor {
background: none; min-height: 80px; /* Reduce editor height */
border: none; font-size: 0.85rem; /* Smaller font */
cursor: pointer; padding: 6px 10px;
display: inline-block;
height: 18px;
padding: 2px 2px;
width: 22px;
font-size: 14px;
/* REMOVE THIS to fix side-alignment */
/* float: left; */
vertical-align: middle;
} }
.ql-snow .ql-picker-label { /* Toolbar size */
font-size: 10px; /* Smaller text */ .compact-editor .ql-toolbar {
padding: 0 6px; /* Horizontal padding */ padding: 5px 8px;
height: 20px; /* Height of the label */ font-size: 0.85rem;
line-height: 20px; /* Match height to vertically center single-line text */
background-color: #eee;
border-radius: 0px;
cursor: pointer;
color: #333;
text-align: center;
width: 100%;
display: flex; /* Enable flexbox */
align-items: center; /* Vertical centering */
justify-content: center; /* Horizontal centering */
} }
/* Optional: smaller buttons & spacing */
/* Remove custom upward-opening styles */ .compact-editor .ql-toolbar button {
.ql-toolbar .ql-picker.ql-header .ql-picker-options { height: 24px;
top: 100%; /* Position it below the label */ width: 24px;
bottom: auto; /* Cancel the upward positioning */ padding: 2px;
margin-top: 5px; /* Optional spacing */ }
.compact-editor .ql-toolbar .ql-formats {
margin-right: 6px;
} }
.ql-editor {
padding: 4px 15px;
}

View File

@ -34,7 +34,16 @@ const Editor = ({
return ( return (
<div className="editor-wrapper"> <div className="editor-wrapper">
<div id="custom-toolbar" className="ql-toolbar ql-snow custom-toolbar"> <ReactQuill
value={value}
onChange={onChange}
modules={modules}
formats={formats}
theme="snow"
placeholder={placeholder}
/>
<div id="custom-toolbar" className="ql-toolbar ql-snow custom-toolbar">
<div className="d-flex justify-content-between align-items-center w-100"> <div className="d-flex justify-content-between align-items-center w-100">
{/* Left: Quill Format Buttons */} {/* Left: Quill Format Buttons */}
<span className="d-flex"> <span className="d-flex">
@ -61,19 +70,8 @@ const Editor = ({
</span> </span>
</span> </span>
{/* Right: Submit + Cancel Buttons */}
</div> <div className="d-flex gap-2">
</div>
<ReactQuill
value={value}
onChange={onChange}
modules={modules}
formats={formats}
theme="snow"
placeholder={placeholder}
/>
{/* Right: Submit + Cancel Buttons */}
<div className="d-flex justify-content-end gap-2 p-1">
<span className="btn btn-xs btn-secondary" aria-disabled={loading} onClick={onCancel}> <span className="btn btn-xs btn-secondary" aria-disabled={loading} onClick={onCancel}>
Cancel Cancel
</span> </span>
@ -86,7 +84,8 @@ const Editor = ({
{loading ? "Please Wait..." : "Submit"} {loading ? "Please Wait..." : "Submit"}
</span> </span>
</div> </div>
</div>
</div>
</div> </div>
); );
}; };

View File

@ -11,6 +11,5 @@ export const DirectoryRepository = {
CreateNote: ( data ) => api.post( '/api/directory/note', data ), CreateNote: ( data ) => api.post( '/api/directory/note', data ),
GetNote: ( id ) => api.get( `/api/directory/note/${ id }` ), GetNote: ( id ) => api.get( `/api/directory/note/${ id }` ),
UpdateNote: ( id, data ) => api.put( `/api/directory/note/${ id }`, data ), UpdateNote:(id,data)=>api.put(`/api/directory/note/${id }`,data )
DeleteNote:(id)=> api.delete(`/api/directory/note/${ id }`)
} }