Card changes to show days left for project

This commit is contained in:
Vikas Nale 2025-04-09 14:44:57 +05:30
parent 19abc42fc6
commit 29caa20250
5 changed files with 287 additions and 283 deletions

6
package-lock.json generated
View File

@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"@hookform/resolvers": "^3.10.0", "@hookform/resolvers": "^3.10.0",
"@reduxjs/toolkit": "^2.5.0", "@reduxjs/toolkit": "^2.5.0",
"@types/web": "^0.0.216",
"@vitejs/plugin-react": "^4.3.4", "@vitejs/plugin-react": "^4.3.4",
"axios": "^1.7.9", "axios": "^1.7.9",
"axios-retry": "^4.5.0", "axios-retry": "^4.5.0",
@ -1439,6 +1440,11 @@
"resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz", "resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz",
"integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==" "integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg=="
}, },
"node_modules/@types/web": {
"version": "0.0.216",
"resolved": "https://registry.npmjs.org/@types/web/-/web-0.0.216.tgz",
"integrity": "sha512-HLaPWQKq1oh6aQv1JLRsiH0vW4VsO+L/zTOeOUmoGBnLVR2wCj4w4oWfa/0O5JFMqZXWC6VpipqQU6B1v2M/qg=="
},
"node_modules/@ungap/structured-clone": { "node_modules/@ungap/structured-clone": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.1.tgz", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.1.tgz",

View File

@ -3,7 +3,6 @@
"private": true, "private": true,
"version": "0.0.0", "version": "0.0.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"json-server": "json-server --watch ./src/data/demo.json --port 5000", "json-server": "json-server --watch ./src/data/demo.json --port 5000",
@ -14,6 +13,7 @@
"dependencies": { "dependencies": {
"@hookform/resolvers": "^3.10.0", "@hookform/resolvers": "^3.10.0",
"@reduxjs/toolkit": "^2.5.0", "@reduxjs/toolkit": "^2.5.0",
"@types/web": "^0.0.216",
"@vitejs/plugin-react": "^4.3.4", "@vitejs/plugin-react": "^4.3.4",
"axios": "^1.7.9", "axios": "^1.7.9",
"axios-retry": "^4.5.0", "axios-retry": "^4.5.0",

View File

@ -2,279 +2,283 @@ import React, { useState } from "react";
import moment from "moment"; import moment from "moment";
import { getDateDifferenceInDays } from "../../utils/dateUtils"; import { getDateDifferenceInDays } from "../../utils/dateUtils";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import {useProjectDetails} from "../../hooks/useProjects"; import { useProjectDetails } from "../../hooks/useProjects";
import ManageProjectInfo from "./ManageProjectInfo"; import ManageProjectInfo from "./ManageProjectInfo";
import ProjectRepository from "../../repositories/ProjectRepository"; import ProjectRepository from "../../repositories/ProjectRepository";
import {cacheData, getCachedData} from "../../slices/apiDataManager"; import { cacheData, getCachedData } from "../../slices/apiDataManager";
import showToast from "../../services/toastService"; import showToast from "../../services/toastService";
import {useHasUserPermission} from "../../hooks/useHasUserPermission"; import { useHasUserPermission } from "../../hooks/useHasUserPermission";
import {MANAGE_PROJECT} from "../../utils/constants"; import { MANAGE_PROJECT } from "../../utils/constants";
const ProjectCard = ({ projectData }) => { const ProjectCard = ({ projectData }) => {
const [projectInfo, setProjectInfo] = useState(projectData); const [projectInfo, setProjectInfo] = useState(projectData);
const [projectDetails, setProjectDetails] = useState(null); const [projectDetails, setProjectDetails] = useState(null);
const [showModal, setShowModal] = useState(false); const [showModal, setShowModal] = useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
const ManageProject = useHasUserPermission(MANAGE_PROJECT); const ManageProject = useHasUserPermission(MANAGE_PROJECT);
const handleShow = async () => { const handleShow = async () => {
try { try {
const response = await ProjectRepository.getProjectByprojectId(projectInfo.id); const response = await ProjectRepository.getProjectByprojectId(projectInfo.id);
setProjectDetails(response.data); setProjectDetails(response.data);
setShowModal(true); setShowModal(true);
} catch (error) { } catch (error) {
showToast("Failed to load project details", "error"); showToast("Failed to load project details", "error");
} }
}; };
const getProgress = (planned, completed) => { const getProgress = (planned, completed) => {
return (completed * 100) / planned + "%"; return (completed * 100) / planned + "%";
}; };
const getProgressInNumber = (planned, completed) => { const getProgressInNumber = (planned, completed) => {
return (completed * 100) / planned ; return (completed * 100) / planned;
}; };
const handleClose = () => setShowModal( false ); const handleClose = () => setShowModal(false);
const getProjectStatusName = (statusId) => {
switch (statusId) {
case 1:
return "Active";
case 2:
return "On Hold";
// case 3:
// return "Suspended";
case 3:
return "Inactive";
case 4:
return "Completed";
}
};
const getProjectStatusColor = (statusId) => { const getProjectStatusName = (statusId) => {
switch (statusId) { switch (statusId) {
case 1: case 1:
return "bg-label-success"; return "Active";
case 2: case 2:
return "bg-label-warning"; return "On Hold";
case 3: // case 3:
return "bg-label-info"; // return "Suspended";
case 4: case 3:
return "bg-label-secondary"; return "Inactive";
case 5: case 4:
return "bg-label-dark"; return "Completed";
} }
}; };
const handleViewProject = () => { const getProjectStatusColor = (statusId) => {
navigate(`/projects/${projectData.id}`); switch (statusId) {
}; case 1:
return "bg-label-success";
case 2:
return "bg-label-warning";
case 3:
return "bg-label-info";
case 4:
return "bg-label-secondary";
case 5:
return "bg-label-dark";
}
};
const handleViewProject = () => {
navigate(`/projects/${projectData.id}`);
};
const handleFormSubmit = (updatedProject) => { const handleFormSubmit = (updatedProject) => {
if (projectInfo?.id) { if (projectInfo?.id) {
ProjectRepository.updateProject(projectInfo.id, updatedProject) ProjectRepository.updateProject(projectInfo.id, updatedProject)
.then((response) => { .then((response) => {
const updatedProjectData = { const updatedProjectData = {
...projectInfo, ...projectInfo,
...response.data, ...response.data,
building: projectDetails?.building, building: projectDetails?.building,
}; };
setProjectInfo(updatedProject); setProjectInfo(updatedProject);
if (getCachedData(`projectinfo-${projectInfo.id}`)) { if (getCachedData(`projectinfo-${projectInfo.id}`)) {
cacheData(`projectinfo-${projectInfo.id}`, updatedProjectData); cacheData(`projectinfo-${projectInfo.id}`, updatedProjectData);
} }
const projects_list = getCachedData("projectslist"); const projects_list = getCachedData("projectslist");
if (projects_list) { if (projects_list) {
const updatedProjectsList = projects_list.map((project) => const updatedProjectsList = projects_list.map((project) =>
project.id === projectInfo.id project.id === projectInfo.id
? { ...project, ...response.data, tenant: project.tenant } ? { ...project, ...response.data, tenant: project.tenant }
: project : project
); );
cacheData("projectslist", updatedProjectsList); cacheData("projectslist", updatedProjectsList);
} }
showToast("Project updated successfully.", "success"); showToast("Project updated successfully.", "success");
setShowModal(false); setShowModal(false);
}) })
.catch((error) => { .catch((error) => {
showToast(error.message, "error"); showToast(error.message, "error");
}); });
} }
}; };
return ( return (
<> <>
{showModal && projectDetails && ( {showModal && projectDetails && (
<div <div
className="modal fade show" className="modal fade show"
tabIndex="-1" tabIndex="-1"
role="dialog" role="dialog"
style={{ display: "block" }} style={{ display: "block" }}
aria-hidden="false" aria-hidden="false"
> >
<ManageProjectInfo <ManageProjectInfo
project={projectDetails} project={projectDetails}
handleSubmitForm={handleFormSubmit} handleSubmitForm={handleFormSubmit}
onClose={handleClose} onClose={handleClose}
/> />
</div>
)}
<div className="col-md-6 col-lg-4 col-xl-4 order-0 mb-4">
<div className="card cursor-pointer">
<div className="card-header pb-4">
<div className="d-flex align-items-start">
<div className="d-flex align-items-center">
<div className="avatar me-4">
<i
className="rounded-circle bx bx-building-house"
style={{ fontSize: "xx-large" }}
></i>
</div> </div>
<div className="me-2"> )}
<h5 className="mb-0">
<a
className="stretched-link text-heading"
onClick={handleViewProject}
>
{projectInfo.name}
</a>
</h5>
<div className="client-info text-body">
<span className="fw-medium">Client: </span>
<span>{projectInfo.contactPerson}</span>
</div>
</div>
</div>
<div className={`ms-auto ${!ManageProject && "d-none"}`}>
<div className="dropdown z-2">
<button
type="button"
className="btn btn-icon btn-text-secondary rounded-pill dropdown-toggle hide-arrow p-0"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i className="bx bx-dots-vertical-rounded bx-sm text-muted"></i>
</button>
<ul className="dropdown-menu dropdown-menu-end">
<li>
<a
aria-label="click to View details"
className="dropdown-item"
onClick={handleViewProject}
>
<i className="bx bx-detail me-2"></i>
<span className="align-left">View details</span>
</a>
</li>
<li onClick={handleShow}>
<a className="dropdown-item">
<i className="bx bx-pencil me-2"></i>
<span className="align-left">Modify</span>
</a>
</li>
<li>
<a className="dropdown-item">
<i className="bx bx-task me-2"></i>
<span className="align-left">Activities</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div className="card-body pb-1">
<div className="d-flex align-items-center flex-wrap">
<div className="text-start mb-4">
<p className="mb-1">
<span className="text-heading fw-medium">Start Date: </span>
{projectInfo.startDate
? moment(projectInfo.startDate).format("DD-MMM-YYYY")
: "NA"}
</p>
<p className="mb-1">
<span className="text-heading fw-medium">Deadline: </span>
{projectInfo.endDate <div className="col-md-6 col-lg-4 col-xl-4 order-0 mb-4">
? moment(projectInfo.endDate).format("DD-MMM-YYYY") <div className="card cursor-pointer">
: "NA"} <div className="card-header pb-4">
</p> <div className="d-flex align-items-start">
<p className="mb-0">{projectInfo.projectAddress}</p> <div className="d-flex align-items-center">
<div className="avatar me-4">
<i
className="rounded-circle bx bx-building-house"
style={{ fontSize: "xx-large" }}
></i>
</div>
<div className="me-2">
<h5 className="mb-0">
<a
className="stretched-link text-heading"
onClick={handleViewProject}
>
{projectInfo.name}
</a>
</h5>
<div className="client-info text-body">
<span className="fw-medium">Client: </span>
<span>{projectInfo.contactPerson}</span>
</div>
</div>
</div>
<div className={`ms-auto ${!ManageProject && "d-none"}`}>
<div className="dropdown z-2">
<button
type="button"
className="btn btn-icon btn-text-secondary rounded-pill dropdown-toggle hide-arrow p-0"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i className="bx bx-dots-vertical-rounded bx-sm text-muted"></i>
</button>
<ul className="dropdown-menu dropdown-menu-end">
<li>
<a
aria-label="click to View details"
className="dropdown-item"
onClick={handleViewProject}
>
<i className="bx bx-detail me-2"></i>
<span className="align-left">View details</span>
</a>
</li>
</div> <li onClick={handleShow}>
<a className="dropdown-item">
</div> <i className="bx bx-pencil me-2"></i>
</div> <span className="align-left">Modify</span>
<div className="card-body border-top"> </a>
<div className="d-flex align-items-center mb-4"> </li>
<p className="mb-0"> <li>
<span <a className="dropdown-item">
className={ <i className="bx bx-task me-2"></i>
`badge rounded-pill ` + <span className="align-left">Activities</span>
getProjectStatusColor(projectInfo.projectStatusId) </a>
} </li>
> </ul>
{getProjectStatusName(projectInfo.projectStatusId)} </div>
</span> </div>
</p>{" "} </div>
<span className="badge bg-label-success ms-auto"> </div>
{projectInfo.startDate && <div className="card-body pb-1">
projectInfo.endDate && <div className="d-flex align-items-center flex-wrap">
getDateDifferenceInDays( <div className="text-start mb-4">
projectInfo.startDate, <p className="mb-1">
projectInfo.endDate <span className="text-heading fw-medium">Start Date: </span>
)}{" "} {projectInfo.startDate
Days left ? moment(projectInfo.startDate).format("DD-MMM-YYYY")
</span> : "NA"}
</div> </p>
<div className="d-flex justify-content-between align-items-center mb-2"> <p className="mb-1">
<small className="text-body">Task: {projectInfo.completedWork} / { projectInfo.plannedWork}</small> <span className="text-heading fw-medium">Deadline: </span>
<small className="text-body">{Math.floor(getProgressInNumber(projectInfo.plannedWork,projectInfo.completedWork)) || 0} % Completed</small>
</div> {projectInfo.endDate
<div className="progress mb-4 rounded" style={{ height: "8px" }}> ? moment(projectInfo.endDate).format("DD-MMM-YYYY")
<div : "NA"}
className="progress-bar rounded" </p>
role="progressbar" <p className="mb-0">{projectInfo.projectAddress}</p>
style={{ width: getProgress(projectInfo.plannedWork,projectInfo.completedWork) }}
aria-valuenow={projectInfo.completedWork} </div>
aria-valuemin="0"
aria-valuemax={projectInfo.plannedWork} </div>
></div> </div>
</div> <div className="card-body border-top">
<div className="d-flex align-items-center justify-content-between"> <div className="d-flex align-items-center mb-4">
{/* <div className="d-flex align-items-center "> <p className="mb-0">
<span
className={
`badge rounded-pill ` +
getProjectStatusColor(projectInfo.projectStatusId)
}
>
{getProjectStatusName(projectInfo.projectStatusId)}
</span>
</p>{" "}
{getDateDifferenceInDays(projectInfo.endDate, Date()) >= 0 &&
( <span className="badge bg-label-success ms-auto">
{projectInfo.endDate &&
getDateDifferenceInDays(projectInfo.endDate, Date())}{" "}
Days left
</span>) }
{getDateDifferenceInDays(projectInfo.endDate, Date()) < 0 &&
( <span className="badge bg-label-danger ms-auto">
{projectInfo.endDate &&
getDateDifferenceInDays(projectInfo.endDate, Date())}{" "}
Days overdue
</span>)}
</div>
<div className="d-flex justify-content-between align-items-center mb-2">
<small className="text-body">Task: {projectInfo.completedWork} / {projectInfo.plannedWork}</small>
<small className="text-body">{Math.floor(getProgressInNumber(projectInfo.plannedWork, projectInfo.completedWork)) || 0} % Completed</small>
</div>
<div className="progress mb-4 rounded" style={{ height: "8px" }}>
<div
className="progress-bar rounded"
role="progressbar"
style={{ width: getProgress(projectInfo.plannedWork, projectInfo.completedWork) }}
aria-valuenow={projectInfo.completedWork}
aria-valuemin="0"
aria-valuemax={projectInfo.plannedWork}
></div>
</div>
<div className="d-flex align-items-center justify-content-between">
{/* <div className="d-flex align-items-center ">
</div> */} </div> */}
<div > <div >
<a <a
className="text-muted d-flex " className="text-muted d-flex " alt="Active team size"
> >
<i className="bx bx-group bx-sm me-1_5"></i>{projectInfo?.teamSize} <i className="bx bx-group bx-sm me-1_5"></i>{projectInfo?.teamSize} Members
</a> </a>
</div> </div>
<div > <div >
<a <a
className="text-muted d-flex align-items-center" className="text-muted d-flex align-items-center"
> >
<i className="bx bx-chat me-1"></i> 15 <i className="bx bx-chat me-1 "></i> <span className="text-decoration-line-through">15</span>
</a> </a>
</div>
</div>
</div>
</div>
</div> </div>
</div> </>
</div> );
</div>
</div>
</>
);
}; };
export default ProjectCard; export default ProjectCard;

View File

@ -13,56 +13,50 @@ export const getDateDifferenceInDays = (startDate, endDate) => {
} }
// Calculate the difference in milliseconds // Calculate the difference in milliseconds
const differenceInMs = end - start; const differenceInMs = start - end;
// Convert milliseconds to days // Convert milliseconds to days
const differenceInDays = Math.floor(differenceInMs / (1000 * 60 * 60 * 24)); const differenceInDays = Math.floor(differenceInMs / (1000 * 60 * 60 * 24));
return differenceInDays; return differenceInDays;
}; };
export const formatDate = (date) => { export const formatDate = (date) => {
if (!date) return ''; // Return an empty string if no date if (!date) return ""; // Return an empty string if no date
const dateObj = new Date(date); const dateObj = new Date(date);
return dateObj.toISOString().split('T')[0]; // Get the date in YYYY-MM-DD format return dateObj.toISOString().split("T")[0]; // Get the date in YYYY-MM-DD format
}; };
export const convertShortTime = (dateString) => {
export const convertShortTime=(dateString)=> {
const date = new Date(dateString); const date = new Date(dateString);
let hours = date.getHours(); let hours = date.getHours();
const minutes = String(date.getMinutes()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, "0");
const ampm = hours >= 12 ? 'PM' : 'AM'; const ampm = hours >= 12 ? "PM" : "AM";
hours = hours % 12; // Convert to 12-hour format hours = hours % 12; // Convert to 12-hour format
hours = hours ? hours : 12; // If hours is 0, set it to 12 hours = hours ? hours : 12; // If hours is 0, set it to 12
return `${String(hours).padStart(2, '0')}:${minutes} ${ampm}`; return `${String(hours).padStart(2, "0")}:${minutes} ${ampm}`;
} };
export const timeElapsed = (checkInTime, timeElapsedInHours) =>{ export const timeElapsed = (checkInTime, timeElapsedInHours) => {
const checkInDate = new Date(checkInTime); const checkInDate = new Date(checkInTime);
const currentTime = new Date(); const currentTime = new Date();
const timeDifference = currentTime - checkInDate;
const timeDifferenceInHours = timeDifference / (1000 * 60 * 60);
return timeDifferenceInHours >= timeElapsedInHours;
}
const timeDifference = currentTime - checkInDate;
const timeDifferenceInHours = timeDifference / (1000 * 60 * 60);
export const checkIfCurrentDate = (dateString) => { return timeDifferenceInHours >= timeElapsedInHours;
const currentDate = new Date(); };
const inputDate = new Date(dateString);
export const checkIfCurrentDate = (dateString) => {
const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0); const inputDate = new Date(dateString);
inputDate.setHours(0, 0, 0, 0);
currentDate.setHours(0, 0, 0, 0);
return currentDate.getTime() === inputDate.getTime(); inputDate.setHours(0, 0, 0, 0);
};
return currentDate.getTime() === inputDate.getTime();
};

View File

@ -13,7 +13,7 @@ export default defineConfig({
define: { define: {
'process.env': { 'process.env': {
VITE_BASE_URL: process.env.VITE_BASE_URL || 'http://localhost:5032', VITE_BASE_URL: process.env.VITE_BASE_URL || 'http://localhost:5032',
}, },
}, },
plugins: [react()], plugins: [react()],