import React, { useState } from 'react';
import { View, Image, Linking, Text } from 'react-native';
import { CommonActions, useNavigation } from '@react-navigation/native';
import { WarningModal } from '../WarningModal';
import { MenuButton } from '../MenuButton';
import { styles } from './styles';
import { StoreType, storage } from 'src/storage';
import { useDeleteUserMutation } from '@api/app';
import { Colors } from 'src/theme';
import { NAVIGATION_PAGES } from 'src/types';
import MailIcon from '../../../assets/icons/mail.svg';
import DocumentIcon from '../../../assets/icons/document.svg';
import ExitIcon from '../../../assets/icons/exit.svg';
import UserXMark from '../../../assets/icons/user-xmark.svg';
import InfoIcon from 'assets/icons/info-solid.svg';
import BellIcon from 'assets/icons/notifications/bell-solid.svg';
import SharingIcon from 'assets/icons/location-sharing.svg';
import { APP_VERSION, FASTEST_MAP_HOST } from 'src/constants';
import { useNotification } from 'src/contexts/NotificationContext';
import { useMessagesStore } from 'src/stores/unreadMessagesStore';
import { SafeAreaView } from 'react-native-safe-area-context';
import { usePostIsFeatureActiveQuery } from '@api/location';
export const MenuDrawer = (props: any) => {
const { mutate: deleteUser } = useDeleteUserMutation();
const token = storage.get('token', StoreType.STRING) as string;
const { data: isFeatureActive } = usePostIsFeatureActiveQuery(token, !!token);
const navigation = useNavigation();
const [modalInfo, setModalInfo] = useState({
visible: false,
type: 'confirm',
message: '',
action: () => {}
});
const { updateNotificationStatus } = useNotification();
const updateUnreadMessagesCount = useMessagesStore((state) => state.updateUnreadMessagesCount);
const openModal = (type: string, message: string, action: any) => {
setModalInfo({
visible: true,
type,
message,
action
});
};
const closeModal = () => {
setModalInfo({ ...modalInfo, visible: false });
};
const handleLogout = () => {
storage.remove('token');
storage.remove('uid');
storage.remove('currentUserData');
storage.remove('showNomads');
storage.remove('filterSettings');
updateNotificationStatus();
updateUnreadMessagesCount();
navigation.dispatch(
CommonActions.reset({
index: 1,
routes: [{ name: NAVIGATION_PAGES.WELCOME }]
})
);
};
const handleDeleteAccount = () => {
deleteUser({ token }, { onSuccess: handleLogout });
};
return (
<>
}
red={false}
buttonFn={() => navigation.navigate(NAVIGATION_PAGES.INFO as never)}
/>
}
red={false}
buttonFn={() => Linking.openURL('https://nomadmania.com/contact/')}
/>
}
red={false}
buttonFn={() => Linking.openURL('https://nomadmania.com/terms/')}
/>
{token && (
}
red={false}
buttonFn={() =>
// todo: add types
// @ts-ignore
navigation.navigate(NAVIGATION_PAGES.MENU_DRAWER, {
screen: NAVIGATION_PAGES.NOTIFICATIONS
})
}
/>
)}
{isFeatureActive && isFeatureActive.active && (
}
red={false}
buttonFn={() =>
// @ts-ignore
navigation.navigate(NAVIGATION_PAGES.MENU_DRAWER, {
screen: NAVIGATION_PAGES.LOCATION_SHARING
})
}
/>
)}
{token ? (
<>
}
red={true}
buttonFn={() =>
openModal('confirm', 'Are you sure you want to logout?', handleLogout)
}
/>
}
red={true}
buttonFn={() =>
openModal(
'confirm',
'Are you sure you want to delete your account?',
handleDeleteAccount
)
}
/>
>
) : null}
Version {APP_VERSION}
Map server:{'\n'}
{FASTEST_MAP_HOST}
{
modalInfo.action();
closeModal();
}}
/>
>
);
};