From 06549bf9bb228e066ab9f2c523bb028eda2dfb26 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Tue, 6 Jun 2023 20:52:15 +0100 Subject: [PATCH] Displays countdown if task is yet to pass due, else displays due time --- src/components/MyActiveJobs/ActiveJobs.jsx | 74 +++++++++++++++++----- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/src/components/MyActiveJobs/ActiveJobs.jsx b/src/components/MyActiveJobs/ActiveJobs.jsx index e1c365f..7cb2cca 100644 --- a/src/components/MyActiveJobs/ActiveJobs.jsx +++ b/src/components/MyActiveJobs/ActiveJobs.jsx @@ -4,16 +4,17 @@ import Layout from "../Partials/Layout"; import { useNavigate } from "react-router-dom"; import ActiveJobMessage from "./ActiveJobMessage"; import LoadingSpinner from "../Spinners/LoadingSpinner"; - import CountDown from "../Helpers/CountDown"; import usersService from "../../services/UsersService"; function ActiveJobs(props) { const ApiCall = new usersService() + let navigate = useNavigate() let { userDetails } = useSelector((state) => state.userDetails); - let navigate = useNavigate() + + let [passDue, setPassDue] = useState(new Date() > new Date(props.details?.delivery_date)) // STATE TO KNOW IF TASK IS PASSED DUE TIME let [messageToSend, setMessageToSend] = useState('') // State to hold the value of message to be sent @@ -147,10 +148,33 @@ function ActiveJobs(props) { } } + + // FUNCTION TO CHECK IF TASK PASS DUE IS REACHED + let isPassedDue = () => { + // console.log('TESTING',new Date() > new Date(props.details?.delivery_date) ) + if(new Date() > new Date(props.details?.delivery_date)){ + setPassDue(true) + }else{ + setPassDue(false) + } + } + + + useEffect(()=>{ + if(!passDue){ + let passDueInterval = setInterval(()=>{ + isPassedDue() + },1000) + return ()=>{ + clearInterval(passDueInterval) + } + } + },[passDue]) + return ( -
+
{/* job title */}
@@ -175,9 +199,9 @@ function ActiveJobs(props) {
-

- {userDetails.firstname && userDetails.firstname} -

+

+ {userDetails.firstname && userDetails.firstname} +

Description:

{props.details?.description && props.details.description}

@@ -189,19 +213,37 @@ function ActiveJobs(props) { {/* job details */}

Delivery Detail

-
-

Due:

-
-

- + {passDue ? + ( +

+

+ Due: + {props.details?.delivery_date && + props.details.delivery_date.split(" ")[0]}

-
- Hrs - Min - Sec +

+ {props.details?.delivery_date && + props.details.delivery_date.split(" ")[1]} +

+
+ ) + : + ( +
+

Due:

+
+

+ +

+
+ Hrs + Min + Sec +
-
+ ) + }
Duration: