| @@ -23,8 +23,8 @@ import ConfirmDialog from "../../components/MUI/ConfirmDialog"; | |||
| import { useTranslation } from "react-i18next"; | |||
| import { USER_DETAILS_LOADING } from "../../store/actions/users/usersActionConstants"; | |||
| import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors"; | |||
| import { selectCategories } from "../../store/selectors/categoriesSelector"; | |||
| import { setCategoriesReq } from "../../store/actions/categories/categoriesAction"; | |||
| import { selectIsCategoriesChecked } from "../../store/selectors/categoriesSelector"; | |||
| import { setIsCategoriesCheckedReq } from "../../store/actions/categories/categoriesAction"; | |||
| const UserDetails = ({ history }) => { | |||
| const theme = useTheme(); | |||
| @@ -35,7 +35,7 @@ const UserDetails = ({ history }) => { | |||
| const [showReset, setReset] = useState(false); | |||
| const [showDelete, setDelete] = useState(false); | |||
| const { t } = useTranslation(); | |||
| const categories = useSelector(selectCategories); | |||
| const categories = useSelector(selectIsCategoriesChecked); | |||
| const { user, errorMessage } = useSelector((s) => s.userDetails); | |||
| @@ -49,8 +49,10 @@ const UserDetails = ({ history }) => { | |||
| }; | |||
| useEffect(() => { | |||
| dispatch(setCategoriesReq()); | |||
| }, []); | |||
| if(id){ | |||
| dispatch(setIsCategoriesCheckedReq({userId:id})); | |||
| } | |||
| }, [id]); | |||
| const handleApiResponseSuccessReset = () => { | |||
| setReset(false); | |||
| @@ -71,6 +71,7 @@ export default { | |||
| }, | |||
| categories: { | |||
| allCategories: base + "/categories/names", | |||
| isCategoriesChecked: base + "/categories/granted-categories" | |||
| }, | |||
| tags: { | |||
| allTags: base + "/tags/names", | |||
| @@ -3,3 +3,6 @@ import apiEndpoints from "./apiEndpoints"; | |||
| export const getAllCategories = () => | |||
| getRequest(apiEndpoints.categories.allCategories); | |||
| export const getIsCategoriesChecked = (userId) => | |||
| getRequest(apiEndpoints.categories.isCategoriesChecked + "?userId=" + userId); | |||
| @@ -2,6 +2,9 @@ import { | |||
| FETCH_CATEGORIES_REQ, | |||
| FETCH_CATEGORIES_SUCCESS, | |||
| FETCH_CATEGORIES_ERR, | |||
| FETCH_IS_CATEGORIES_CHECKED_ERR, | |||
| FETCH_IS_CATEGORIES_CHECKED_REQ, | |||
| FETCH_IS_CATEGORIES_CHECKED_SUCCESS | |||
| } from "./categoriesActionConstants"; | |||
| export const setCategoriesReq = () => ({ | |||
| @@ -17,3 +20,19 @@ export const setCategories = (payload) => ({ | |||
| type: FETCH_CATEGORIES_SUCCESS, | |||
| payload, | |||
| }); | |||
| export const setIsCategoriesCheckedReq = (payload) => ({ | |||
| type: FETCH_IS_CATEGORIES_CHECKED_REQ, | |||
| payload | |||
| }); | |||
| export const setIsCategoriesCheckedError = (payload) => ({ | |||
| type: FETCH_IS_CATEGORIES_CHECKED_ERR, | |||
| payload, | |||
| }); | |||
| export const setIsCategoriesChecked = (payload) => ({ | |||
| type: FETCH_IS_CATEGORIES_CHECKED_SUCCESS, | |||
| payload, | |||
| }); | |||
| @@ -5,7 +5,12 @@ import { | |||
| } from "../actionHelpers"; | |||
| const FETCH_CATEGORIES_SCOPE = "FETCH_CATEGORIES"; | |||
| const FETCH_IS_CATEGORIES_CHECKED_SCOPE = "FETCH_IS_CATEGORIES_CHECKED"; | |||
| export const FETCH_CATEGORIES_REQ = createFetchType(FETCH_CATEGORIES_SCOPE); | |||
| export const FETCH_CATEGORIES_ERR = createErrorType(FETCH_CATEGORIES_SCOPE); | |||
| export const FETCH_CATEGORIES_SUCCESS = createSuccessType(FETCH_CATEGORIES_SCOPE); | |||
| export const FETCH_IS_CATEGORIES_CHECKED_REQ = createFetchType(FETCH_IS_CATEGORIES_CHECKED_SCOPE); | |||
| export const FETCH_IS_CATEGORIES_CHECKED_ERR = createErrorType(FETCH_IS_CATEGORIES_CHECKED_SCOPE); | |||
| export const FETCH_IS_CATEGORIES_CHECKED_SUCCESS = createSuccessType(FETCH_IS_CATEGORIES_CHECKED_SCOPE); | |||
| @@ -1,11 +1,14 @@ | |||
| import { | |||
| FETCH_CATEGORIES_ERR, | |||
| FETCH_CATEGORIES_SUCCESS, | |||
| FETCH_IS_CATEGORIES_CHECKED_ERR, | |||
| FETCH_IS_CATEGORIES_CHECKED_SUCCESS, | |||
| } from "../../actions/categories/categoriesActionConstants"; | |||
| import createReducer from "../../utils/createReducer"; | |||
| const initialState = { | |||
| categories: [], | |||
| isCategoriesChecked: [], | |||
| errorMessage: "", | |||
| }; | |||
| @@ -13,20 +16,36 @@ export default createReducer( | |||
| { | |||
| [FETCH_CATEGORIES_SUCCESS]: setStateCategories, | |||
| [FETCH_CATEGORIES_ERR]: setCategoriesErrorMessage, | |||
| [FETCH_IS_CATEGORIES_CHECKED_SUCCESS]: setStateIsCategoriesChecked, | |||
| [FETCH_IS_CATEGORIES_CHECKED_ERR]: setIsCategoriesCheckedErrorMessage, | |||
| }, | |||
| initialState | |||
| ); | |||
| function setStateCategories(state, action) { | |||
| return { | |||
| ...state, | |||
| categories: action.payload, | |||
| }; | |||
| } | |||
| function setCategoriesErrorMessage(state, action) { | |||
| return { | |||
| ...state, | |||
| errorMessage: action.payload, | |||
| }; | |||
| } | |||
| return { | |||
| ...state, | |||
| categories: action.payload, | |||
| }; | |||
| } | |||
| function setCategoriesErrorMessage(state, action) { | |||
| return { | |||
| ...state, | |||
| errorMessage: action.payload, | |||
| }; | |||
| } | |||
| function setStateIsCategoriesChecked(state, action) { | |||
| return { | |||
| ...state, | |||
| isCategoriesChecked: action.payload, | |||
| }; | |||
| } | |||
| function setIsCategoriesCheckedErrorMessage(state, action) { | |||
| return { | |||
| ...state, | |||
| errorMessage: action.payload, | |||
| }; | |||
| } | |||
| @@ -1,11 +1,22 @@ | |||
| import { all, call, put, takeLatest } from "redux-saga/effects"; | |||
| import { setCategories, setCategoriesError } from "../actions/categories/categoriesAction"; | |||
| import { | |||
| setCategories, | |||
| setCategoriesError, | |||
| setIsCategoriesChecked, | |||
| setIsCategoriesCheckedError, | |||
| } from "../actions/categories/categoriesAction"; | |||
| import { authScopeStringGetHelper } from "../../util/helpers/authScopeHelpers"; | |||
| import { JWT_TOKEN } from "../../constants/localStorage"; | |||
| import { addHeaderToken } from "../../request"; | |||
| import { rejectErrorCodeHelper } from "../../util/helpers/rejectErrorCodeHelper"; | |||
| import { FETCH_CATEGORIES_REQ } from "../actions/categories/categoriesActionConstants"; | |||
| import { getAllCategories } from "../../request/categoriesRequest"; | |||
| import { | |||
| FETCH_CATEGORIES_REQ, | |||
| FETCH_IS_CATEGORIES_CHECKED_REQ, | |||
| } from "../actions/categories/categoriesActionConstants"; | |||
| import { | |||
| getAllCategories, | |||
| getIsCategoriesChecked, | |||
| } from "../../request/categoriesRequest"; | |||
| export function* getCategories() { | |||
| try { | |||
| @@ -19,8 +30,21 @@ export function* getCategories() { | |||
| } | |||
| } | |||
| export function* getIsCategoriesCheckedSaga({ payload }) { | |||
| try { | |||
| const JwtToken = yield call(authScopeStringGetHelper, JWT_TOKEN); | |||
| yield call(addHeaderToken, JwtToken); | |||
| const result = yield call(getIsCategoriesChecked, payload.userId); | |||
| yield put(setIsCategoriesChecked(result.data)); | |||
| } catch (error) { | |||
| const errorMessage = yield call(rejectErrorCodeHelper, error); | |||
| yield put(setIsCategoriesCheckedError(errorMessage)); | |||
| } | |||
| } | |||
| export default function* categoriesSaga() { | |||
| yield all([ | |||
| takeLatest(FETCH_CATEGORIES_REQ, getCategories), | |||
| ]); | |||
| } | |||
| yield all([ | |||
| takeLatest(FETCH_CATEGORIES_REQ, getCategories), | |||
| takeLatest(FETCH_IS_CATEGORIES_CHECKED_REQ, getIsCategoriesCheckedSaga), | |||
| ]); | |||
| } | |||
| @@ -11,3 +11,13 @@ export const selectCategoriesError = createSelector( | |||
| categoriesSelector, | |||
| (state) => state.errorMessage | |||
| ); | |||
| export const selectIsCategoriesChecked = createSelector( | |||
| categoriesSelector, | |||
| (state) => state.isCategoriesChecked | |||
| ); | |||
| export const selectIsCategoriesCheckedError = createSelector( | |||
| categoriesSelector, | |||
| (state) => state.errorMessage | |||
| ); | |||