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

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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