Skip to content

Commit

Permalink
fix error catching
Browse files Browse the repository at this point in the history
  • Loading branch information
anissa-agahchen committed May 26, 2021
1 parent 69c53de commit 888be52
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,33 @@ const SurveyGeneralInformation: React.FC<ISurveyGeneralInformationProps> = (prop
};

const handleDialogEditOpen = async () => {
let surveyDetailsResponseData;

try {
const response = await biohubApi.survey.getSurveyForUpdate(projectForViewData.id, survey_details?.id, [
UPDATE_GET_SURVEY_ENTITIES.survey_details
]);

if (!response) {
if (!response?.survey_details) {
showErrorDialog({ open: true });
return;
}

if (response.survey_details) {
setSurveyDataForUpdate(response?.survey_details);
setGeneralInformationFormData({
...response.survey_details,
start_date: getFormattedDate(DATE_FORMAT.ShortDateFormat, response.survey_details.start_date),
end_date: getFormattedDate(DATE_FORMAT.ShortDateFormat, response.survey_details.end_date)
});
setOpenEditDialog(true);
}
surveyDetailsResponseData = response.survey_details;
} catch (error) {
const apiError = error as APIError;
showErrorDialog({ dialogText: apiError.message, open: true });
return;
}
};

setSurveyDataForUpdate(surveyDetailsResponseData);
setGeneralInformationFormData({
...surveyDetailsResponseData,
start_date: getFormattedDate(DATE_FORMAT.ShortDateFormat, surveyDetailsResponseData.start_date),
end_date: getFormattedDate(DATE_FORMAT.ShortDateFormat, surveyDetailsResponseData.end_date)
});
setOpenEditDialog(true);
};
const handleDialogEditSave = async (values: IGeneralInformationForm) => {
try {
if (surveyDataForUpdate) {
Expand Down

0 comments on commit 888be52

Please sign in to comment.