|
@@ -18,74 +18,99 @@ import UserXMark from '../../../../../assets/icons/user-xmark.svg';
|
|
|
|
|
|
import type { MenuButtonType } from '../../../../types/components';
|
|
|
import { StoreType, storage } from 'src/storage';
|
|
|
-import { CommonActions } from '@react-navigation/native';
|
|
|
-
|
|
|
-const buttons: MenuButtonType[] = [
|
|
|
- {
|
|
|
- label: 'Edit Profile',
|
|
|
- icon: <UserPenIcon fill={Colors.DARK_BLUE} width={20} height={20} />,
|
|
|
- buttonFn: (navigation) => {
|
|
|
- navigation.navigate(NAVIGATION_PAGES.EDIT_PERSONAL_INFO);
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Invite a Friend',
|
|
|
- icon: <UserPlusIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Notification',
|
|
|
- icon: <BellIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Contact Us',
|
|
|
- icon: <MailIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'FAQs',
|
|
|
- icon: <FAQIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Terms & Conditions',
|
|
|
- icon: <DocumentIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Privacy Notice',
|
|
|
- icon: <ShieldIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Logout',
|
|
|
- icon: <ExitIcon fill={Colors.RED} width={20} height={20} />,
|
|
|
- red: true,
|
|
|
- buttonFn: (navigation) => {
|
|
|
- storage.remove('token');
|
|
|
- storage.remove('uid');
|
|
|
-
|
|
|
- navigation.dispatch(
|
|
|
- CommonActions.reset({
|
|
|
- index: 1,
|
|
|
- routes: [{ name: NAVIGATION_PAGES.WELCOME }]
|
|
|
- })
|
|
|
- );
|
|
|
- }
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Delete account',
|
|
|
- icon: <UserXMark fill={Colors.RED} width={20} height={20} />,
|
|
|
- red: true
|
|
|
- }
|
|
|
-];
|
|
|
+import { CommonActions, useNavigation } from '@react-navigation/native';
|
|
|
|
|
|
const Settings = () => {
|
|
|
const [isSubscribed, setIsSubscribed] = useState(false);
|
|
|
- const [warningVisible, setWarningVisible] = useState(false);
|
|
|
- const [askPermission, setAskPermission] = useState(false);
|
|
|
const [shouldOpenWarningModal, setShouldOpenWarningModal] = useState(false);
|
|
|
+ const navigation = useNavigation();
|
|
|
+ const [modalInfo, setModalInfo] = useState({
|
|
|
+ visible: false,
|
|
|
+ type: 'confirm',
|
|
|
+ message: '',
|
|
|
+ action: () => {}
|
|
|
+ });
|
|
|
+
|
|
|
+ const openModal = (type: string, message: string, action: any) => {
|
|
|
+ setModalInfo({
|
|
|
+ visible: true,
|
|
|
+ type,
|
|
|
+ message,
|
|
|
+ action
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const closeModal = () => {
|
|
|
+ setModalInfo({ ...modalInfo, visible: false });
|
|
|
+ };
|
|
|
+
|
|
|
+ const buttons: MenuButtonType[] = [
|
|
|
+ {
|
|
|
+ label: 'Edit Profile',
|
|
|
+ icon: <UserPenIcon fill={Colors.DARK_BLUE} width={20} height={20} />,
|
|
|
+ buttonFn: (navigation) => {
|
|
|
+ navigation.navigate(NAVIGATION_PAGES.EDIT_PERSONAL_INFO);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: 'Invite a Friend',
|
|
|
+ icon: <UserPlusIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: 'Notification',
|
|
|
+ icon: <BellIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: 'Contact Us',
|
|
|
+ icon: <MailIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: 'FAQs',
|
|
|
+ icon: <FAQIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: 'Terms & Conditions',
|
|
|
+ icon: <DocumentIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: 'Privacy Notice',
|
|
|
+ icon: <ShieldIcon fill={Colors.DARK_BLUE} width={20} height={20} />
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: 'Logout',
|
|
|
+ icon: <ExitIcon fill={Colors.RED} width={20} height={20} />,
|
|
|
+ red: true,
|
|
|
+ buttonFn: () => openModal('confirm', 'Are you sure you want to logout?', handleLogout)
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: 'Delete account',
|
|
|
+ icon: <UserXMark fill={Colors.RED} width={20} height={20} />,
|
|
|
+ red: true,
|
|
|
+ buttonFn: () =>
|
|
|
+ openModal('confirm', 'Are you sure you want to delete your account?', handleDeleteAccount)
|
|
|
+ }
|
|
|
+ ];
|
|
|
|
|
|
useEffect(() => {
|
|
|
const subscribed = (storage.get('subscribed', StoreType.BOOLEAN) as boolean) ?? false;
|
|
|
setIsSubscribed(subscribed);
|
|
|
}, []);
|
|
|
|
|
|
+ const handleLogout = () => {
|
|
|
+ storage.remove('token');
|
|
|
+ storage.remove('uid');
|
|
|
+ navigation.dispatch(
|
|
|
+ CommonActions.reset({
|
|
|
+ index: 1,
|
|
|
+ routes: [{ name: NAVIGATION_PAGES.WELCOME }]
|
|
|
+ })
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleDeleteAccount = () => {
|
|
|
+ console.log('Account deleted');
|
|
|
+ };
|
|
|
+
|
|
|
const handleSubscribe = async () => {
|
|
|
const token = await registerForPushNotificationsAsync();
|
|
|
if (token) {
|
|
@@ -104,12 +129,18 @@ const Settings = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const toggleSwitch = async () => {
|
|
|
+ const toggleSwitch = () => {
|
|
|
if (isSubscribed) {
|
|
|
storage.set('subscribed', false);
|
|
|
setIsSubscribed(false);
|
|
|
} else {
|
|
|
- setAskPermission(true);
|
|
|
+ setModalInfo({
|
|
|
+ visible: true,
|
|
|
+ type: 'success',
|
|
|
+ message:
|
|
|
+ 'To use this feature we need your permission to access your notifications. If you press OK your system will ask you to confirm permission to receive notifications from NomadMania.',
|
|
|
+ action: () => setShouldOpenWarningModal(true)
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -122,7 +153,14 @@ const Settings = () => {
|
|
|
finalStatus = status;
|
|
|
}
|
|
|
if (finalStatus !== 'granted') {
|
|
|
- setWarningVisible(true);
|
|
|
+ setModalInfo({
|
|
|
+ visible: true,
|
|
|
+ type: 'success',
|
|
|
+ message:
|
|
|
+ 'NomadMania app needs notification permissions to function properly. Open settings?',
|
|
|
+ action: () =>
|
|
|
+ Platform.OS === 'ios' ? Linking.openURL('app-settings:') : Linking.openSettings()
|
|
|
+ });
|
|
|
return null;
|
|
|
}
|
|
|
token = (await Notifications.getExpoPushTokenAsync()).data;
|
|
@@ -156,7 +194,8 @@ const Settings = () => {
|
|
|
display: 'flex',
|
|
|
flexDirection: 'row',
|
|
|
justifyContent: 'space-between',
|
|
|
- marginTop: 20
|
|
|
+ marginTop: 20,
|
|
|
+ alignItems: 'center'
|
|
|
}}
|
|
|
>
|
|
|
<Text style={{ color: Colors.DARK_BLUE, fontSize: 16, fontWeight: 'bold' }}>
|
|
@@ -170,30 +209,20 @@ const Settings = () => {
|
|
|
/>
|
|
|
</View>
|
|
|
<WarningModal
|
|
|
- isVisible={askPermission}
|
|
|
- onClose={() => setAskPermission(false)}
|
|
|
+ isVisible={modalInfo.visible}
|
|
|
+ onClose={closeModal}
|
|
|
onModalHide={() => {
|
|
|
if (shouldOpenWarningModal) {
|
|
|
setShouldOpenWarningModal(false);
|
|
|
handleSubscribe();
|
|
|
}
|
|
|
}}
|
|
|
- type="success"
|
|
|
- action={() => {
|
|
|
- setAskPermission(false);
|
|
|
- setShouldOpenWarningModal(true);
|
|
|
- }}
|
|
|
- message="To use this feature we need your permission to access your notifications. If you press OK your system will ask you to confirm permission to receive notifications from NomadMania."
|
|
|
- />
|
|
|
- <WarningModal
|
|
|
- isVisible={warningVisible}
|
|
|
- onClose={() => setWarningVisible(false)}
|
|
|
- type="success"
|
|
|
+ type={modalInfo.type}
|
|
|
+ message={modalInfo.message}
|
|
|
action={() => {
|
|
|
- Platform.OS === 'ios' ? Linking.openURL('app-settings:') : Linking.openSettings();
|
|
|
- setWarningVisible(false);
|
|
|
+ modalInfo.action();
|
|
|
+ closeModal();
|
|
|
}}
|
|
|
- message="NomadMania app needs notification permissions to function properly. Open settings?"
|
|
|
/>
|
|
|
</PageWrapper>
|
|
|
);
|