Skip to content

Commit

Permalink
[MergeStep] Convert Save&Continue Button to LoadingButton
Browse files Browse the repository at this point in the history
Prevent clicking button twice
  • Loading branch information
imnasnainaec authored Aug 4, 2022
1 parent ea05947 commit d8bc7ce
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/goals/MergeDupGoal/MergeDupStep/MergeDupStepComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button, Grid, ImageList, Typography } from "@material-ui/core";
import React, { ReactElement } from "react";
import { WithTranslation, withTranslation } from "react-i18next";

import LoadingButton from "components/Buttons/LoadingButton";
import MergeDragDrop from "goals/MergeDupGoal/MergeDupStep/DragDropComponents/MergeDragDrop";
import theme from "types/theme";

Expand All @@ -12,13 +13,27 @@ interface MergeDupStepProps extends WithTranslation {
mergeAll: () => Promise<void>;
}

class MergeDupStep extends React.Component<MergeDupStepProps> {
interface MergeDupStepState {
isSaving: boolean;
}

class MergeDupStep extends React.Component<
MergeDupStepProps,
MergeDupStepState
> {
constructor(props: MergeDupStepProps) {
super(props);
this.state = { isSaving: false };
}

next(): void {
this.props.clearSidebar();
this.setState({ isSaving: false });
this.props.advanceStep();
}

saveContinue(): void {
this.setState({ isSaving: true });
this.props.clearSidebar();
this.props.mergeAll().then(() => this.next());
}
Expand All @@ -43,16 +58,19 @@ class MergeDupStep extends React.Component<MergeDupStepProps> {
{/* Merge/skip buttons */}
<Grid container justifyContent="flex-start">
<Grid item>
<Button
color="primary"
variant="contained"
style={{ marginRight: theme.spacing(3) }}
onClick={() => this.saveContinue()}
title={this.props.t("mergeDups.helpText.saveAndContinue")}
id="merge-save"
<LoadingButton
loading={this.state.isSaving}
buttonProps={{
color: "primary",
variant: "contained",
style: { marginRight: theme.spacing(3) },
onClick: () => this.saveContinue(),
title: this.props.t("mergeDups.helpText.saveAndContinue"),
id: "merge-save",
}}
>
{this.props.t("buttons.saveAndContinue")}
</Button>
</LoadingButton>
<Button
color="secondary"
variant="contained"
Expand Down

0 comments on commit d8bc7ce

Please sign in to comment.