Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda