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

118
Visualizações
how to handle the request depending on other request or leave the page?

i have page of request a "task" , and i want to handle one request if the user don't submit the task or he leave the page ,

these are the cases ,

1-

  1. List item if the user submit the form i will re-direct him to other page.

2.if user want to leave the page of the form request , i want to make a request called "DELETE".

3.if the user navigate out side the page by click on other public route , then also i want to make a request called "DELETE".

this is code when i submit the form :

// here if the user submit the form 
  useEffect(() => {
    if (submitForm.status === RequestStatus.resolved) {
      setFormLoading(false);
      notification.success({
        message: t('messages.success'),
        description: t('messages.success.requestCreated'),
      });
      history.goBack();
    } else if (submitForm.status === RequestStatus.rejected) {
      setFormLoading(false);
      notification.error({
        message: t('leaves.newRequest.message.leaveRequestError'),
        description: submitForm.error?.message?.includes('Leave request already exists')
          ? t('leaves.newRequest.error.alreadyExists')
          : submitForm.error?.message,
      });
    }
  }, [submitForm.status, t, submitForm.error?.message, history]);

this the delete request

 const deleteProcessInstance = useCallback(async () => {
    
      try {

     // Delete request here 

  
      } catch {
        notification.error({
          message: t('messages.error.wentWrong'),
          description: t('messages.error.tryAgainLater'),
        });
      }
    
  }, [ dispatch, t]);

here how to i handle the delete request if with case 2 and 3 , but i faceing now error when i submit the form , then the delete request hit ,

and i don't want that , i want only to hit delete request if the user dont sumbit the form and navigate out of the submit form page

this my code

  useEffect(
    () => () => {
      deleteProcessInstance();
    },
    // eslint-disable-next-line react-hooks/exhaustive-deps
    []
  );
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There is no reliable way to do this, you can use the unload event but it's not reliable. Unoad event.

Better don't save anything in DB till form is submitted, or come up with some different solution

about 4 years ago · Juan Pablo Isaza Relatório
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