Skip to content

Commit b0f6b66

Browse files
committed
[terms/dashboard] avoid resubmitting twice
1 parent 13a5f8e commit b0f6b66

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

components/dashboard/src/components/tos/terms-of-service.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ export interface TermsOfServiceProps {
2525
}
2626
interface TermsOfServiceState {
2727
isUpdate: boolean;
28+
flowId: string;
2829
userInfo?: any;
2930
terms?: Terms;
3031
acceptsTos: boolean;
32+
submitted: boolean;
3133
}
3234
export class TermsOfService extends React.Component<TermsOfServiceProps, TermsOfServiceState> {
3335
protected gitpodHost = new GitpodHostUrl(window.location.href);
@@ -38,7 +40,9 @@ export class TermsOfService extends React.Component<TermsOfServiceProps, TermsOf
3840
super(props);
3941
this.state = {
4042
isUpdate: false,
41-
acceptsTos: false
43+
acceptsTos: false,
44+
submitted: false,
45+
flowId: "ignore",
4246
};
4347
this.formRef = React.createRef();
4448
this.onDecline = this.onDecline.bind(this);
@@ -53,6 +57,7 @@ export class TermsOfService extends React.Component<TermsOfServiceProps, TermsOf
5357
const tosHints = Cookies.getJSON('tosHints');
5458
this.setState({
5559
isUpdate: tosHints?.isUpdate === true,
60+
flowId: typeof tosHints?.flowId === "string" ? tosHints?.flowId : this.state.flowId,
5661
userInfo: typeof tosHints?.userInfo === "object" ? tosHints?.userInfo : undefined
5762
});
5863
this.props.terms.then(terms => this.setState({ terms }));
@@ -63,10 +68,10 @@ export class TermsOfService extends React.Component<TermsOfServiceProps, TermsOf
6368
}
6469

6570
onAccept() {
66-
this.setState({ acceptsTos: true }, () => this.doSubmit());
71+
this.setState({ acceptsTos: true, submitted: true }, () => this.doSubmit());
6772
}
6873
onDecline() {
69-
this.setState({ acceptsTos: false }, () => this.doSubmit());
74+
this.setState({ acceptsTos: false, submitted: true }, () => this.doSubmit());
7075
}
7176
protected doSubmit() {
7277
this.formRef.current!.submit();
@@ -126,6 +131,7 @@ export class TermsOfService extends React.Component<TermsOfServiceProps, TermsOf
126131
</AppBar>
127132
<div className='content content-area'>
128133
<form ref={this.formRef} action={this.actionUrl} method="post" id="accept-tos-form">
134+
<input type="hidden" id="flowId" name="flowId" value={this.state.flowId} />
129135
<div className="tos-checks">
130136
<Typography className="tos-content" dangerouslySetInnerHTML={{ __html: update ? updateMessage : content }} />
131137
<p>
@@ -148,13 +154,15 @@ export class TermsOfService extends React.Component<TermsOfServiceProps, TermsOf
148154
variant='text'
149155
color={'secondary'}
150156
onClick={this.onDecline}
157+
disabled={this.state.submitted}
151158
data-testid="decline">
152159
{'Decline and log out'}
153160
</ButtonWithProgress>
154161
)}
155162
<ButtonWithProgress
156163
className='button'
157164
onClick={this.onAccept}
165+
disabled={this.state.submitted}
158166
variant='outlined'
159167
color={'primary'}
160168
data-testid="submit">

0 commit comments

Comments
 (0)