|
|
@ -7,7 +7,7 @@ import { |
|
|
|
} from '../../services/mobileWsType'; |
|
|
|
import Bridge from '../../utils/bridge'; |
|
|
|
import { RootState } from '..'; |
|
|
|
import { SettingDTO } from '../../services/apiTypes'; |
|
|
|
import { ReqStatus, SettingDTO } from '../../services/apiTypes'; |
|
|
|
|
|
|
|
interface ContextState { |
|
|
|
device: PeripheralStatus['data']; |
|
|
@ -21,6 +21,8 @@ interface ContextState { |
|
|
|
syncItems: Array<SyncItemFinish['data']>; |
|
|
|
|
|
|
|
setting: SettingDTO; |
|
|
|
settingReqStatus: ReqStatus; |
|
|
|
error: string | null; |
|
|
|
} |
|
|
|
|
|
|
|
const orgGwdXmStr = localStorage.getItem('org_gwd_xm'); |
|
|
@ -57,19 +59,21 @@ const initialState: ContextState = { |
|
|
|
server: '', |
|
|
|
standbyMinutes: 20, |
|
|
|
}, |
|
|
|
settingReqStatus: 'idle', |
|
|
|
error: null, |
|
|
|
}; |
|
|
|
|
|
|
|
export const fetchConfig = createAsyncThunk('context/fetchConfig', async () => { |
|
|
|
export const fetchConfig = createAsyncThunk('context/fetchConfig', async (_, thunkAPI) => { |
|
|
|
const conf = await Bridge.getConfig(); |
|
|
|
return conf.success ? conf.data : null; |
|
|
|
return conf.success ? conf.data : Promise.reject(conf.message); |
|
|
|
}); |
|
|
|
|
|
|
|
export const saveConfig = createAsyncThunk( |
|
|
|
'context/saveConfig', |
|
|
|
async (param: SettingDTO, thunkAPI) => { |
|
|
|
const res = await Bridge.saveConfig(param); |
|
|
|
res.success && thunkAPI.dispatch(fetchConfig()); |
|
|
|
return res; |
|
|
|
// res.success && thunkAPI.dispatch(fetchConfig());
|
|
|
|
return res.success ? res : Promise.reject(res.message); |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
@ -115,10 +119,26 @@ export const contextSlice = createSlice({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
extraReducers: (builder) => { |
|
|
|
builder.addCase(fetchConfig.pending, (state) => { |
|
|
|
state.settingReqStatus = 'loading'; |
|
|
|
}); |
|
|
|
builder.addCase(fetchConfig.fulfilled, (state, action) => { |
|
|
|
if (action.payload) { |
|
|
|
state.setting = action.payload; |
|
|
|
} |
|
|
|
state.setting = action.payload; |
|
|
|
state.settingReqStatus = 'succeeded'; |
|
|
|
}); |
|
|
|
builder.addCase(fetchConfig.rejected, (state, action) => { |
|
|
|
state.settingReqStatus = 'failed'; |
|
|
|
state.error = action.payload as string; |
|
|
|
}); |
|
|
|
builder.addCase(saveConfig.pending, (state) => { |
|
|
|
state.settingReqStatus = 'loading'; |
|
|
|
}); |
|
|
|
builder.addCase(saveConfig.fulfilled, (state, action) => { |
|
|
|
state.settingReqStatus = 'succeeded'; |
|
|
|
}); |
|
|
|
builder.addCase(saveConfig.rejected, (state, action) => { |
|
|
|
state.settingReqStatus = 'failed'; |
|
|
|
state.error = action.payload as string; |
|
|
|
}); |
|
|
|
builder.addCase(refreshSyncProgress.fulfilled, (state, action) => { |
|
|
|
if (action.payload) { |
|
|
|