Skip to content

Commit

Permalink
use a single prop to close modal
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis committed Dec 11, 2024
1 parent 9e52aaf commit d779abe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 4 additions & 6 deletions scripts/core/prompt-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {gettext} from './utils';

interface IProps {
label: string;
closeModal(): void;
onDone(value: string): void;
closeModal(result: {value: string | null}): void;
okButtonText?: string;
cancelButtonText?: string;
}
Expand All @@ -27,21 +26,20 @@ export class PromptModal extends React.Component<IProps, IState> {
<Modal
position="top"
visible
onHide={this.props.closeModal}
onHide={() => this.props.closeModal({value: null})}
footerTemplate={
(
<Spacer h gap="4" justifyContent="end" noWrap>
<Button
type="default"
text={this.props.cancelButtonText ?? gettext('Cancel')}
onClick={this.props.closeModal}
onClick={() => this.props.closeModal({value: null})}
/>
<Button
type="primary"
text={this.props.okButtonText ?? gettext('Ok')}
onClick={() => {
this.props.onDone(this.state.value);
this.props.closeModal();
this.props.closeModal({value: this.state.value});
}}
/>
</Spacer>
Expand Down
11 changes: 7 additions & 4 deletions scripts/core/ui-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ export const ui = {
showModal(({closeModal}) => {
return (
<PromptModal
closeModal={closeModal}
closeModal={({value}) => {
closeModal();

if (value != null) {
resolve(value);
}
}}
label={options.inputLabel}
okButtonText={options.okButtonText}
cancelButtonText={options.cancelButtonText}
onDone={(value) => {
resolve(value);
}}
/>
);
});
Expand Down

0 comments on commit d779abe

Please sign in to comment.