From 4075fee0fe8427b9714c229bade6000e6b25ab49 Mon Sep 17 00:00:00 2001 From: Szymon Oleksy Date: Mon, 19 Feb 2024 15:43:21 +0100 Subject: [PATCH] feat: add possibility to use async onSave method --- ui/src/components/BaseFormView.tsx | 6 ++++-- ui/src/components/EntityModal/EntityModal.tsx | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ui/src/components/BaseFormView.tsx b/ui/src/components/BaseFormView.tsx index cdc54af0a..26d5a0c2b 100644 --- a/ui/src/components/BaseFormView.tsx +++ b/ui/src/components/BaseFormView.tsx @@ -522,7 +522,7 @@ class BaseFormView extends PureComponent { } }; - handleSubmit = (event: React.MouseEvent | React.FormEvent) => { + handleSubmit = async (event: React.MouseEvent | React.FormEvent) => { event.preventDefault(); this.clearErrorMsg(); this.props.handleFormSubmit(/* isSubmitting */ true, /* closeEntity */ false); @@ -536,7 +536,8 @@ class BaseFormView extends PureComponent { }); if (this.hook && typeof this.hook.onSave === 'function') { - const validationPass = this.hook.onSave(this.datadict); + const validationPass = await this.hook.onSave(this.datadict); + if (!validationPass) { this.props.handleFormSubmit(/* isSubmitting */ false, /* closeEntity */ false); return; @@ -1251,6 +1252,7 @@ class BaseFormView extends PureComponent { } this.flag = false; } + return (
{ this.props.handleRequestClose(); }; - handleSubmit: ButtonClickHandler = (e) => { - const result = this.form.current?.handleSubmit(e); + handleSubmit: ButtonClickHandler = async (e) => { + const result = await this.form.current?.handleSubmit(e); if (result) { this.handleRequestClose(); }