Commit 897d2eda by Tonk

get connected device from firebase, add modal, ...update

parent 5d90726b
...@@ -12,6 +12,7 @@ export const GET_EXISTED_MCBLINKS_DATA = 'GET_EXISTED_MCBLINKS_DATA'; ...@@ -12,6 +12,7 @@ export const GET_EXISTED_MCBLINKS_DATA = 'GET_EXISTED_MCBLINKS_DATA';
export const GET_EXISTED_SUBBREAKERS_DATA = 'GET_EXISTED_SUBBREAKERS_DATA'; export const GET_EXISTED_SUBBREAKERS_DATA = 'GET_EXISTED_SUBBREAKERS_DATA';
export const GET_SELECTED_TIMER_DATA = 'GET_SELECTED_TIMER_DATA'; export const GET_SELECTED_TIMER_DATA = 'GET_SELECTED_TIMER_DATA';
export const SET_EDIT_MODAL_VISIBLE = 'SET_EDIT_MODAL_VISIBLE'; export const SET_EDIT_MODAL_VISIBLE = 'SET_EDIT_MODAL_VISIBLE';
export const GET_EXISTED_CONNECTED_DEVICE = 'GET_EXISTED_CONNECTED_DEVICE';
export const getTimersAction = allTimers => ({ export const getTimersAction = allTimers => ({
type: GET_TIMERS, type: GET_TIMERS,
...@@ -28,6 +29,11 @@ export const getExistedSubBreakersDataAction = existedSubBreakersData => ({ ...@@ -28,6 +29,11 @@ export const getExistedSubBreakersDataAction = existedSubBreakersData => ({
existedSubBreakersData, existedSubBreakersData,
}); });
export const getExistedConnectedDeviceAction = existedConnectedDevice => ({
type: GET_EXISTED_CONNECTED_DEVICE,
existedConnectedDevice,
});
export const getSelectedTimerDataAction = selectedTimerData => ({ export const getSelectedTimerDataAction = selectedTimerData => ({
type: GET_SELECTED_TIMER_DATA, type: GET_SELECTED_TIMER_DATA,
selectedTimerData, selectedTimerData,
...@@ -59,6 +65,7 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -59,6 +65,7 @@ export const getTimers = () => async (dispatch, getState) => {
let subBreakersTimers = []; let subBreakersTimers = [];
let existedMcbLinks = []; let existedMcbLinks = [];
let existedSubBreakers = []; let existedSubBreakers = [];
let existedConnectedDevice = [];
//main device section //main device section
/*-------------------------------------*/ /*-------------------------------------*/
...@@ -126,6 +133,31 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -126,6 +133,31 @@ export const getTimers = () => async (dispatch, getState) => {
}) })
) )
); );
await Promise.all(
selectedDeviceSubBreakersDetails.docs.map(async subBreaker => {
if (subBreaker.exists) {
//Electronic device section
/*-------------------------------------*/
const connectedDevices = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLink.id)
.collection('subBreakers')
.doc(subBreaker.id)
.collection('electronicDevices')
.get();
existedConnectedDevice.push(
connectedDevices.docs.map(connectedDevice =>
Object.assign(connectedDevice.data(), {
connectedDeviceId: connectedDevice.id,
})
)
);
}
})
);
await Promise.all( await Promise.all(
selectedDeviceSubBreakersDetails.docs.map(async subBreaker => { selectedDeviceSubBreakersDetails.docs.map(async subBreaker => {
...@@ -163,6 +195,7 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -163,6 +195,7 @@ export const getTimers = () => async (dispatch, getState) => {
dispatch(getExistedMcbLinksDataAction(existedMcbLinks)); dispatch(getExistedMcbLinksDataAction(existedMcbLinks));
dispatch(getExistedSubBreakersDataAction(existedSubBreakers)); dispatch(getExistedSubBreakersDataAction(existedSubBreakers));
dispatch(getExistedConnectedDeviceAction(existedConnectedDevice));
allTimersData = [...mainDeviceTimers, ...subBreakersTimers]; allTimersData = [...mainDeviceTimers, ...subBreakersTimers];
dispatch(getTimersAction(allTimersData)); dispatch(getTimersAction(allTimersData));
......
...@@ -6,12 +6,14 @@ import { ...@@ -6,12 +6,14 @@ import {
GET_EXISTED_SUBBREAKERS_DATA, GET_EXISTED_SUBBREAKERS_DATA,
GET_SELECTED_TIMER_DATA, GET_SELECTED_TIMER_DATA,
SET_EDIT_MODAL_VISIBLE, SET_EDIT_MODAL_VISIBLE,
GET_EXISTED_CONNECTED_DEVICE,
} from '../actions/timersAction'; } from '../actions/timersAction';
const initState = { const initState = {
allTimers: [], allTimers: [],
existedMcbLinksData: [], existedMcbLinksData: [],
existedSubBreakersData: [], existedSubBreakersData: [],
existedConnectedDevice: [],
selectedTimerData: null, selectedTimerData: null,
isEditVisible: false, isEditVisible: false,
isLoading: true, isLoading: true,
...@@ -34,7 +36,8 @@ const timersReducer = (state = initState, action) => { ...@@ -34,7 +36,8 @@ const timersReducer = (state = initState, action) => {
return { ...state, isLoading: action.isLoading }; return { ...state, isLoading: action.isLoading };
case GET_TIMERS_ERROR: case GET_TIMERS_ERROR:
return { ...state, error: action.error }; return { ...state, error: action.error };
case GET_EXISTED_CONNECTED_DEVICE:
return { ...state, existedConnectedDevice: action.existedConnectedDevice };
default: default:
return state; return state;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment