forked from Abdulbari/sgeUpdated
Add 'sge-frontend/' from commit '5fa787e054b25ac53edc7ff0275ea7960a709401'
git-subtree-dir: sge-frontend git-subtree-mainline:876c278ac4git-subtree-split:5fa787e054
This commit is contained in:
15
sge-frontend/src/redux/reducers/accessToken/index.js
Normal file
15
sge-frontend/src/redux/reducers/accessToken/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const initialState = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const accessTokenReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_NEWACCESSTOKEN":
|
||||
return {
|
||||
...state,
|
||||
data: action.payload.newAccessToken,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default accessTokenReducer;
|
||||
68
sge-frontend/src/redux/reducers/answer/index.js
Normal file
68
sge-frontend/src/redux/reducers/answer/index.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const initialState = {
|
||||
answers: [],
|
||||
answersWithPaginate: [],
|
||||
};
|
||||
|
||||
const answersReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_ANSWERS":
|
||||
return {
|
||||
...state,
|
||||
answers: action.payload.answers,
|
||||
};
|
||||
case "GET_ANSWERS_WITH_PAGINATE":
|
||||
return {
|
||||
...state,
|
||||
answersWithPaginate: action.payload.answersWithPaginate,
|
||||
};
|
||||
|
||||
case "ADD_ANSWER":
|
||||
return {
|
||||
...state,
|
||||
answers: [...state.answers, action.payload.answers],
|
||||
answersWithPaginate: {
|
||||
...state.answersWithPaginate,
|
||||
content: [
|
||||
...state.answersWithPaginate.content,
|
||||
action.payload.answers,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
case "UPDATE_ANSWER":
|
||||
return {
|
||||
...state,
|
||||
answers: state.answers.map((answer) => {
|
||||
if (answer.id === action.payload.answers.id) {
|
||||
return action.payload.answers;
|
||||
}
|
||||
return answer;
|
||||
}),
|
||||
answersWithPaginate: {
|
||||
...state.answersWithPaginate,
|
||||
content: state.answersWithPaginate?.content.map((answer) => {
|
||||
if (answer.id === action.payload.answers?.id) {
|
||||
return action.payload.answers;
|
||||
}
|
||||
return answer;
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case "DELETE_ANSWER":
|
||||
return {
|
||||
...state,
|
||||
answers: state.answers.filter(
|
||||
(answer) => answer.id != action.payload.id
|
||||
),
|
||||
answersWithPaginate: {
|
||||
...state.answersWithPaginate,
|
||||
content: state.answersWithPaginate?.content.filter(
|
||||
(answer) => answer.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default answersReducer;
|
||||
69
sge-frontend/src/redux/reducers/areas/index.js
Normal file
69
sge-frontend/src/redux/reducers/areas/index.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const initialState = {
|
||||
areas: [],
|
||||
areasWithCriteria: [],
|
||||
areasWithPaginate: [],
|
||||
};
|
||||
|
||||
const areasReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_AREAS":
|
||||
return {
|
||||
...state,
|
||||
areas: action.payload.areas,
|
||||
};
|
||||
case "GET_AREAS_WITH_PAGINATE":
|
||||
return {
|
||||
...state,
|
||||
areasWithPaginate: action.payload.areasWithPaginate,
|
||||
};
|
||||
case "GET_AREAS_WITH_CRITERIA":
|
||||
return {
|
||||
...state,
|
||||
areasWithCriteria: action.payload.getAreasWithCriteria,
|
||||
};
|
||||
|
||||
case "ADD_AREA":
|
||||
return {
|
||||
...state,
|
||||
areas: [...state.areas, action.payload.areas],
|
||||
areasWithPaginate: {
|
||||
...state.areasWithPaginate,
|
||||
content: [...state.areasWithPaginate.content, action.payload.areas],
|
||||
},
|
||||
};
|
||||
|
||||
case "UPDATE_AREA":
|
||||
return {
|
||||
...state,
|
||||
areas: state.areas.map((area) => {
|
||||
if (area.id === action.payload.areas.id) {
|
||||
return action.payload.areas;
|
||||
}
|
||||
return area;
|
||||
}),
|
||||
areasWithPaginate: {
|
||||
...state.areasWithPaginate,
|
||||
content: state.areasWithPaginate?.content.map((area) => {
|
||||
if (area.id === action.payload.areas?.id) {
|
||||
return action.payload.areas;
|
||||
}
|
||||
return area;
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case "DELETE_AREA":
|
||||
return {
|
||||
...state,
|
||||
areas: state.areas.filter((area) => area.id != action.payload.id),
|
||||
areasWithPaginate: {
|
||||
...state.areasWithPaginate,
|
||||
content: state.areasWithPaginate?.content.filter(
|
||||
(area) => area.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default areasReducer;
|
||||
32
sge-frontend/src/redux/reducers/auth/index.js
Normal file
32
sge-frontend/src/redux/reducers/auth/index.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const initialState = {
|
||||
uid: null,
|
||||
user: null,
|
||||
isLoggedIn: false,
|
||||
accessToken: null,
|
||||
// refreshToken: null,
|
||||
}
|
||||
|
||||
const authReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case 'LOGIN':
|
||||
return {
|
||||
uid: action.payload.id,
|
||||
user: action.payload.user,
|
||||
isLoggedIn: true,
|
||||
accessToken: action.payload.accessToken,
|
||||
// refreshToken: action.payload.refreshToken,
|
||||
}
|
||||
case 'LOGOUT':
|
||||
return {
|
||||
uid: null,
|
||||
user: null,
|
||||
isLoggedIn: false,
|
||||
accessToken: null,
|
||||
// refreshToken: null,
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
export default authReducer
|
||||
28
sge-frontend/src/redux/reducers/cities/index.js
Normal file
28
sge-frontend/src/redux/reducers/cities/index.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const initialState = {
|
||||
cities: [],
|
||||
paginateCities: [],
|
||||
};
|
||||
|
||||
const citiesReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_CITIES":
|
||||
return {
|
||||
...state,
|
||||
cities: action.payload.cities,
|
||||
};
|
||||
|
||||
case "PAGINATE_CITIES":
|
||||
return {
|
||||
...state,
|
||||
paginateCities: action.payload.paginateCities,
|
||||
};
|
||||
|
||||
case "GET_CITIES_WITHOUT_COORDS":
|
||||
return {
|
||||
...state,
|
||||
cities: action.payload.cities,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default citiesReducer;
|
||||
15
sge-frontend/src/redux/reducers/city/index.js
Normal file
15
sge-frontend/src/redux/reducers/city/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const initialState = {
|
||||
city: [],
|
||||
};
|
||||
|
||||
const cityReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_CITY":
|
||||
return {
|
||||
...state,
|
||||
city: action.payload.city,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default cityReducer;
|
||||
15
sge-frontend/src/redux/reducers/country/index.js
Normal file
15
sge-frontend/src/redux/reducers/country/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const initialState = {
|
||||
countries: [],
|
||||
};
|
||||
|
||||
const countriesReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_COUNTRIES":
|
||||
return {
|
||||
...state,
|
||||
countries: action.payload.countries,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default countriesReducer;
|
||||
100
sge-frontend/src/redux/reducers/dataCenter/index.js
Normal file
100
sge-frontend/src/redux/reducers/dataCenter/index.js
Normal file
@@ -0,0 +1,100 @@
|
||||
const initialState = {
|
||||
dataCenters: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
creating: false,
|
||||
createError: null,
|
||||
updating: false,
|
||||
updateError: null,
|
||||
deleting: false,
|
||||
deleteError: null,
|
||||
total: 0
|
||||
};
|
||||
|
||||
const dataCenterReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_DATA_CENTERS_LOADING":
|
||||
return {
|
||||
...state,
|
||||
loading: true,
|
||||
error: null,
|
||||
};
|
||||
case "GET_DATA_CENTERS_SUCCESS":
|
||||
return {
|
||||
...state,
|
||||
dataCenters: action.payload.dataCenters,
|
||||
total: action.payload.total || action.payload.dataCenters.length,
|
||||
loading: false,
|
||||
error: null,
|
||||
};
|
||||
case "GET_DATA_CENTERS_ERROR":
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
error: action.payload.error,
|
||||
};
|
||||
case "CREATE_DATA_CENTER_LOADING":
|
||||
return {
|
||||
...state,
|
||||
creating: true,
|
||||
createError: null,
|
||||
};
|
||||
case "CREATE_DATA_CENTER_SUCCESS":
|
||||
return {
|
||||
...state,
|
||||
dataCenters: [...state.dataCenters, action.payload],
|
||||
creating: false,
|
||||
createError: null,
|
||||
};
|
||||
case "CREATE_DATA_CENTER_ERROR":
|
||||
return {
|
||||
...state,
|
||||
creating: false,
|
||||
createError: action.payload.error,
|
||||
};
|
||||
case "UPDATE_DATA_CENTER_LOADING":
|
||||
return {
|
||||
...state,
|
||||
updating: true,
|
||||
updateError: null,
|
||||
};
|
||||
case "UPDATE_DATA_CENTER_SUCCESS":
|
||||
return {
|
||||
...state,
|
||||
dataCenters: state.dataCenters.map(dc =>
|
||||
dc.id === action.payload.id ? action.payload : dc
|
||||
),
|
||||
updating: false,
|
||||
updateError: null,
|
||||
};
|
||||
case "UPDATE_DATA_CENTER_ERROR":
|
||||
return {
|
||||
...state,
|
||||
updating: false,
|
||||
updateError: action.payload.error,
|
||||
};
|
||||
case "DELETE_DATA_CENTER_LOADING":
|
||||
return {
|
||||
...state,
|
||||
deleting: true,
|
||||
deleteError: null,
|
||||
};
|
||||
case "DELETE_DATA_CENTER_SUCCESS":
|
||||
return {
|
||||
...state,
|
||||
dataCenters: state.dataCenters.filter(dc => dc.id !== action.payload.id),
|
||||
deleting: false,
|
||||
deleteError: null,
|
||||
};
|
||||
case "DELETE_DATA_CENTER_ERROR":
|
||||
return {
|
||||
...state,
|
||||
deleting: false,
|
||||
deleteError: action.payload.error,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default dataCenterReducer;
|
||||
58
sge-frontend/src/redux/reducers/datas/index.js
Normal file
58
sge-frontend/src/redux/reducers/datas/index.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const initialState = {
|
||||
sectors: [],
|
||||
sector: [],
|
||||
subSectors: [],
|
||||
subSector: [],
|
||||
activitySubUnits: [],
|
||||
consuptionUnits: [],
|
||||
emissionScopes: [],
|
||||
gpcReferences: [],
|
||||
mcfTypes: [],
|
||||
};
|
||||
|
||||
const datasReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_SECTORS":
|
||||
return {
|
||||
...state,
|
||||
sectors: action.payload.sectors,
|
||||
};
|
||||
case "GET_SECTOR_BY_ID":
|
||||
return {
|
||||
...state,
|
||||
sector: action.payload.sector,
|
||||
};
|
||||
case "GET_SUBSECTORS":
|
||||
return {
|
||||
...state,
|
||||
subSectors: action.payload.subSectors,
|
||||
};
|
||||
case "GET_SUBSECTOR_BY_ID":
|
||||
return {
|
||||
...state,
|
||||
subSector: action.payload.subSector || {},
|
||||
};
|
||||
case "GET_ACTIVITY_SUBUNITS":
|
||||
return {
|
||||
...state,
|
||||
activitySubUnits: action.payload.activitySubUnits,
|
||||
};
|
||||
case "GET_CONSUPTION_UNITS":
|
||||
return {
|
||||
...state,
|
||||
consuptionUnits: action.payload.consuptionUnits,
|
||||
};
|
||||
case "GET_GPC_REFERENCES":
|
||||
return {
|
||||
...state,
|
||||
gpcReferences: action.payload.gpcReferences,
|
||||
};
|
||||
case "GET_MCF_TYPES":
|
||||
return {
|
||||
...state,
|
||||
mcfTypes: action.payload.mcfTypes,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default datasReducer;
|
||||
15
sge-frontend/src/redux/reducers/district/index.js
Normal file
15
sge-frontend/src/redux/reducers/district/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const initialState = {
|
||||
district: [],
|
||||
};
|
||||
|
||||
const districtReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_DISTRICT":
|
||||
return {
|
||||
...state,
|
||||
district: action.payload.district,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default districtReducer;
|
||||
15
sge-frontend/src/redux/reducers/districts/index.js
Normal file
15
sge-frontend/src/redux/reducers/districts/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const initialState = {
|
||||
districts: [],
|
||||
};
|
||||
|
||||
const districtsReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_DISTRICTS":
|
||||
return {
|
||||
...state,
|
||||
districts: action.payload.districts,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default districtsReducer;
|
||||
79
sge-frontend/src/redux/reducers/emissionSources/index.js
Normal file
79
sge-frontend/src/redux/reducers/emissionSources/index.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const initialState = {
|
||||
emissionSources: [],
|
||||
emissionSourcesWithPaginate: [],
|
||||
emissionSource: [],
|
||||
};
|
||||
|
||||
const emissionSourceReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_EMISSION_SOURCES":
|
||||
return {
|
||||
...state,
|
||||
emissionSources: action.payload.emissionSources,
|
||||
};
|
||||
case "GET_EMISSION_SOURCES_WITH_PAGINATE":
|
||||
return {
|
||||
...state,
|
||||
emissionSourcesWithPaginate: action.payload.emissionSourcesWithPaginate,
|
||||
};
|
||||
case "ADD_EMISSION_SOURCE":
|
||||
return {
|
||||
...state,
|
||||
emissionSources: [
|
||||
...state.emissionSources,
|
||||
action.payload.emissionSource,
|
||||
],
|
||||
emissionSourcesWithPaginate: {
|
||||
...state.emissionSourcesWithPaginate,
|
||||
content: [
|
||||
...state.emissionSourcesWithPaginate.content,
|
||||
action.payload.emissionSource,
|
||||
],
|
||||
},
|
||||
};
|
||||
case "UPDATE_EMISSION_SOURCE" || "UPDATE_EMISSION_SOURCE_OF_WASTE":
|
||||
return {
|
||||
...state,
|
||||
emissionSources: [
|
||||
...state.emissionSources.map((emissionSource) => {
|
||||
if (emissionSource.id === action.payload.emissionSource.id) {
|
||||
return action.payload.emissionSource;
|
||||
}
|
||||
return emissionSource;
|
||||
}),
|
||||
],
|
||||
emissionSourcesWithPaginate: {
|
||||
...state.emissionSourcesWithPaginate,
|
||||
content: state.emissionSourcesWithPaginate?.content.map(
|
||||
(emissionSource) => {
|
||||
if (emissionSource.id === action.payload.emissionSource?.id) {
|
||||
return action.payload.emissionSource;
|
||||
}
|
||||
return emissionSource;
|
||||
}
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
case "DELETE_EMISSION_SOURCE":
|
||||
return {
|
||||
...state,
|
||||
emissionSources: [
|
||||
...state.emissionSources.filter(
|
||||
(emissionSource) => emissionSource.id != action.payload.id
|
||||
),
|
||||
],
|
||||
emissionSourcesWithPaginate: {
|
||||
...state.emissionSourcesWithPaginate,
|
||||
content: state.emissionSourcesWithPaginate?.content.filter(
|
||||
(emissionSource) => emissionSource.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default emissionSourceReducer;
|
||||
35
sge-frontend/src/redux/reducers/layout/index.js
Normal file
35
sge-frontend/src/redux/reducers/layout/index.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// ** ThemeConfig Import
|
||||
import themeConfig from "../../../configs/themeConfig";
|
||||
|
||||
// ** Returns Initial Menu Collapsed State
|
||||
const initialMenuCollapsed = () => {
|
||||
const item = window.localStorage.getItem('menuCollapsed')
|
||||
//** Parse stored json or if none return initialValue
|
||||
return item ? JSON.parse(item) : themeConfig.layout.menu.isCollapsed
|
||||
}
|
||||
|
||||
// ** Initial State
|
||||
const initialState = {
|
||||
isRTL: themeConfig.layout.isRTL,
|
||||
menuCollapsed: initialMenuCollapsed(),
|
||||
menuHidden: themeConfig.layout.menu.isHidden,
|
||||
contentWidth: themeConfig.layout.contentWidth
|
||||
}
|
||||
|
||||
const layoutReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case 'HANDLE_CONTENT_WIDTH':
|
||||
return { ...state, contentWidth: action.value }
|
||||
case 'HANDLE_MENU_COLLAPSED':
|
||||
window.localStorage.setItem('menuCollapsed', action.value)
|
||||
return { ...state, menuCollapsed: action.value }
|
||||
case 'HANDLE_MENU_HIDDEN':
|
||||
return { ...state, menuHidden: action.value }
|
||||
case 'HANDLE_RTL':
|
||||
return { ...state, isRTL: action.value }
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
export default layoutReducer
|
||||
66
sge-frontend/src/redux/reducers/mailSettings/index.js
Normal file
66
sge-frontend/src/redux/reducers/mailSettings/index.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const initialState = {
|
||||
currentSettings: null,
|
||||
|
||||
loading: false,
|
||||
error: null,
|
||||
success: false,
|
||||
}
|
||||
|
||||
const mailSettingsReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_MAIL_SETTINGS_PENDING":
|
||||
return {
|
||||
...state,
|
||||
loading: true,
|
||||
error: null,
|
||||
}
|
||||
case "GET_MAIL_SETTINGS_FULFILLED":
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
// Even if payload is null, we still want to set loading to false
|
||||
currentSettings: action.payload || null,
|
||||
}
|
||||
case "GET_MAIL_SETTINGS_REJECTED":
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
error: action.payload || "Failed to fetch mail settings",
|
||||
}
|
||||
case "UPDATE_MAIL_SETTINGS_PENDING":
|
||||
return {
|
||||
...state,
|
||||
loading: true,
|
||||
error: null,
|
||||
success: false,
|
||||
}
|
||||
case "UPDATE_MAIL_SETTINGS_FULFILLED":
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
currentSettings: action.payload,
|
||||
success: true,
|
||||
}
|
||||
case "UPDATE_MAIL_SETTINGS_REJECTED":
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
error: action.payload || "Failed to update mail settings",
|
||||
success: false,
|
||||
}
|
||||
case "CLEAR_MAIL_ERROR":
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
}
|
||||
case "CLEAR_MAIL_SUCCESS":
|
||||
return {
|
||||
...state,
|
||||
success: false,
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
export default mailSettingsReducer
|
||||
50
sge-frontend/src/redux/reducers/mainDataTables/index.js
Normal file
50
sge-frontend/src/redux/reducers/mainDataTables/index.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const initialState = {
|
||||
mainDataTables: [],
|
||||
mainDataTablesWithPaginate: null,
|
||||
vmEmissionSummary: null
|
||||
};
|
||||
|
||||
const mainDataTablesReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_MAIN_TABLES":
|
||||
return {
|
||||
...state,
|
||||
mainDataTables: action.payload.mainDataTables,
|
||||
};
|
||||
case "GET_MAIN_TABLES_WITH_PAGINATE":
|
||||
return {
|
||||
...state,
|
||||
mainDataTablesWithPaginate: action.payload.mainDataTablesWithPaginate,
|
||||
};
|
||||
case "GET_VM_EMISSION_SUMMARY":
|
||||
return {
|
||||
...state,
|
||||
vmEmissionSummary: action.payload.vmEmissionSummary,
|
||||
};
|
||||
case "ADD_DATA_INPUT":
|
||||
return {
|
||||
...state,
|
||||
mainDataTables: [...state.mainDataTables, action.payload.dataInput],
|
||||
};
|
||||
case "UPDATE_DATA_INPUT":
|
||||
return {
|
||||
...state,
|
||||
mainDataTables: state.mainDataTables.map((data) =>
|
||||
data.id === action.payload.dataInput.id
|
||||
? action.payload.dataInput
|
||||
: data
|
||||
),
|
||||
};
|
||||
case "DELETE_DATA_INPUT":
|
||||
return {
|
||||
...state,
|
||||
mainDataTables: state.mainDataTables.filter(
|
||||
(data) => data.id !== action.payload.id
|
||||
),
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default mainDataTablesReducer;
|
||||
53
sge-frontend/src/redux/reducers/neighborhoods/index.js
Normal file
53
sge-frontend/src/redux/reducers/neighborhoods/index.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const initialState = {
|
||||
neighborhoods: [],
|
||||
};
|
||||
|
||||
const neighborhoodsReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_NEIGHBORHOODS":
|
||||
return {
|
||||
...state,
|
||||
neighborhoods: action.payload.neighborhoods,
|
||||
};
|
||||
|
||||
case "ADD_NEIGHBORHOOD":
|
||||
return {
|
||||
...state,
|
||||
neighborhoods: {
|
||||
...state.neighborhoods,
|
||||
content: [
|
||||
...state.neighborhoods.content,
|
||||
action.payload.neighborhoods,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
case "UPDATE_NEIGHBORHOOD":
|
||||
return {
|
||||
...state,
|
||||
neighborhoods: {
|
||||
...state.neighborhoods,
|
||||
content: state.neighborhoods?.content.map((neighborhood) => {
|
||||
if (neighborhood.id === action.payload.neighborhoods?.id) {
|
||||
return action.payload.neighborhoods;
|
||||
}
|
||||
return neighborhood;
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case "DELETE_NEIGHBORHOOD":
|
||||
return {
|
||||
...state,
|
||||
neighborhoods: {
|
||||
...state.neighborhoods,
|
||||
content: state.neighborhoods?.content.filter(
|
||||
(neighborhood) => neighborhood.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
export default neighborhoodsReducer;
|
||||
39
sge-frontend/src/redux/reducers/notifications/index.js
Normal file
39
sge-frontend/src/redux/reducers/notifications/index.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const initialState = {
|
||||
getQuickNotifications: [],
|
||||
totalForQuick: 0,
|
||||
notifications: [],
|
||||
};
|
||||
|
||||
const notificationsReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_QUICKNOTIFICATIONS":
|
||||
return {
|
||||
...state,
|
||||
getQuickNotifications: action.payload.getQuickNotifications || [],
|
||||
totalForQuick: (action.payload.getQuickNotifications || []).filter(
|
||||
(notification) => notification.read === false
|
||||
).length,
|
||||
};
|
||||
|
||||
case "GET_SETNOTIFICATIONREAD":
|
||||
return {
|
||||
...state,
|
||||
setNotificationRead: action.payload.setNotificationRead,
|
||||
//totalForQuick: state.totalForQuick >= 1 ? state.totalForQuick - 1 : 0,
|
||||
};
|
||||
|
||||
case "GET_ALLNOTIFICATION":
|
||||
return {
|
||||
...state,
|
||||
notifications: action.payload.getAllNotifications || [],
|
||||
};
|
||||
|
||||
case "GET_NOTIFICATIONREMOVE":
|
||||
return {
|
||||
...state,
|
||||
notificationRemove: action.payload.notificationRemove,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default notificationsReducer;
|
||||
86
sge-frontend/src/redux/reducers/organisations/index.js
Normal file
86
sge-frontend/src/redux/reducers/organisations/index.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const initialState = {
|
||||
dataOrganization: [],
|
||||
organizationWithPaginate: [],
|
||||
organization: [],
|
||||
total: 0,
|
||||
};
|
||||
|
||||
const organisationReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_ORGANISATIONS":
|
||||
return {
|
||||
...state,
|
||||
dataOrganization: action.payload.organisations,
|
||||
total: action.payload.organisations.length,
|
||||
};
|
||||
case "GET_ORGANIZATIONS_WITH_PAGINATE":
|
||||
return {
|
||||
...state,
|
||||
organizationWithPaginate: action.payload.organizationsWithPaginate,
|
||||
};
|
||||
case "GET_ORGANISATION_BY_ID":
|
||||
return {
|
||||
...state,
|
||||
organization: action.payload.organisation,
|
||||
};
|
||||
case "ADD_ORGANIZATION":
|
||||
return {
|
||||
...state,
|
||||
dataOrganization: [
|
||||
...state.dataOrganization,
|
||||
action.payload.organisation,
|
||||
],
|
||||
organizationWithPaginate: {
|
||||
...state.organizationWithPaginate,
|
||||
content: [
|
||||
...state.organizationWithPaginate.content,
|
||||
action.payload.organisation,
|
||||
],
|
||||
},
|
||||
};
|
||||
case "UPDATE_ORGANIZATION":
|
||||
return {
|
||||
...state,
|
||||
dataOrganization: [
|
||||
...state.dataOrganization.map((organisation) => {
|
||||
if (organisation.id === action.payload.organisation.id) {
|
||||
return action.payload.organisation;
|
||||
}
|
||||
return organisation;
|
||||
}),
|
||||
],
|
||||
organizationWithPaginate: {
|
||||
...state.organizationWithPaginate,
|
||||
content: state.organizationWithPaginate?.content.map(
|
||||
(organization) => {
|
||||
if (organization.id === action.payload.organisation?.id) {
|
||||
return action.payload.organisation;
|
||||
}
|
||||
return organization;
|
||||
}
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
case "DELETE_ORGANIZATION":
|
||||
return {
|
||||
...state,
|
||||
dataOrganization: [
|
||||
...state.dataOrganization.filter(
|
||||
(organisation) => organisation.id != action.payload.id
|
||||
),
|
||||
],
|
||||
organizationWithPaginate: {
|
||||
...state.organizationWithPaginate,
|
||||
content: state.organizationWithPaginate?.content.filter(
|
||||
(organization) => organization.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default organisationReducer;
|
||||
20
sge-frontend/src/redux/reducers/permissions/index.js
Normal file
20
sge-frontend/src/redux/reducers/permissions/index.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const initialState = {
|
||||
permissions: [],
|
||||
};
|
||||
|
||||
const permissionsReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_PERMISSIONS":
|
||||
return {
|
||||
...state,
|
||||
permissions: action.payload.permissions,
|
||||
};
|
||||
case "GET_USERPERMISSIONS":
|
||||
return {
|
||||
...state,
|
||||
permissions: action.payload.userpermissions,
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default permissionsReducer;
|
||||
68
sge-frontend/src/redux/reducers/question/index.js
Normal file
68
sge-frontend/src/redux/reducers/question/index.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const initialState = {
|
||||
questions: [],
|
||||
questionsWithPaginate: [],
|
||||
};
|
||||
|
||||
const questionsReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_QUESTİONS":
|
||||
return {
|
||||
...state,
|
||||
questions: action.payload.questions,
|
||||
};
|
||||
case "GET_QUESTİONS_WITH_PAGINATE":
|
||||
return {
|
||||
...state,
|
||||
questionsWithPaginate: action.payload.questionsWithPaginate,
|
||||
};
|
||||
|
||||
case "ADD_QUESTİON":
|
||||
return {
|
||||
...state,
|
||||
questions: [...state.questions, action.payload.questions],
|
||||
questionsWithPaginate: {
|
||||
...state.questionsWithPaginate,
|
||||
content: [
|
||||
...state.questionsWithPaginate.content,
|
||||
action.payload.questions,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
case "UPDATE_QUESTİON":
|
||||
return {
|
||||
...state,
|
||||
questions: state.questions.map((question) => {
|
||||
if (question.id === action.payload.questions.id) {
|
||||
return action.payload.questions;
|
||||
}
|
||||
return question;
|
||||
}),
|
||||
questionsWithPaginate: {
|
||||
...state.questionsWithPaginate,
|
||||
content: state.questionsWithPaginate?.content.map((question) => {
|
||||
if (question.id === action.payload.questions?.id) {
|
||||
return action.payload.questions;
|
||||
}
|
||||
return question;
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case "DELETE_QUESTİON":
|
||||
return {
|
||||
...state,
|
||||
questions: state.questions.filter(
|
||||
(question) => question.id != action.payload.id
|
||||
),
|
||||
questionsWithPaginate: {
|
||||
...state.questionsWithPaginate,
|
||||
content: state.questionsWithPaginate?.content.filter(
|
||||
(question) => question.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
return state;
|
||||
};
|
||||
export default questionsReducer;
|
||||
59
sge-frontend/src/redux/reducers/roles/index.js
Normal file
59
sge-frontend/src/redux/reducers/roles/index.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const initialState = {
|
||||
roles: [],
|
||||
rolesWithPaginate: [],
|
||||
isError: false,
|
||||
};
|
||||
|
||||
const rolesReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_ROLES":
|
||||
return {
|
||||
...state,
|
||||
roles: action.payload.roles,
|
||||
isError: action.payload.errorStatus,
|
||||
};
|
||||
|
||||
case "GET_ROLES_WITH_PAGINATE":
|
||||
return {
|
||||
...state,
|
||||
rolesWithPaginate: action.payload.roles,
|
||||
};
|
||||
|
||||
case "ADD_ROLES":
|
||||
return {
|
||||
...state,
|
||||
rolesWithPaginate: {
|
||||
...state.roles,
|
||||
content: [...state.rolesWithPaginate.content, action.payload.roles],
|
||||
},
|
||||
};
|
||||
|
||||
case "UPDATE_ROLES":
|
||||
return {
|
||||
...state,
|
||||
rolesWithPaginate: {
|
||||
...state.roles,
|
||||
content: state.rolesWithPaginate?.content.map((role) => {
|
||||
if (role.id === action.payload.roles?.id) {
|
||||
return action.payload.roles;
|
||||
}
|
||||
return role;
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case "DELETE_ROLES":
|
||||
return {
|
||||
...state,
|
||||
rolesWithPaginate: {
|
||||
...state.rolesWithPaginate,
|
||||
content: state.rolesWithPaginate?.content.filter(
|
||||
(role) => role.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
export default rolesReducer;
|
||||
62
sge-frontend/src/redux/reducers/rootReducer.js
Normal file
62
sge-frontend/src/redux/reducers/rootReducer.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import { combineReducers } from "redux";
|
||||
import auth from "./auth";
|
||||
import layout from "./layout";
|
||||
import users from "./users";
|
||||
import user from "./user";
|
||||
import userProfileSettings from "./userProfileSettings";
|
||||
import organizations from "./organisations";
|
||||
import rolesReducer from "./roles";
|
||||
import permissionsReducer from "./permissions";
|
||||
import systemHistory from "./systemHistory";
|
||||
import userHistory from "./userHistory";
|
||||
import areas from "./areas";
|
||||
import countries from "./country";
|
||||
import cities from "./cities";
|
||||
import city from "./city";
|
||||
import districts from "./districts";
|
||||
import district from "./district";
|
||||
import neighborhoods from "./neighborhoods";
|
||||
import notifications from "./notifications";
|
||||
import accessToken from "./accessToken";
|
||||
import emissionSources from "./emissionSources";
|
||||
import datas from "./datas";
|
||||
import mainDataTables from "./mainDataTables";
|
||||
import questions from "./question";
|
||||
import answers from "./answer";
|
||||
import surveys from "./surveys";
|
||||
import uploads from "./upload";
|
||||
import mailSettings from "./mailSettings";
|
||||
import dataCenter from "./dataCenter";
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
accessToken,
|
||||
auth,
|
||||
layout,
|
||||
users,
|
||||
user,
|
||||
userProfileSettings,
|
||||
organizations,
|
||||
rolesReducer,
|
||||
permissionsReducer,
|
||||
systemHistory,
|
||||
userHistory,
|
||||
areas,
|
||||
countries,
|
||||
cities,
|
||||
city,
|
||||
districts,
|
||||
district,
|
||||
neighborhoods,
|
||||
notifications,
|
||||
emissionSources,
|
||||
datas,
|
||||
mainDataTables,
|
||||
questions,
|
||||
answers,
|
||||
surveys,
|
||||
uploads,
|
||||
mailSettings,
|
||||
dataCenter,
|
||||
});
|
||||
|
||||
export default rootReducer;
|
||||
127
sge-frontend/src/redux/reducers/surveys/index.js
Normal file
127
sge-frontend/src/redux/reducers/surveys/index.js
Normal file
@@ -0,0 +1,127 @@
|
||||
const initialState = {
|
||||
publishedSurvey: [],
|
||||
savedSurveys: [],
|
||||
survey: [],
|
||||
surveys: [],
|
||||
surveysWithPaginate: [],
|
||||
};
|
||||
|
||||
const surveysReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_SURVEY":
|
||||
return {
|
||||
...state,
|
||||
survey: action.payload.survey,
|
||||
};
|
||||
|
||||
case "PUBLİSHED_SURVEY":
|
||||
return {
|
||||
...state,
|
||||
publishedSurvey: action.payload.publishedSurvey,
|
||||
};
|
||||
case "GET_SURVEYS_WITH_PAGINATE":
|
||||
return {
|
||||
...state,
|
||||
surveysWithPaginate: action.payload.surveysWithPaginate,
|
||||
};
|
||||
|
||||
case "SAVED_SURVEYS_FROM_SURVEYS":
|
||||
return {
|
||||
...state,
|
||||
savedSurveysFromSurveys: action.payload.savedSurveysFromSurveys,
|
||||
};
|
||||
|
||||
case "SAVED_SURVEYS":
|
||||
return {
|
||||
...state,
|
||||
savedSurveys: action.payload.savedSurveys,
|
||||
};
|
||||
|
||||
case "ADD_SURVEY":
|
||||
return {
|
||||
...state,
|
||||
surveys: [...state.surveys, action.payload.surveys],
|
||||
surveysWithPaginate: {
|
||||
...state.surveysWithPaginate,
|
||||
content: [
|
||||
...state.surveysWithPaginate.content,
|
||||
action.payload.surveys,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
case "ADD_QUESTION_TO_SURVEY":
|
||||
return {
|
||||
...state,
|
||||
surveys: [
|
||||
...state.surveys.map((survey) => {
|
||||
if (survey.id === action.payload.surveys.id) {
|
||||
return action.payload.survey;
|
||||
}
|
||||
return survey;
|
||||
}),
|
||||
],
|
||||
surveysWithPaginate: {
|
||||
...state.surveysWithPaginate,
|
||||
content: state.surveysWithPaginate?.content.map((survey) => {
|
||||
if (survey.id === action.payload.surveys?.id) {
|
||||
return action.payload.surveys;
|
||||
}
|
||||
return survey;
|
||||
}),
|
||||
},
|
||||
};
|
||||
case "DELETE_QUESTİON_FROM_SURVEY":
|
||||
return {
|
||||
...state,
|
||||
surveys: state.surveys.filter(
|
||||
(survey) => survey.id != action.payload.id
|
||||
),
|
||||
surveysWithPaginate: {
|
||||
...state.surveysWithPaginate,
|
||||
content: state.surveysWithPaginate?.content.filter(
|
||||
(survey) => survey.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
/*
|
||||
case "UPDATE_QUESTİON":
|
||||
return {
|
||||
...state,
|
||||
questions: state.questions.map((question) => {
|
||||
if (question.id === action.payload.questions.id) {
|
||||
return action.payload.questions;
|
||||
}
|
||||
return question;
|
||||
}),
|
||||
questionsWithPaginate: {
|
||||
...state.questionsWithPaginate,
|
||||
content: state.questionsWithPaginate?.content.map((question) => {
|
||||
if (question.id === action.payload.questions?.id) {
|
||||
return action.payload.questions;
|
||||
}
|
||||
return question;
|
||||
}),
|
||||
},
|
||||
};
|
||||
*/
|
||||
|
||||
case "DELETE_SURVEY":
|
||||
return {
|
||||
...state,
|
||||
surveys: state.surveys.filter(
|
||||
(survey) => survey.id != action.payload.id
|
||||
),
|
||||
surveysWithPaginate: {
|
||||
...state.surveysWithPaginate,
|
||||
content: state.surveysWithPaginate?.content.filter(
|
||||
(survey) => survey.id != action.payload.id
|
||||
),
|
||||
},
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default surveysReducer;
|
||||
17
sge-frontend/src/redux/reducers/systemHistory/index.js
Normal file
17
sge-frontend/src/redux/reducers/systemHistory/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const initialState = {
|
||||
systemHistories: [],
|
||||
}
|
||||
|
||||
const systemHistoryReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_SYSTEMHISTORY":
|
||||
return {
|
||||
...state,
|
||||
systemHistories: action.payload.systemHistories,
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
export default systemHistoryReducer
|
||||
17
sge-frontend/src/redux/reducers/upload/index.js
Normal file
17
sge-frontend/src/redux/reducers/upload/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const initialState = {
|
||||
excelUpload: null,
|
||||
}
|
||||
|
||||
const uploadReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "EXCEL_UPLOAD":
|
||||
return {
|
||||
...state,
|
||||
excelUpload: action.payload.excelUpload,
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
export default uploadReducer
|
||||
30
sge-frontend/src/redux/reducers/user/index.js
Normal file
30
sge-frontend/src/redux/reducers/user/index.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const initialState = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const UserReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_USER":
|
||||
return {
|
||||
...state,
|
||||
data: action.payload.user,
|
||||
};
|
||||
|
||||
case "UPDATE_USERINFO":
|
||||
return {
|
||||
...state,
|
||||
data: state.data,
|
||||
};
|
||||
|
||||
case "UPDATE_PASSWORD":
|
||||
return {
|
||||
...state,
|
||||
data: state.data,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default UserReducer;
|
||||
17
sge-frontend/src/redux/reducers/userHistory/index.js
Normal file
17
sge-frontend/src/redux/reducers/userHistory/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const initialState = {
|
||||
userhistories: [],
|
||||
};
|
||||
|
||||
const userHistoryReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_USERHISTORY":
|
||||
return {
|
||||
...state,
|
||||
userHistories: action.payload.userhistories,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default userHistoryReducer;
|
||||
23
sge-frontend/src/redux/reducers/userProfileSettings/index.js
Normal file
23
sge-frontend/src/redux/reducers/userProfileSettings/index.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const initialState = {
|
||||
userProfileSettings: [],
|
||||
};
|
||||
|
||||
const userProfileSettings = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_USERPROFILESETTING":
|
||||
return {
|
||||
...state,
|
||||
userProfileSettings: action.payload.getUserProfileSettings,
|
||||
};
|
||||
|
||||
case "UPDATE_USERPROFILESETTING":
|
||||
return {
|
||||
...state,
|
||||
userProfileSettings: action.payload.data,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default userProfileSettings;
|
||||
53
sge-frontend/src/redux/reducers/users/index.js
Normal file
53
sge-frontend/src/redux/reducers/users/index.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const initialState = {
|
||||
data: [],
|
||||
total: 0,
|
||||
};
|
||||
|
||||
const DataTablesReducer = (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case "GET_USERS":
|
||||
return {
|
||||
...state,
|
||||
data: action.payload.users,
|
||||
total: action.payload.users?.content?.length,
|
||||
};
|
||||
case "ADD_USER":
|
||||
return {
|
||||
...state,
|
||||
data: {
|
||||
...state.data,
|
||||
content: [...state.data.content, action.payload.data],
|
||||
},
|
||||
total: state.total + 1,
|
||||
};
|
||||
case "DELETE_USER":
|
||||
return {
|
||||
...state,
|
||||
data: {
|
||||
...state.data,
|
||||
content: state.data?.content.filter(
|
||||
(user) => user.id != action.payload.id
|
||||
),
|
||||
},
|
||||
total: state.total - 1,
|
||||
};
|
||||
|
||||
case "UPDATE_USER":
|
||||
return {
|
||||
...state,
|
||||
data: {
|
||||
...state.data,
|
||||
content: state.data?.content.map((user) => {
|
||||
if (user.id === action.payload.data?.id) {
|
||||
return action.payload.data;
|
||||
}
|
||||
return user;
|
||||
}),
|
||||
},
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default DataTablesReducer;
|
||||
Reference in New Issue
Block a user