Skip to content

Commit 98926ca

Browse files
committed
fixed redux issues
1 parent 0129621 commit 98926ca

File tree

4 files changed

+48
-44
lines changed

4 files changed

+48
-44
lines changed

client/hooks/useFetchKeyData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useEffect } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
3-
import { fetchKeyData } from '../util/slices/keyDataSlicer'
3+
import { fetchKeyData } from '../util/redux/keyDataReducer'
44
import { RootState } from '../util/store'
55

66
const useFetchKeyData = () => {
77
const dispatch = useDispatch()
8-
const keyData = useSelector((state: RootState) => state.keyData)
8+
const keyData = useSelector((state: RootState) => state.keyData.data)
99

1010
useEffect(() => {
1111
dispatch(fetchKeyData())

client/util/redux/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import faculties from './facultyReducer'
1717
import summaries from './summaryReducer'
1818
import reformAnswers from './reformAnswerReducer'
1919
import monitoring from './facultyMonitoringReducer'
20+
import keyData from './keyDataReducer'
2021

2122
export default combineReducers({
2223
form,
@@ -36,4 +37,5 @@ export default combineReducers({
3637
summaries,
3738
reformAnswers,
3839
monitoring,
40+
keyData,
3941
})
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import callBuilder from '../apiConnection'
2+
interface State {
3+
data: any;
4+
pending?: boolean;
5+
error?: boolean;
6+
}
7+
8+
interface Action {
9+
type: string;
10+
response?: any;
11+
}
12+
13+
export const fetchKeyData = () => {
14+
const route = '/keyData'
15+
const prefix = 'GET_KEY_DATA'
16+
return callBuilder(route, prefix)
17+
}
18+
19+
export default (state: State = { data: null }, action: Action) => {
20+
switch (action.type) {
21+
case 'GET_KEY_DATA_ATTEMPT':
22+
return {
23+
...state,
24+
pending: true,
25+
error: false,
26+
}
27+
case 'GET_KEY_DATA_SUCCESS':
28+
return {
29+
...state,
30+
data: action.response,
31+
pending: false,
32+
error: false,
33+
}
34+
case 'GET_KEY_DATA_FAILURE':
35+
return {
36+
...state,
37+
data: [],
38+
pending: false,
39+
error: true,
40+
}
41+
default:
42+
return state
43+
}
44+
}

client/util/slices/keyDataSlicer.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)