|
@@ -10,11 +10,19 @@ import { ConnectionProvider } from 'src/contexts/ConnectionContext';
|
|
|
import ConnectionBanner from 'src/components/ConnectionBanner/ConnectionBanner';
|
|
|
import { RegionProvider } from 'src/contexts/RegionContext';
|
|
|
import { ErrorProvider, useError } from 'src/contexts/ErrorContext';
|
|
|
-import { useEffect } from 'react';
|
|
|
+import { useEffect, useState } from 'react';
|
|
|
import { setupInterceptors } from 'src/utils/request';
|
|
|
-import { ErrorModal } from 'src/components';
|
|
|
+import { ErrorModal, WarningModal } from 'src/components';
|
|
|
import { NotificationProvider } from 'src/contexts/NotificationContext';
|
|
|
import React from 'react';
|
|
|
+import { Linking, Platform } from 'react-native';
|
|
|
+import { API_URL, APP_VERSION } from 'src/constants';
|
|
|
+import axios from 'axios';
|
|
|
+import { API } from 'src/types';
|
|
|
+
|
|
|
+const IOS_STORE_URL = 'https://apps.apple.com/app/id6502843543';
|
|
|
+const ANDROID_STORE_URL =
|
|
|
+ 'https://play.google.com/store/apps/details?id=com.nomadmania.presentation';
|
|
|
|
|
|
const routingInstrumentation = Sentry.reactNavigationIntegration({
|
|
|
enableTimeToInitialDisplay: true
|
|
@@ -42,11 +50,39 @@ const App = () => {
|
|
|
const InnerApp = () => {
|
|
|
const errorContext = useError();
|
|
|
const navigation = React.useRef(null);
|
|
|
+ const [isUpdateAvailable, setIsUpdateAvailable] = useState(false);
|
|
|
|
|
|
useEffect(() => {
|
|
|
setupInterceptors(errorContext);
|
|
|
}, [errorContext]);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ const checkLatestVersion = async () => {
|
|
|
+ try {
|
|
|
+ const response = await axios.get(API_URL + '/' + API.LATEST_VERSION, {
|
|
|
+ headers: {
|
|
|
+ 'App-Version': APP_VERSION,
|
|
|
+ Platform: Platform.OS
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const { version } = response.data;
|
|
|
+
|
|
|
+ if (APP_VERSION !== version) {
|
|
|
+ setIsUpdateAvailable(true);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Failed to check latest version:', error);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ checkLatestVersion();
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const handleUpdatePress = () => {
|
|
|
+ const storeUrl = Platform.OS === 'ios' ? IOS_STORE_URL : ANDROID_STORE_URL;
|
|
|
+ Linking.openURL(storeUrl).catch((err) => console.error('Failed to open store URL:', err));
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<ConnectionProvider>
|
|
|
<RegionProvider>
|
|
@@ -59,6 +95,14 @@ const InnerApp = () => {
|
|
|
<Route />
|
|
|
<ConnectionBanner />
|
|
|
<ErrorModal />
|
|
|
+ <WarningModal
|
|
|
+ isVisible={isUpdateAvailable}
|
|
|
+ type="success"
|
|
|
+ title="Update Available"
|
|
|
+ message="A new version of the NomadMania app is available. Please update to the latest version."
|
|
|
+ action={handleUpdatePress}
|
|
|
+ onClose={() => setIsUpdateAvailable(false)}
|
|
|
+ />
|
|
|
</NavigationContainer>
|
|
|
</RegionProvider>
|
|
|
</ConnectionProvider>
|