diff --git a/src/appredux/actions.js b/src/appredux/actions.js index 1052d41..37fe8a8 100644 --- a/src/appredux/actions.js +++ b/src/appredux/actions.js @@ -1,22 +1,7 @@ -/* -* All actions should be import and exported first -* to make components / pages are easy to use -*/ +// user actions +export * from './modules/user/actions'; -import { - setIsLogin, - setUser, - setFcmToken, - setChosenLanguage, - setRegister -} from './modules/user/actions'; +// theme actions +export * from './modules/theme/actions'; - - -export { - setIsLogin, - setUser, - setFcmToken, - setChosenLanguage, - setRegister -} \ No newline at end of file +export * from './modules/incidentReport/actions' diff --git a/src/appredux/modules/incidentReport/actions.js b/src/appredux/modules/incidentReport/actions.js new file mode 100644 index 0000000..c4f0af2 --- /dev/null +++ b/src/appredux/modules/incidentReport/actions.js @@ -0,0 +1,115 @@ +// Action Types +export const SET_INCIDENT_DATE = 'SET_INCIDENT_DATE'; +export const SET_INCIDENT_TIME = 'SET_INCIDENT_TIME'; +export const SET_REPORT_DATE = 'SET_REPORT_DATE'; +export const SET_REPORT_TIME = 'SET_REPORT_TIME'; +export const SET_AREA = 'SET_AREA'; +export const SET_DATA_RECEPIENT = 'SET_DATA_RECEPIENT'; +export const SET_DATA_REPORTER = 'SET_DATA_REPORTER'; +export const SET_INCIDENT_LOCATION = 'SET_INCIDENT_LOCATION'; +export const SET_REPORT_LOCATION = 'SET_REPORT_LOCATION'; +export const SET_DATA_INCIDENT = 'SET_DATA_INCIDENT'; +export const SET_DATA_ACHIEVEMENT = 'SET_DATA_ACHIEVEMENT'; +export const SET_DATA_TYPE_RISK = 'SET_DATA_TYPE_RISK'; +export const SET_INCIDENT_RISK_POTENTIAL = 'SET_INCIDENT_RISK_POTENTIAL'; +export const SET_RISK_LEVEL = 'SET_RISK_LEVEL'; +export const SET_ROOT_CASE = 'SET_ROOT_CASE'; +export const SET_CHRONOLOGY = 'SET_CHRONOLOGY'; +export const SET_DATA_PREVENTION = 'SET_DATA_PREVENTION'; +export const SET_DATA_IMAGES = 'SET_DATA_IMAGES'; +export const RESET_INCIDENT_REPORT = 'RESET_INCIDENT_REPORT'; +// Action Creators +export const setIncidentDate = (date) => ({ + type: SET_INCIDENT_DATE, + payload: date, +}); + +export const setIncidentTime = (time) => ({ + type: SET_INCIDENT_TIME, + payload: time, +}); + +export const setReportDate = (date) => ({ + type: SET_REPORT_DATE, + payload: date, +}); + +export const setReportTime = (time) => ({ + type: SET_REPORT_TIME, + payload: time, +}); + +export const setArea = (area) => ({ + type: SET_AREA, + payload: area, +}); + +export const setDataRecepient = (data) => ({ + type: SET_DATA_RECEPIENT, + payload: data, +}); + +export const setDataReporter = (data) => ({ + type: SET_DATA_REPORTER, + payload: data, +}); + +export const setIncidentLocation = (location) => ({ + type: SET_INCIDENT_LOCATION, + payload: location, +}); + +export const setReportLocation = (location) => ({ + type: SET_REPORT_LOCATION, + payload: location, +}); + +export const setDataIncident = (data) => ({ + type: SET_DATA_INCIDENT, + payload: data, +}); + +export const setDataAchievement = (data) => ({ + type: SET_DATA_ACHIEVEMENT, + payload: data, +}); + +export const setDataTypeRisk = (data) => ({ + type: SET_DATA_TYPE_RISK, + payload: data, +}); + +export const setIncidentRiskPotential = (data) => ({ + type: SET_INCIDENT_RISK_POTENTIAL, + payload: data, +}); + +export const setRiskLevel = (data) => ({ + type: SET_RISK_LEVEL, + payload: data, +}); + +export const setChronology = (data) => ({ + type: SET_CHRONOLOGY, + payload: data, +}); + +export const setRootCase = (data) => ({ + type: SET_ROOT_CASE, + payload: data, +}); + +export const setDataPrevention = (data) => ({ + type: SET_DATA_PREVENTION, + payload: data, +}); + +export const setImages = (images) => ({ + type: SET_DATA_IMAGES, + payload: images, +}); + + +export const resetIncidentReport = () => ({ + type: RESET_INCIDENT_REPORT, +}); diff --git a/src/appredux/modules/incidentReport/reducers.js b/src/appredux/modules/incidentReport/reducers.js new file mode 100644 index 0000000..0169fba --- /dev/null +++ b/src/appredux/modules/incidentReport/reducers.js @@ -0,0 +1,89 @@ +import { + SET_INCIDENT_DATE, + SET_INCIDENT_TIME, + SET_REPORT_DATE, + SET_REPORT_TIME, + SET_AREA, + SET_DATA_RECEPIENT, + SET_DATA_REPORTER, + SET_INCIDENT_LOCATION, + SET_REPORT_LOCATION, + SET_DATA_INCIDENT, + SET_DATA_ACHIEVEMENT, + SET_DATA_TYPE_RISK, + RESET_INCIDENT_REPORT, + SET_CHRONOLOGY, + SET_ROOT_CASE, + SET_INCIDENT_RISK_POTENTIAL, + SET_RISK_LEVEL, + SET_DATA_PREVENTION, + SET_DATA_IMAGES +} from './actions'; + +const initialState = { + area: { external: false, internal: false }, + chronology: null, + dataAchievement: [], + dataIncidentReport: [], + dataPrevention: [], + dataRecipient: { name: "", noContact: "", position: "" }, + dataReporter: { name: "", noContact: "", position: "" }, + incidentDate: null, + incidentLocation: { location: "", subLocation: "" }, + incidentRiskPotential: { impact: "", impactDescription: "", likelihood: "", likelihoodDescription: "", value: "" }, + incidentTime: null, + dataImage: [], + reportDate: null, + reportLocation: { projectLocation: "", reportLocation: "", subLocation: "" }, + reportTime: null, + riskLevel: { backgroundColor: "", color: "", level: "" }, + rootCase: null, + typeRiskIncident: null, +}; + + + +export default function incidentReportReducer(state = initialState, action) { + switch (action.type) { + case SET_INCIDENT_DATE: + return { ...state, incidentDate: action.payload }; + case SET_INCIDENT_TIME: + return { ...state, incidentTime: action.payload }; + case SET_REPORT_DATE: + return { ...state, reportDate: action.payload }; + case SET_REPORT_TIME: + return { ...state, reportTime: action.payload }; + case SET_AREA: + return { ...state, area: action.payload }; + case SET_DATA_RECEPIENT: + return { ...state, dataRecipient: { ...state.dataRecipient, ...action.payload } }; + case SET_DATA_REPORTER: + return { ...state, dataReporter: { ...state.dataReporter, ...action.payload } }; + case SET_INCIDENT_LOCATION: + return { ...state, incidentLocation: { ...state.incidentLocation, ...action.payload } }; + case SET_REPORT_LOCATION: + return { ...state, reportLocation: { ...state.reportLocation, ...action.payload } }; + case SET_DATA_INCIDENT: + return { ...state, dataIncidentReport: action.payload }; + case SET_DATA_ACHIEVEMENT: + return { ...state, dataAchievement: action.payload }; + case SET_DATA_TYPE_RISK: + return { ...state, typeRiskIncident: action.payload }; + case SET_INCIDENT_RISK_POTENTIAL: + return { ...state, incidentRiskPotential: action.payload }; + case SET_RISK_LEVEL: + return { ...state, riskLevel: action.payload }; + case SET_CHRONOLOGY: + return { ...state, chronology: action.payload }; + case SET_ROOT_CASE: + return { ...state, rootCase: action.payload }; + case SET_DATA_PREVENTION: + return { ...state, dataPrevention: action.payload }; + case SET_DATA_IMAGES: + return { ...state, dataImage: action.payload }; + case RESET_INCIDENT_REPORT: + return initialState; + default: + return state; + } +} diff --git a/src/appredux/modules/user/actions.js b/src/appredux/modules/user/actions.js index 0f85d32..b8241fa 100644 --- a/src/appredux/modules/user/actions.js +++ b/src/appredux/modules/user/actions.js @@ -25,12 +25,12 @@ export const setFcmToken = obj => dispatch => { }) } -export const setChosenLanguage = obj => dispatch => { +export const setChosenLanguage = (language) => dispatch => { dispatch({ type: SET_CHOSEN_LANGUAGE, - payload: obj - }) -} + payload: language + }); +}; export const setRegister = obj => dispatch => { dispatch({ diff --git a/src/appredux/modules/user/reducers.js b/src/appredux/modules/user/reducers.js index 63076b7..65ea723 100644 --- a/src/appredux/modules/user/reducers.js +++ b/src/appredux/modules/user/reducers.js @@ -6,27 +6,26 @@ import { SET_REGISTER } from "./actions"; - const initialState = { isLogin: false, - user: null, // the payload after request login to API + user: null, fcmToken: null, - chosenLanguage: 'en', // id / en + chosenLanguage: 'id', isRegister: false -} +}; function userReducer(state = initialState, action) { switch (action.type) { case SET_IS_LOGIN: - return { ...state, isLogin: action.payload } + return { ...state, isLogin: action.payload }; case SET_USER: - return { ...state, user: action.payload } + return { ...state, user: action.payload }; case SET_FCM_TOKEN: - return { ...state, fcmToken: action.payload } + return { ...state, fcmToken: action.payload }; case SET_CHOSEN_LANGUAGE: - return { ...state, chosenLanguage: action.payload } + return { ...state, chosenLanguage: action.payload }; case SET_REGISTER: - return { ...state, isRegister: action.payload } + return { ...state, isRegister: action.payload }; default: return state; } diff --git a/src/appredux/reducers.js b/src/appredux/reducers.js index 5db5844..483de3f 100644 --- a/src/appredux/reducers.js +++ b/src/appredux/reducers.js @@ -4,10 +4,14 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; // modules import userReducer from './modules/user/reducers'; +import themeReducer from './modules/theme/reducers'; +import incidentReportReducer from './modules/incidentReport/reducers' const rootReducer = combineReducers({ - userReducer + userReducer, + themeReducer, + incidentReportReducer }); const appReducer = (state, action) => {