Skip to content

Commit

Permalink
fix: 🐛 prevent triggering the call multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Spielmann committed Mar 16, 2021
1 parent e0ed8d4 commit 6e91110
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/components/profile/DeleteAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const DeleteAccount = () => {
const [isPasswordWarningActive, setIsPasswordWarningActive] = useState<
boolean
>(false);
const [isRequestInProgress, setIsRequestInProgress] = useState<boolean>(
false
);

const deleteAccountButton: ButtonItem = {
label: translate('deleteAccount.button.label'),
Expand Down Expand Up @@ -71,11 +74,10 @@ export const DeleteAccount = () => {

const overlaySuccess: OverlayItem = {
headline: translate('deleteAccount.successOverlay.headline'),
headlineStyleLevel: '3',
svg: CheckIllustration,
buttonSet: [
{
label: 'schließen',
label: translate('deleteAccount.successOverlay.button'),
function: OVERLAY_FUNCTIONS.REDIRECT,
type: BUTTON_TYPES.SECONDARY
}
Expand All @@ -85,14 +87,19 @@ export const DeleteAccount = () => {
const handleOverlayAction = (buttonFunction: string) => {
if (buttonFunction === OVERLAY_FUNCTIONS.CLOSE) {
setIsOverlayActive(false);
} else if (buttonFunction === OVERLAY_FUNCTIONS.DELETE_ACCOUNT) {
} else if (
!isRequestInProgress &&
buttonFunction === OVERLAY_FUNCTIONS.DELETE_ACCOUNT
) {
setIsRequestInProgress(true);
apiDeleteAskerAccount(password)
.then(() => {
setIsSuccessOverlay(true);
})
.catch((error) => {
if (error.message === FETCH_ERRORS.BAD_REQUEST) {
setIsPasswordWarningActive(true);
setIsRequestInProgress(false);
} else {
console.log(error);
}
Expand Down
3 changes: 2 additions & 1 deletion src/resources/scripts/i18n/de/deleteAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const deleteAccount = {
'confirmOverlay.input.label': 'Passwort',
'confirmOverlay.input.warning': 'Ihr Passwort ist nicht korrekt.',
'successOverlay.headline':
'Sie haben Ihren Account bei der Caritas Online Beratung und Hilfe erfolgreich gelöscht.'
'Sie haben Ihren Account bei der Caritas Online Beratung und Hilfe erfolgreich gelöscht.',
'successOverlay.button': 'schließen'
};

export default deleteAccount;

0 comments on commit 6e91110

Please sign in to comment.