diff --git a/src/components/transaction/create-user-transaction-form.tsx b/src/components/transaction/create-user-transaction-form.tsx index 4c87772d..6e483a41 100644 --- a/src/components/transaction/create-user-transaction-form.tsx +++ b/src/components/transaction/create-user-transaction-form.tsx @@ -61,9 +61,12 @@ type Props = RouteComponentProps<{ id: string }> & export class CreateUserTransactionForm extends React.Component { public state = initialState; - // tslint:disable-next-line:no-any public submitUserId = (user: User): void => { - this.setState(() => ({ selectedUser: user }), this.createTransaction); + if (!this.state.selectedUser.id) { + this.setState(() => ({ selectedUser: user })); + } else { + this.handleSubmit(); + } }; public createTransaction = async () => { @@ -85,6 +88,15 @@ export class CreateUserTransactionForm extends React.Component { } }; + public handleSubmit = (e?: React.FormEvent) => { + if (e) { + e.preventDefault(); + } + if (this.state.selectedUser.id && this.state.selectedAmount) { + this.createTransaction(); + } + }; + public setComment = (event: React.ChangeEvent) => { this.setState({ comment: event.target.value }); }; @@ -113,58 +125,60 @@ export class CreateUserTransactionForm extends React.Component { } else { return ( <> - - - this.setState({ - selectedAmount: value, - }) - } - /> - → - + + + this.setState({ + selectedAmount: value, + }) + } + /> + → + user.name} + onSelect={this.submitUserId} + /> + ( + + + + )} + /> + + user.name} - onSelect={this.submitUserId} - /> - ( - - - - )} /> - - + ); }