Merge branch 'Issues_Nov_4W' of https://git.marcoaiot.com/admin/marco.pms.web into Finance_Export_Functionality

This commit is contained in:
Kartik Sharma 2025-11-27 10:40:45 +05:30
commit 359a787bdb
6 changed files with 39 additions and 26 deletions

View File

@ -20,14 +20,21 @@ import { SpinnerLoader } from "../common/Loader";
const usePagination = (data, itemsPerPage) => {
const [currentPage, setCurrentPage] = useState(1);
const maxPage = Math.ceil(data.length / itemsPerPage);
// const maxPage = Math.ceil(data.length / itemsPerPage);
const maxPage = Math.max(1, Math.ceil(data.length / itemsPerPage));
const currentItems = useMemo(() => {
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
return data.slice(startIndex, endIndex);
}, [data, currentPage, itemsPerPage]);
const paginate = useCallback((pageNumber) => setCurrentPage(pageNumber), []);
// const paginate = useCallback((pageNumber) => setCurrentPage(pageNumber), []);
const paginate = useCallback((pageNumber) => {
// keep page within 1..maxPage
const p = Math.max(1, Math.min(pageNumber, maxPage));
setCurrentPage(p);
}, [maxPage]);
const resetPage = useCallback(() => setCurrentPage(1), []);
return {
@ -36,6 +43,7 @@ const usePagination = (data, itemsPerPage) => {
currentItems,
paginate,
resetPage,
setCurrentPage,
};
};
@ -125,9 +133,16 @@ const AttendanceLog = ({ handleModalData, searchTerm, organizationId }) => {
resetPage,
} = usePagination(filteredSearchData, 20);
// useEffect(() => {
// resetPage();
// }, [filteredSearchData]);
useEffect(() => {
resetPage();
}, [filteredSearchData]);
if (currentPage > totalPages) {
paginate(totalPages || 1);
}
// NOTE: do NOT force reset to page 1 here keep the same page if still valid
}, [filteredSearchData, totalPages, currentPage, paginate]);
const handler = useCallback(
(msg) => {
@ -144,10 +159,9 @@ const AttendanceLog = ({ handleModalData, searchTerm, organizationId }) => {
record.id === msg.response.id ? { ...record, ...msg.response } : record
);
});
resetPage();
}
},
[selectedProject, dateRange, resetPage]
[selectedProject, dateRange]
);
useEffect(() => {

View File

@ -9,6 +9,7 @@ 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,
@ -22,14 +23,14 @@ const NoteCardDirectoryEditable = ({
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 { setContactOpen } = useDirectoryContext();
const handleUpdateNote = async () => {
const payload = {
@ -45,12 +46,6 @@ const NoteCardDirectoryEditable = ({
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 {
@ -88,7 +83,9 @@ const NoteCardDirectoryEditable = ({
<div>
<div
className="d-flex ms-3 align-middle cursor-pointer"
onClick={() => contactProfile(noteItem.contactId)}
onClick={() =>
setContactOpen({ contact: { id: noteItem.contactId }, Open: true })
}
>
<span>
<span className="fw-bold "> {noteItem?.contactName} </span>{" "}
@ -97,6 +94,7 @@ const NoteCardDirectoryEditable = ({
</span>
</span>
</div>
<div className="d-flex ms-0 align-middle"></div>
<div className="d-flex ms-3 mt-2">
<span className="text-muted">

View File

@ -140,6 +140,7 @@ const ManageJob = ({ Job }) => {
formData.projectId = projectId;
CreateJob(formData);
setManageJob({ isOpen: false, jobId: null });
}
};

View File

@ -63,7 +63,7 @@ const OrganizationInfo = ({ onNext, onPrev, onSubmitTenant }) => {
setLogoPreview(logoImage);
setLogoName("Uploaded Logo");
}
}, [getValues]);
}, [getValues]);
return (
@ -134,7 +134,7 @@ const OrganizationInfo = ({ onNext, onPrev, onSubmitTenant }) => {
control={control}
placeholder="DD-MM-YYYY"
maxDate={new Date()}
className={errors.onBoardingDate ? "is-invalid" : ""}
className={`w-100 ${errors.onBoardingDate ? "is-invalid" : ""}`}
/>
{errors.onBoardingDate && (
<div className="invalid-feedback">

View File

@ -109,7 +109,7 @@ const ServiceGroups = ({ service }) => {
/>
</span>
)}
<p className="m-0 fw-bold ">{group.name}</p>
<p className="m-0 ">{group.name}</p>
</div>
<div className="d-flex flex-row gap-3">
<div className="d-flex flex-row gap-2">

View File

@ -132,7 +132,7 @@ export const useAddSubscription = (onSuccessCallback) => {
onSuccess: (data, variables) => {
const { tenantId } = variables;
showToast("Tenant Plan Added SuccessFully", "success");
queryClient.invalidateQueries({ queryKey: ["Tenant", tenantId] });
queryClient.invalidateQueries({ queryKey: ["Tenants", tenantId] });
if (onSuccessCallback) onSuccessCallback();
},
onError: (error) => {