Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add possibility to use async onSave method #1079

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ui/src/components/BaseFormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class BaseFormView extends PureComponent<BaseFormProps, BaseFormState> {
}
};

handleSubmit = (event: React.MouseEvent | React.FormEvent) => {
handleSubmit = async (event: React.MouseEvent | React.FormEvent) => {
event.preventDefault();
this.clearErrorMsg();
this.props.handleFormSubmit(/* isSubmitting */ true, /* closeEntity */ false);
Expand All @@ -536,7 +536,8 @@ class BaseFormView extends PureComponent<BaseFormProps, BaseFormState> {
});

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;
Expand Down Expand Up @@ -1251,6 +1252,7 @@ class BaseFormView extends PureComponent<BaseFormProps, BaseFormState> {
}
this.flag = false;
}

return (
<div>
<form
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/EntityModal/EntityModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class EntityModal extends Component<EntityModalProps, EntityModalState> {
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();
}
Expand Down
Loading