|
@@ -1,4 +1,5 @@
|
|
-import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
|
|
|
+import { createSlice, PayloadAction, createAsyncThunk } from '@reduxjs/toolkit';
|
|
|
|
+import { fetchSoftwareInfo } from '../API/softwareInfo';
|
|
|
|
|
|
interface ProductState {
|
|
interface ProductState {
|
|
productName: 'DROS' | 'VETDROS';
|
|
productName: 'DROS' | 'VETDROS';
|
|
@@ -12,6 +13,18 @@ const initialState: ProductState = {
|
|
source: 'Browser',
|
|
source: 'Browser',
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+export const initializeProductState = createAsyncThunk(
|
|
|
|
+ 'product/initializeProductState',
|
|
|
|
+ async () => {
|
|
|
|
+ const softwareInfo = await fetchSoftwareInfo();
|
|
|
|
+ return {
|
|
|
|
+ productName: softwareInfo.product as 'DROS' | 'VETDROS',
|
|
|
|
+ language: softwareInfo.language[0],
|
|
|
|
+ source: 'Browser' as const,
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+);
|
|
|
|
+
|
|
const productSlice = createSlice({
|
|
const productSlice = createSlice({
|
|
name: 'product',
|
|
name: 'product',
|
|
initialState,
|
|
initialState,
|
|
@@ -22,6 +35,21 @@ const productSlice = createSlice({
|
|
state.source = action.payload.source;
|
|
state.source = action.payload.source;
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
+ extraReducers: (builder) => {
|
|
|
|
+ builder
|
|
|
|
+ .addCase(initializeProductState.fulfilled, (state, action) => {
|
|
|
|
+ state.productName = action.payload.productName;
|
|
|
|
+ state.language = action.payload.language;
|
|
|
|
+ state.source = action.payload.source;
|
|
|
|
+ })
|
|
|
|
+ .addCase(initializeProductState.rejected, (state, action) => {
|
|
|
|
+ console.error(
|
|
|
|
+ 'Failed to initialize product state:',
|
|
|
|
+ action.error,
|
|
|
|
+ state
|
|
|
|
+ );
|
|
|
|
+ });
|
|
|
|
+ },
|
|
});
|
|
});
|
|
|
|
|
|
export const { setProduct } = productSlice.actions;
|
|
export const { setProduct } = productSlice.actions;
|