Skip to content

Commit 2692672

Browse files
vibhandikyashsomangshu
authored andcommitted
FIX #6324 : reset recaptcha token on click and handled button loading explicitly (#6337)
reset re-captcha token on click and handled button loading explicitly such that the user know that the api call has not finished (cherry picked from commit 31f8a70) (cherry picked from commit 35ee2a9)
1 parent f00b391 commit 2692672

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

app/client/src/components/designSystems/blueprint/ButtonComponent.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export enum ButtonType {
153153
interface RecaptchaProps {
154154
googleRecaptchaKey?: string;
155155
clickWithRecaptcha: (token: string) => void;
156+
handleRecaptchaV2Loading?: (isLoading: boolean) => void;
156157
recaptchaV2?: boolean;
157158
}
158159

@@ -190,20 +191,27 @@ function RecaptchaV2Component(
190191
) {
191192
const recaptchaRef = useRef<ReCAPTCHA>(null);
192193
const [isInvalidKey, setInvalidKey] = useState(false);
194+
const handleRecaptchaLoading = (isloading: boolean) => {
195+
props.handleRecaptchaV2Loading && props.handleRecaptchaV2Loading(isloading);
196+
};
193197
const handleBtnClick = async (event: React.MouseEvent<HTMLElement>) => {
194198
if (isInvalidKey) {
195199
// Handle incorrent google recaptcha site key
196200
props.handleError(event, createMessage(GOOGLE_RECAPTCHA_KEY_ERROR));
197201
} else {
202+
handleRecaptchaLoading(true);
198203
try {
204+
await recaptchaRef?.current?.reset();
199205
const token = await recaptchaRef?.current?.executeAsync();
200206
if (token) {
201207
props.clickWithRecaptcha(token);
202208
} else {
203209
// Handle incorrent google recaptcha site key
204210
props.handleError(event, createMessage(GOOGLE_RECAPTCHA_KEY_ERROR));
205211
}
212+
handleRecaptchaLoading(false);
206213
} catch (err) {
214+
handleRecaptchaLoading(false);
207215
// Handle error due to google recaptcha key of different domain
208216
props.handleError(event, createMessage(GOOGLE_RECAPTCHA_DOMAIN_ERROR));
209217
}
@@ -316,6 +324,7 @@ function ButtonContainer(
316324
<BtnWrapper
317325
clickWithRecaptcha={props.clickWithRecaptcha}
318326
googleRecaptchaKey={props.googleRecaptchaKey}
327+
handleRecaptchaV2Loading={props.handleRecaptchaV2Loading}
319328
onClick={props.onClick}
320329
recaptchaV2={props.recaptchaV2}
321330
>

app/client/src/widgets/ButtonWidget.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ class ButtonWidget extends BaseWidget<ButtonWidgetProps, ButtonWidgetState> {
144144
}
145145

146146
clickWithRecaptcha(token: string) {
147-
if (this.props.onClick) {
148-
this.setState({
149-
isLoading: true,
150-
});
151-
}
152147
this.props.updateWidgetMetaProperty("recaptchaToken", token, {
153148
triggerPropertyName: "onClick",
154149
dynamicString: this.props.onClick,
@@ -159,6 +154,12 @@ class ButtonWidget extends BaseWidget<ButtonWidgetProps, ButtonWidgetState> {
159154
});
160155
}
161156

157+
handleRecaptchaV2Loading = (isLoading: boolean) => {
158+
if (this.props.onClick) {
159+
this.setState({ isLoading });
160+
}
161+
};
162+
162163
handleActionComplete = () => {
163164
this.setState({
164165
isLoading: false,
@@ -172,6 +173,7 @@ class ButtonWidget extends BaseWidget<ButtonWidgetProps, ButtonWidgetState> {
172173
clickWithRecaptcha={this.clickWithRecaptchaBound}
173174
disabled={this.props.isDisabled}
174175
googleRecaptchaKey={this.props.googleRecaptchaKey}
176+
handleRecaptchaV2Loading={this.handleRecaptchaV2Loading}
175177
isLoading={this.props.isLoading || this.state.isLoading}
176178
key={this.props.widgetId}
177179
onClick={!this.props.isDisabled ? this.onButtonClickBound : undefined}

0 commit comments

Comments
 (0)