Browse Source
Reviewed-on: #2 Co-authored-by: Oksana Stepanenko <oksana.stepanenko@jetup.team> Co-committed-by: Oksana Stepanenko <oksana.stepanenko@jetup.team>pull/4/head
14 changed files with 173 additions and 41 deletions
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
import { ApiResponse } from '../http.types' |
||||
import { IActualAppVersionResp } from './responses.interfaces' |
||||
import http from '../http.service' |
||||
|
||||
export const fetchActualAppVersionReq = ( |
||||
platform: string, |
||||
): ApiResponse<IActualAppVersionResp> => { |
||||
return http.get<IActualAppVersionResp>('system/app-version', { |
||||
params: { platform }, |
||||
}) |
||||
} |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
export interface IActualAppVersionResp { |
||||
version: string |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
import { fetchActualAppVersionReq } from '@/api' |
||||
import { appEvents } from '@/shared' |
||||
import { DeviceInfoService } from './device-info.service' |
||||
import { Linking, Platform } from 'react-native' |
||||
import { config } from '@/config' |
||||
import { simpleDispatch } from '@/store/store-helpers' |
||||
import { SetActualAppVersion } from '@/store/shared' |
||||
|
||||
const updateApp = () => { |
||||
const link = Platform.select({ |
||||
ios: config.appStoreUrl, |
||||
android: config.googlePlayUrl, |
||||
}) |
||||
Linking.canOpenURL(link) |
||||
.then(supported => supported && Linking.openURL(link)) |
||||
.catch(() => |
||||
appEvents.emit('openInfoModal', { |
||||
title: 'Сталась помилка!', |
||||
message: 'Спробуйте будь-ласка пізніше.', |
||||
onPressOk: () => {}, |
||||
}), |
||||
) |
||||
} |
||||
|
||||
const loadActualAppVersion = async () => { |
||||
try { |
||||
const { data } = await fetchActualAppVersionReq(Platform.OS) |
||||
if (data) { |
||||
const currentAppVersion = DeviceInfoService.getAppVersion() |
||||
|
||||
simpleDispatch(new SetActualAppVersion(data)) |
||||
|
||||
if (data.version !== currentAppVersion) |
||||
setTimeout(() => { |
||||
appEvents.emit('openConfirmModal', { |
||||
title: 'Доступна нова версія додатку. Бажаєте оновити зараз?', |
||||
buttonToHighlight: 'notAllow', |
||||
allowBtnAction: () => { |
||||
setTimeout(() => { |
||||
updateApp() |
||||
}, 300) |
||||
}, |
||||
notAllowBtnAction: () => {}, |
||||
}) |
||||
}, 1500) |
||||
} |
||||
} catch (e) { |
||||
console.log('Error on load actual app version', e) |
||||
} |
||||
} |
||||
|
||||
export const appInfoService = { |
||||
loadActualAppVersion, |
||||
updateApp, |
||||
} |
Loading…
Reference in new issue