Skip to content

Commit

Permalink
feat(settings): add confirmation before resetting
Browse files Browse the repository at this point in the history
- add i18n context
- add alert to confirm reset
  • Loading branch information
SimonGolms committed Jan 24, 2021
1 parent 8dcf2b5 commit 64b0dde
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/pages/Settings/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ ion-item-divider {
ion-content ion-toolbar {
--background: transparent;
}

.alert-button.alert-button-danger {
color: var(--ion-color-danger);
}
30 changes: 28 additions & 2 deletions src/pages/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
IonButtons,
Expand All @@ -18,6 +18,7 @@ import {
IonIcon,
IonItemGroup,
IonItemDivider,
IonAlert,
} from '@ionic/react';
import './index.css';
import { useTranslation } from 'react-i18next';
Expand All @@ -31,6 +32,8 @@ import { resetUserState, setCurrentTheme } from '../../data/user/user.slice';
export const SettingsPage: React.FC = () => {
const { t, i18n } = useTranslation();

const [showAlertReset, setShowAlertReset] = useState(false);

const dispatch = useDispatch();
const currentTheme = useSelector(selectCurrentTheme);

Expand Down Expand Up @@ -122,12 +125,35 @@ export const SettingsPage: React.FC = () => {
<IonItem routerLink={'/credits'}>
<IonLabel>{t('SETTINGS.GENERAL.ITEMS.CREDITS.LABEL')}</IonLabel>
</IonItem>
<IonItem button onClick={() => dispatch(resetUserState())}>
<IonItem
button
detail={false}
onClick={() => setShowAlertReset(true)}
>
<IonLabel color="danger">
{t('SETTINGS.GENERAL.ITEMS.RESET.LABEL')}
</IonLabel>
</IonItem>
</IonList>
<IonAlert
isOpen={showAlertReset}
onDidDismiss={() => setShowAlertReset(false)}
header={t('SETTINGS.GENERAL.ITEMS.RESET.ALERT.HEADER')}
message={t('SETTINGS.GENERAL.ITEMS.RESET.ALERT.MESSAGE')}
buttons={[
{
text: t('SETTINGS.GENERAL.ITEMS.RESET.ALERT.BUTTON.CANCEL'),
role: 'cancel',
},
{
cssClass: 'alert-button-danger',
text: t('SETTINGS.GENERAL.ITEMS.RESET.ALERT.BUTTON.RESET'),
handler: () => {
dispatch(resetUserState());
},
},
]}
/>
</IonContent>
</IonPage>
);
Expand Down
10 changes: 9 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3078,7 +3078,15 @@
"NOTE": "Boehringer Ingelheim"
},
"RESET": {
"LABEL": "Reset"
"LABEL": "Reset",
"ALERT": {
"HEADER": "Reset App Settings",
"MESSAGE": "This will reset all your settings like the selection of language and theme and will also delete your favorites.",
"BUTTON": {
"CANCEL": "Cancel",
"RESET": "Reset"
}
}
}
}
},
Expand Down

0 comments on commit 64b0dde

Please sign in to comment.