Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
how to enable a disable button on date change in react.js

I am making an attendance & time management portal. I have two buttons Checkin & checkOut.On clicking the check-in button check-in time & attendance is marked & on clicking the checkOut button checkOut time is marked. What I am trying to do is I am matching the check-in date which is coming from the backend & the current date from the front end, if it matches Checkin & checkout button should be enabled & if the condition is false these two buttons should be disabled. My scenario is first, my check-in button should be enabled & the checkout button should be disabled.on clicking the check-in button check-in time is marked. At this point, the check-in button should become disabled and the checkOut button should become enabled. When I press the checkOut button checkout time is marked & the checkOut button also becomes disabled. These two buttons should remain disabled until the date changes. on the next date, the CheckIn button should automatically become enabled & the same pattern should follow. Here, whether the condition is true or not button disables on clicking & doesn't enable again.

const employee = useSelector(state => state.employee);

const [checkInDisable, setCheckInDisable] = useState(false);
const [checkOutDisable, setCheckOutDisable] = useState(true);

var currentDate = new Date();
var d = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
var date = d + "-" + month + "-" + year;

useEffect(() => {
  
  dispatch(getEmployeeCheckIn());
  dispatch(getEmployeeCheckOut());

  employee.checkIn.map(In => In.day === date).toString()
    ? setCheckInDisable(true) && setCheckOutDisable(false)
    : setCheckInDisable(false);
  employee.checkOut.map(Out => Out.day === date).toString()
    ? setCheckOutDisable(true)
    : setCheckOutDisable(false);

  },
  [dispatch, employee, date]
);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!