{"size": 3016, "ext": "js", "max_stars_repo_path": "src/container/UserPrincipalInfoContainer.js", "max_stars_repo_name": "tails5555/Our_Title_Academy_2018_Web", "max_stars_repo_stars_event_min_datetime": "2018-12-25T12:04:54.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-25T12:04:54.000Z", "max_issues_repo_path": "src/container/UserPrincipalInfoContainer.js", "max_issues_repo_name": "tails5555/Our_Title_Academy_2018_Web", "max_issues_repo_issues_event_min_datetime": "2018-08-17T13:05:31.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-19T12:31:35.000Z", "max_forks_repo_path": "src/container/UserPrincipalInfoContainer.js", "max_forks_repo_name": "tails5555/Our_Title_Academy_2018_Web", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 44.3529411765, "max_line_length": 108, "alphanum_fraction": 0.6362732095}
import {UserPrincipalInfo} from '../component/main_side/user_list_page';
import {connect} from 'react-redux';
import {
    adminLoadUserInfo, adminLoadUserInfoSuccess, adminLoadUserInfoFailure,
    managerLoadUserInfo, managerLoadUserInfoSuccess, managerLoadUserInfoFailure, resetCommonLoadUserInfo
} from "../action/action_user";
import {
    resetUserFetchMyRequestStatistic, resetUserFetchMyTitleStatistic, userFetchMyRequestStatistic,
    userFetchMyRequestStatisticFailure,
    userFetchMyRequestStatisticSuccess,
    userFetchMyTitleStatistic, userFetchMyTitleStatisticFailure,
    userFetchMyTitleStatisticSuccess
} from "../action/action_my_context";

function mapStateToProps(state){
    return {
        accessor : state.user.accessor,
        principalInfo : state.user.principalInfo,
        myTitleStatistic : state.title.myTitleStatistic,
        myRequestStatistic : state.request.myRequestStatistic
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        fetchUserInfo : (userType, loginId) => {
            let accessToken = sessionStorage.getItem('jwtToken');
            if(!accessToken || accessToken === '') return;
            if(userType === 'ADMIN') {
                dispatch(adminLoadUserInfo(accessToken, loginId)).then((response) => {
                    if(!response.error){
                        dispatch(adminLoadUserInfoSuccess(response.payload));
                    } else {
                        dispatch(adminLoadUserInfoFailure(response.payload));
                    }
                });
            } else {
                dispatch(managerLoadUserInfo(accessToken, loginId)).then((response) => {
                    if(response.payload.status !== 200){
                        dispatch(managerLoadUserInfoFailure("조회 권한이 없습니다..."));
                    } else if(!response.error){
                        dispatch(managerLoadUserInfoSuccess(response.payload));
                    }
                })
            }
        },
        resetFetchUserInfo : () => {
            dispatch(resetCommonLoadUserInfo());
        },
        fetchRequestStatistic : (userId) => dispatch(userFetchMyRequestStatistic(userId)).then(response => {
            if(!response.error)
                dispatch(userFetchMyRequestStatisticSuccess(response.payload));
            else
                dispatch(userFetchMyRequestStatisticFailure(response.payload));
        }),
        resetFetchRequestStatistic : () => dispatch(resetUserFetchMyRequestStatistic()),
        fetchTitleStatistic : (userId) => dispatch(userFetchMyTitleStatistic(userId)).then(response => {
            if(!response.error){
                dispatch(userFetchMyTitleStatisticSuccess(response.payload));
            }else{
                dispatch(userFetchMyTitleStatisticFailure(response.payload));
            }
        }),
        resetFetchTitleStatistic : () => dispatch(resetUserFetchMyTitleStatistic())
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(UserPrincipalInfo);