Compare commits

..

No commits in common. "c1a8b87a2c9db5d31fcde7c1c56707d8fce1d13f" and "ef005162566cec89b42df8ffda34eb4ecacbbc39" have entirely different histories.

9 changed files with 75 additions and 128 deletions

View File

@ -6,12 +6,7 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { queryClient } from "./layouts/AuthLayout"; import { queryClient } from "./layouts/AuthLayout";
import ModalProvider from "./ModalProvider"; import ModalProvider from "./ModalProvider";
window.addEventListener("unhandledrejection", (event) => {
if (event.reason?.message?.includes("Failed to fetch")) {
event.preventDefault();
console.debug("Network issue (fetch failed) - suppressed");
}
});
const App = () => { const App = () => {
return ( return (

View File

@ -1,14 +1,15 @@
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { useOrganizationModal } from "./hooks/useOrganization"; import { useOrganizationModal } from "./hooks/useOrganization";
import OrganizationModal from "./components/Organization/OrganizationModal"; import OrganizationModal from "./components/Organization/OrganizationModal";
import { useAuthModal, useModal } from "./hooks/useAuth"; import { useAuthModal } from "./hooks/useAuth";
import SwitchTenant from "./pages/authentication/SwitchTenant"; import SwitchTenant from "./pages/authentication/SwitchTenant";
import { useProjectModal } from "./hooks/useProjects";
import { ProjectModal } from "./components/Project/ManageProjectInfo"; import { ProjectModal } from "./components/Project/ManageProjectInfo";
const ModalProvider = () => { const ModalProvider = () => {
const { isOpen, onClose } = useOrganizationModal(); const { isOpen, onClose } = useOrganizationModal();
const { isOpen: isAuthOpen } = useAuthModal(); const { isOpen: isAuthOpen } = useAuthModal();
const {isOpen:isOpenProject} = useModal("ManageProject") const {isOpen:isOpenProject} = useProjectModal()
return ( return (
<> <>

View File

@ -22,19 +22,9 @@ const Regularization = ({ handleRequest, searchTerm, projectId, organizationId,
const { regularizes, loading, error, refetch } = const { regularizes, loading, error, refetch } =
useRegularizationRequests(selectedProject, organizationId, IncludeInActive); useRegularizationRequests(selectedProject, organizationId, IncludeInActive);
useEffect(() => { useEffect(() => {
if (regularizes && regularizes.length) { setregularizedList(regularizes);
setregularizedList((prev) => { }, [regularizes]);
const prevIds = prev.map((i) => i.id).join(",");
const newIds = regularizes.map((i) => i.id).join(",");
if (prevIds !== newIds) {
return regularizes;
}
return prev;
});
}
}, [regularizes]);
const sortByName = (a, b) => { const sortByName = (a, b) => {
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase(); const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();

View File

@ -8,6 +8,7 @@ import DatePicker from "../common/DatePicker";
import { import {
useCreateProject, useCreateProject,
useProjectDetails, useProjectDetails,
useProjectModal,
useUpdateProject, useUpdateProject,
} from "../../hooks/useProjects"; } from "../../hooks/useProjects";
@ -22,7 +23,6 @@ import {
} from "../../hooks/useOrganization"; } from "../../hooks/useOrganization";
import { localToUtc } from "../../utils/appUtils"; import { localToUtc } from "../../utils/appUtils";
import Modal from "../common/Modal"; import Modal from "../common/Modal";
import { useModal } from "../../hooks/useAuth";
const currentDate = new Date().toLocaleDateString("en-CA"); const currentDate = new Date().toLocaleDateString("en-CA");
const formatDate = (date) => { const formatDate = (date) => {
@ -38,7 +38,7 @@ const formatDate = (date) => {
const ManageProjectInfo = ({ project, onClose }) => { const ManageProjectInfo = ({ project, onClose }) => {
const [addressLength, setAddressLength] = useState(0); const [addressLength, setAddressLength] = useState(0);
const maxAddressLength = 500; const maxAddressLength = 500;
const { onOpen, startStep, flowType } = useModal("ManageProject"); const { onOpen, startStep, flowType } = useOrganizationModal();
const ACTIVE_STATUS_ID = "b74da4c2-d07e-46f2-9919-e75e49b12731"; const ACTIVE_STATUS_ID = "b74da4c2-d07e-46f2-9919-e75e49b12731";

View File

@ -1,7 +1,5 @@
import React, { useEffect, useRef } from "react"; import React, { useEffect, useRef } from "react";
import { useController, useFormContext, useWatch } from "react-hook-form"; import { useController, useFormContext, useWatch } from "react-hook-form";
import { useSelector } from "react-redux";
const DateRangePicker = ({ const DateRangePicker = ({
md, md,
sm, sm,
@ -11,29 +9,19 @@ const DateRangePicker = ({
}) => { }) => {
const inputRef = useRef(null); const inputRef = useRef(null);
const persistedRange = useSelector(
(store) => store.localVariables.attendance.defaultDateRange
);
useEffect(() => { useEffect(() => {
let startDate, endDate; const endDate = new Date();
if (endDateMode === "yesterday") {
if (persistedRange?.startDate && persistedRange?.endDate) { endDate.setDate(endDate.getDate() - 1);
startDate = new Date(persistedRange.startDate);
endDate = new Date(persistedRange.endDate);
} else {
endDate = new Date();
if (endDateMode === "yesterday") {
endDate.setDate(endDate.getDate() - 1);
}
endDate.setHours(0, 0, 0, 0);
startDate = new Date(endDate);
startDate.setDate(endDate.getDate() - (DateDifference - 1));
startDate.setHours(0, 0, 0, 0);
} }
const fp = flatpickr(inputRef.current, { endDate.setHours(0, 0, 0, 0);
const startDate = new Date(endDate);
startDate.setDate(endDate.getDate() - (DateDifference - 1));
startDate.setHours(0, 0, 0, 0);
const fp = flatpickr(inputRef.current, {
mode: "range", mode: "range",
dateFormat: "Y-m-d", dateFormat: "Y-m-d",
altInput: true, altInput: true,
@ -53,12 +41,14 @@ const DateRangePicker = ({
endDate: endDate.toLocaleDateString("en-CA"), endDate: endDate.toLocaleDateString("en-CA"),
}); });
return () => fp.destroy(); return () => {
}, [onRangeChange, DateDifference, endDateMode, persistedRange]); fp.destroy();
};
}, [onRangeChange, DateDifference, endDateMode]);
const handleIconClick = () => { const handleIconClick = () => {
if (inputRef.current?._flatpickr) { if (inputRef.current) {
inputRef.current._flatpickr.open(); inputRef.current._flatpickr.open(); // directly opens flatpickr
} }
}; };
@ -73,10 +63,9 @@ const DateRangePicker = ({
/> />
<i <i
className="bx bx-calendar calendar-icon cursor-pointer position-relative top-50 translate-middle-y" className="bx bx-calendar calendar-icon cursor-pointer position-relative top-50 translate-middle-y " onClick={handleIconClick}
onClick={handleIconClick}
style={{ right: "22px", bottom: "-8px" }} style={{ right: "22px", bottom: "-8px" }}
/> ></i>
</div> </div>
); );
}; };
@ -87,7 +76,6 @@ export default DateRangePicker;
export const DateRangePicker1 = ({ export const DateRangePicker1 = ({
startField = "startDate", startField = "startDate",
endField = "endDate", endField = "endDate",
@ -97,6 +85,7 @@ export const DateRangePicker1 = ({
resetSignal, resetSignal,
defaultRange = true, defaultRange = true,
maxDate = null, maxDate = null,
sm,md,
...rest ...rest
}) => { }) => {
const inputRef = useRef(null); const inputRef = useRef(null);
@ -180,11 +169,12 @@ export const DateRangePicker1 = ({
const formattedValue = start && end ? `${start} To ${end}` : ""; const formattedValue = start && end ? `${start} To ${end}` : "";
return ( return (
<div className={`position-relative ${className}`}> <div className={`col-${sm} col-sm-${md} px-1 position-relative`}>
<input <input
type="text" type="text"
className="form-control form-control-sm" className="form-control form-control-sm ps-2 pe-5 me-4 cursor-pointer"
placeholder={placeholder} placeholder="From to End"
id="flatpickr-range"
defaultValue={formattedValue} defaultValue={formattedValue}
ref={(el) => { ref={(el) => {
inputRef.current = el; inputRef.current = el;
@ -193,12 +183,10 @@ export const DateRangePicker1 = ({
readOnly={!allowText} readOnly={!allowText}
autoComplete="off" autoComplete="off"
/> />
<span <i
className="position-absolute top-50 end-0 pe-1 translate-middle-y cursor-pointer" className="bx bx-calendar calendar-icon cursor-pointer position-absolute top-50 end-0 translate-middle-y me-2"
onClick={() => inputRef.current?._flatpickr?.open()} onClick={() => inputRef.current?._flatpickr?.open()}
> ></i>
<i className="bx bx-calendar bx-sm fs-5 text-muted"></i>
</span>
</div> </div>
); );
}; };

View File

@ -14,23 +14,6 @@ import {
} from "../slices/localVariablesSlice.jsx"; } from "../slices/localVariablesSlice.jsx";
import { removeSession } from "../utils/authUtils.js"; import { removeSession } from "../utils/authUtils.js";
// ----------------------------Modal--------------------------
export const useModal = (modalType) => {
const dispatch = useDispatch();
const isOpen = useSelector(
(state) => state.localVariables.modals[modalType]?.isOpen
);
const onOpen = (data = {}) => dispatch(openModal({ modalType, data }));
const onClose = () => dispatch(closeModal({ modalType }));
const onToggle = () => dispatch(toggleModal({ modalType }));
return { isOpen, onOpen, onClose, onToggle };
};
export const useTenants = () => { export const useTenants = () => {
return useQuery({ return useQuery({
queryKey: ["tenantlist"], queryKey: ["tenantlist"],

View File

@ -3,7 +3,7 @@ import { cacheData, getCachedData } from "../slices/apiDataManager";
import ProjectRepository from "../repositories/ProjectRepository"; import ProjectRepository from "../repositories/ProjectRepository";
import { useProfile } from "./useProfile"; import { useProfile } from "./useProfile";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { setProjectId } from "../slices/localVariablesSlice"; import { closeProjectModal, openProjectModal, setProjectId } from "../slices/localVariablesSlice";
import EmployeeList from "../components/Directory/EmployeeList"; import EmployeeList from "../components/Directory/EmployeeList";
import eventBus from "../services/eventBus"; import eventBus from "../services/eventBus";
import { import {
@ -12,25 +12,23 @@ import {
useQuery, useQuery,
useQueryClient, useQueryClient,
} from "@tanstack/react-query"; } from "@tanstack/react-query";
import showToast from "../services/toastService"; import showToast from "../services/toastService";
export const useCurrentService = () => { export const useCurrentService = () => {
return useSelector((store) => store.globalVariables.selectedServiceId); return useSelector((store) => store.globalVariables.selectedServiceId);
}; };
// export const useProjectModal = () => { export const useProjectModal = () => {
// const dispatch = useDispatch(); const dispatch = useDispatch();
// const { isOpen, data } = useSelector((state) => state.localVariables.ProjectModal); const { isOpen, data } = useSelector((state) => state.localVariables.ProjectModal);
// return { return {
// isOpen, isOpen,
// data, data,
// openModal: (payload = null) => dispatch(openProjectModal(payload)), openModal: (payload = null) => dispatch(openProjectModal(payload)),
// closeModal: () => dispatch(closeProjectModal()), closeModal: () => dispatch(closeProjectModal()),
// }; };
// }; };
// ------------------------------Query------------------- // ------------------------------Query-------------------

View File

@ -70,8 +70,7 @@ const AttendancePage = () => {
}; };
const handleModalData = (employee) => { const handleModalData = (employee) => {
setModelConfig(employee); setModelConfig(employee);
if (employee !== null) setIsCreateModalOpen(true);
}; };
const closeModal = () => { const closeModal = () => {
@ -79,7 +78,11 @@ const AttendancePage = () => {
setIsCreateModalOpen(false); setIsCreateModalOpen(false);
}; };
useEffect(() => {
if (modelConfig !== null) {
openModel();
}
}, [modelConfig, isCreateModalOpen]);
// Handler to change tab and reset search term // Handler to change tab and reset search term
const handleTabChange = (tabName) => { const handleTabChange = (tabName) => {

View File

@ -4,18 +4,10 @@ const localVariablesSlice = createSlice({
name: "localVariables", name: "localVariables",
initialState: { initialState: {
selectedMaster: "Application Role", selectedMaster: "Application Role",
// Attendances regularizationCount: 0,
attendance: { defaultDateRange: {
regularizationCount: 0, startDate: null,
defaultDateRange: { startDate: null, endDate: null }, endDate: null,
SelectedOrg: "",
},
// Modal for all simple pass Name
modals: {
auth: { isOpen: false },
organization: { isOpen: false },
}, },
projectId: null, projectId: null,
reload: false, reload: false,
@ -27,6 +19,10 @@ const localVariablesSlice = createSlice({
startStep: 1, startStep: 1,
flowType: "default", flowType: "default",
}, },
ProjectModal:{
isOpen: false,
data: null,
},
AuthModal: { AuthModal: {
isOpen: false, isOpen: false,
@ -36,18 +32,9 @@ const localVariablesSlice = createSlice({
changeMaster: (state, action) => { changeMaster: (state, action) => {
state.selectedMaster = action.payload; state.selectedMaster = action.payload;
}, },
// ATTENDANCE
updateRegularizationCount: (state, action) => { updateRegularizationCount: (state, action) => {
state.attendance.regularizationCount = action.payload; state.regularizationCount = action.payload;
}, },
setDefaultDateRange: (state, action) => {
state.attendance.defaultDateRange = action.payload;
},
setOrganization: (state, action) => {
state.attendance.SelectedOrg = action.payload;
},
setProjectId: (state, action) => { setProjectId: (state, action) => {
localStorage.setItem("project", null); localStorage.setItem("project", null);
state.projectId = action.payload; state.projectId = action.payload;
@ -56,6 +43,10 @@ const localVariablesSlice = createSlice({
refreshData: (state, action) => { refreshData: (state, action) => {
state.reload = action.payload; state.reload = action.payload;
}, },
setDefaultDateRange: (state, action) => {
state.defaultDateRange = action.payload;
},
openOrgModal: (state, action) => { openOrgModal: (state, action) => {
state.OrganizationModal.isOpen = true; state.OrganizationModal.isOpen = true;
state.OrganizationModal.orgData = action.payload?.orgData || null; state.OrganizationModal.orgData = action.payload?.orgData || null;
@ -84,17 +75,15 @@ const localVariablesSlice = createSlice({
state.AuthModal.isOpen = false; state.AuthModal.isOpen = false;
}, },
openModal: (state, action) => {
const { modalType, data } = action.payload; // project modal
state.modals[modalType] = { isOpen: true, ...data }; openProjectModal: (state, action) => {
state.ProjectModal.isOpen = true;
state.ProjectModal.data = action.payload || null;
}, },
closeModal: (state, action) => { closeProjectModal: (state) => {
const { modalType } = action.payload; state.ProjectModal.isOpen = false;
state.modals[modalType] = { ...state.modals[modalType], isOpen: false }; state.ProjectModal.data = null;
},
toggleModal: (state, action) => {
const { modalType } = action.payload;
state.modals[modalType].isOpen = !state.modals[modalType].isOpen;
}, },
}, },
}); });
@ -110,6 +99,6 @@ export const {
toggleOrgModal, toggleOrgModal,
openAuthModal, openAuthModal,
closeAuthModal, closeAuthModal,
setOrganization,openModal, closeModal, toggleModal openProjectModal, closeProjectModal
} = localVariablesSlice.actions; } = localVariablesSlice.actions;
export default localVariablesSlice.reducer; export default localVariablesSlice.reducer;