P
P
ParaBellum5772021-07-12 13:20:19
React
ParaBellum577, 2021-07-12 13:20:19

Error handling in a modal window?

I have a modal with many fields that are processed on the server. The bottom line is that I need to draw errors if they exist, if not, just close the window and save. Errors are put in the editor after the request to the server, but the problem is that when the error window is opened, there are still no errors, and even if the back request returns an error, the modal closes because they have not yet appeared in the editor. await before close doesn't help

const handleSubmit = async () => {
    if (startTime !== endTime) {
      const data = {
        title: eventName,
        subject: lesson,
        startTime: getUtcTime(startTime, 'LT', startDate),
        endTime: getUtcTime(endTime, 'LT', startDate),
        link: link || null,
        repeat: age,
        isOnline,
        date: startDate.toISOString(),
      };
      if (!editEventData) {
        await addEvent(data, +unitId);
        if (!_.isEmpty(scholars.units) && !hasErrors) {
          setEventName('');
          setAge('');
          setLink('');
          setLesson('');
          handleClose();
        }
      } else if (editEvent && editEventData.id) {
        await editEvent(+unitId, editEventData.id, data);
        if (!_.isEmpty(scholars.units) && _.isEmpty(errorMessages)) {
          handleClose();
        }
      }
    }
  };

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question