Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda