diff --git a/types/AppUpdate.d.ts b/types/AppUpdate.d.ts new file mode 100644 index 00000000..d11aa079 --- /dev/null +++ b/types/AppUpdate.d.ts @@ -0,0 +1,5 @@ +interface AppUpdate { + version: string + update_type: string + updated_at: string +} diff --git a/utils/api.tsx b/utils/api.tsx index 352f60ed..5349cf0f 100644 --- a/utils/api.tsx +++ b/utils/api.tsx @@ -148,6 +148,11 @@ class Api { const resourceUrl = `${this.url}/users/info/${id}` return axios.get(resourceUrl) } + + version() { + const resourceUrl = `${this.url}/version` + return axios.get(resourceUrl) + } } const api: Api = new Api({ url: process.env.NEXT_PUBLIC_SIERO_API_URL || 'https://localhost:3000/api/v1'}) diff --git a/utils/appState.tsx b/utils/appState.tsx index 8dbc9c69..541bc0c2 100644 --- a/utils/appState.tsx +++ b/utils/appState.tsx @@ -67,6 +67,7 @@ interface AppState { jobs: Job[] jobSkills: JobSkill[] weaponKeys: GroupedWeaponKeys + version: AppUpdate } export const initialAppState: AppState = { @@ -127,6 +128,11 @@ export const initialAppState: AppState = { gauph: [], emblem: [], }, + version: { + version: '0.0', + update_type: '', + updated_at: new Date(), + }, } export const appState = proxy(initialAppState) diff --git a/utils/fetchLatestVersion.tsx b/utils/fetchLatestVersion.tsx new file mode 100644 index 00000000..7fff6cde --- /dev/null +++ b/utils/fetchLatestVersion.tsx @@ -0,0 +1,10 @@ +import api from './api' + +export default async function fetchLatestVersion() { + try { + const response = await api.version() + return response.data as AppUpdate + } catch (error) { + console.error(error) + } +}