fixed run time date error
This commit is contained in:
parent
68335f0695
commit
550b142d74
@ -41,7 +41,7 @@ const ProjectCard = ({ project }) => {
|
|||||||
dispatch(setProjectId(project.id));
|
dispatch(setProjectId(project.id));
|
||||||
navigate(`/activities/records?project=${project.id}`);
|
navigate(`/activities/records?project=${project.id}`);
|
||||||
};
|
};
|
||||||
|
console.log(project)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="col-md-6 col-lg-4 col-xl-4 order-0 mb-4">
|
<div className="col-md-6 col-lg-4 col-xl-4 order-0 mb-4">
|
||||||
@ -63,7 +63,7 @@ const ProjectCard = ({ project }) => {
|
|||||||
{project?.shortName ? project?.shortName : project?.name}
|
{project?.shortName ? project?.shortName : project?.name}
|
||||||
</h5>
|
</h5>
|
||||||
<div className="client-info text-body">
|
<div className="client-info text-body">
|
||||||
<span>{project.shortName ? project.name : ""}</span>
|
<span>{project?.shortName ? project?.name : ""}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -125,22 +125,22 @@ const ProjectCard = ({ project }) => {
|
|||||||
<span className="text-heading fw-medium">
|
<span className="text-heading fw-medium">
|
||||||
Contact Person:{" "}
|
Contact Person:{" "}
|
||||||
</span>
|
</span>
|
||||||
{project.contactPerson ? project.contactPerson : "NA"}
|
{project?.contactPerson ? project.contactPerson : "NA"}
|
||||||
</p>
|
</p>
|
||||||
<p className="mb-1">
|
<p className="mb-1">
|
||||||
<span className="text-heading fw-medium">Start Date: </span>
|
<span className="text-heading fw-medium">Start Date: </span>
|
||||||
{project.startDate
|
{project.startDate
|
||||||
? moment(project.startDate).format("DD-MMM-YYYY")
|
? moment(project?.startDate).format("DD-MMM-YYYY")
|
||||||
: "NA"}
|
: "NA"}
|
||||||
</p>
|
</p>
|
||||||
<p className="mb-1">
|
<p className="mb-1">
|
||||||
<span className="text-heading fw-medium">Deadline: </span>
|
<span className="text-heading fw-medium">Deadline: </span>
|
||||||
|
|
||||||
{project.endDate
|
{project?.endDate
|
||||||
? moment(project.endDate).format("DD-MMM-YYYY")
|
? moment(project?.endDate).format("DD-MMM-YYYY")
|
||||||
: "NA"}
|
: "NA"}
|
||||||
</p>
|
</p>
|
||||||
<p className="mb-0">{project.projectAddress}</p>
|
<p className="mb-0">{project?.projectAddress}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -150,37 +150,37 @@ const ProjectCard = ({ project }) => {
|
|||||||
<span
|
<span
|
||||||
className={
|
className={
|
||||||
`badge rounded-pill ` +
|
`badge rounded-pill ` +
|
||||||
getProjectStatusColor(project.projectStatusId)
|
getProjectStatusColor(project?.projectStatusId)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{getProjectStatusName(project.projectStatusId)}
|
{getProjectStatusName(project?.projectStatusId)}
|
||||||
</span>
|
</span>
|
||||||
</p>{" "}
|
</p>{" "}
|
||||||
{getDateDifferenceInDays(project.endDate, Date()) >= 0 && (
|
{getDateDifferenceInDays(project?.endDate,new Date() ) >= 0 && (
|
||||||
<span className="badge bg-label-success ms-auto">
|
<span className="badge bg-label-success ms-auto">
|
||||||
{project.endDate &&
|
{project?.endDate &&
|
||||||
getDateDifferenceInDays(project.endDate, Date())}{" "}
|
getDateDifferenceInDays(project?.endDate, new Date())}{" "}
|
||||||
Days left
|
Days left
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{getDateDifferenceInDays(project.endDate, Date()) < 0 && (
|
{getDateDifferenceInDays(project?.endDate, new Date()) < 0 && (
|
||||||
<span className="badge bg-label-danger ms-auto">
|
<span className="badge bg-label-danger ms-auto">
|
||||||
{project.endDate &&
|
{project?.endDate &&
|
||||||
getDateDifferenceInDays(project.endDate, Date())}{" "}
|
getDateDifferenceInDays(project?.endDate, new Date())}{" "}
|
||||||
Days overdue
|
Days overdue
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="d-flex justify-content-between align-items-center mb-2">
|
<div className="d-flex justify-content-between align-items-center mb-2">
|
||||||
<small className="text-body">
|
<small className="text-body">
|
||||||
Task: {formatNumber(project.completedWork)} /{" "}
|
Task: {formatNumber(project?.completedWork)} /{" "}
|
||||||
{formatNumber(project.plannedWork)}
|
{formatNumber(project?.plannedWork)}
|
||||||
</small>
|
</small>
|
||||||
<small className="text-body">
|
<small className="text-body">
|
||||||
{Math.floor(
|
{Math.floor(
|
||||||
getProgressInNumber(
|
getProgressInNumber(
|
||||||
project.plannedWork,
|
project?.plannedWork,
|
||||||
project.completedWork
|
project?.completedWork
|
||||||
)
|
)
|
||||||
) || 0}{" "}
|
) || 0}{" "}
|
||||||
% Completed
|
% Completed
|
||||||
@ -192,13 +192,13 @@ const ProjectCard = ({ project }) => {
|
|||||||
role="progressbar"
|
role="progressbar"
|
||||||
style={{
|
style={{
|
||||||
width: getProgress(
|
width: getProgress(
|
||||||
project.plannedWork,
|
project?.plannedWork,
|
||||||
project.completedWork
|
project?.completedWork
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
aria-valuenow={project.completedWork}
|
aria-valuenow={project?.completedWork}
|
||||||
aria-valuemin="0"
|
aria-valuemin="0"
|
||||||
aria-valuemax={project.plannedWork}
|
aria-valuemax={project?.plannedWork}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
<div className="d-flex align-items-center justify-content-between">
|
<div className="d-flex align-items-center justify-content-between">
|
||||||
|
@ -3,25 +3,33 @@ import { ActiveTenant } from "./constants";
|
|||||||
|
|
||||||
export const getDateDifferenceInDays = (startDate, endDate) => {
|
export const getDateDifferenceInDays = (startDate, endDate) => {
|
||||||
if (!startDate || !endDate) {
|
if (!startDate || !endDate) {
|
||||||
throw new Error("Both startDate and endDate must be provided");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the dates are valid
|
|
||||||
const start = new Date(startDate);
|
const start = new Date(startDate);
|
||||||
const end = new Date(endDate);
|
const end = new Date(endDate);
|
||||||
|
|
||||||
if (isNaN(start) || isNaN(end)) {
|
if (isNaN(start) || isNaN(end)) {
|
||||||
throw new Error("Invalid date format");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the difference in milliseconds
|
const startAtMidnight = new Date(
|
||||||
const differenceInMs = start - end;
|
start.getFullYear(),
|
||||||
|
start.getMonth(),
|
||||||
|
start.getDate()
|
||||||
|
);
|
||||||
|
|
||||||
// Convert milliseconds to days
|
const endAtMidnight = new Date(
|
||||||
const differenceInDays = Math.floor(differenceInMs / (1000 * 60 * 60 * 24));
|
end.getFullYear(),
|
||||||
return differenceInDays;
|
end.getMonth(),
|
||||||
|
end.getDate()
|
||||||
|
);
|
||||||
|
|
||||||
|
return Math.floor((startAtMidnight - endAtMidnight) / (1000 * 60 * 60 * 24));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user