user.js 3.1 KB
export const initialState = {
    me: null,
    nikeRecord: null,

    isLoggingIn: false,
    isSigningUp: false,
    isLoadingMe: false,
    isLoggingOut: false,

    info: '',
};

export const LOG_IN_REQUEST = 'LOG_IN_REQUEST';
export const LOG_IN_SUCCESS = 'LOG_IN_SUCCESS';
export const LOG_IN_FAILURE = 'LOG_IN_FAILURE';

export const SIGN_UP_REQUEST = 'SIGN_UP_REQUEST';
export const SIGN_UP_SUCCESS = 'SIGN_UP_SUCCESS';
export const SIGN_UP_FAILURE = 'SIGN_UP_FAILURE';

export const LOAD_ME_REQUEST = 'LOAD_USER_REQUEST';
export const LOAD_ME_SUCCESS = 'LOAD_USER_SUCCESS';
export const LOAD_ME_FAILURE = 'LOAD_USER_FAILURE';

export const LOG_OUT_REQUEST = 'LOG_OUT_REQUEST';
export const LOG_OUT_SUCCESS = 'LOG_OUT_SUCCESS';
export const LOG_OUT_FAILURE = 'LOG_OUT_FAILURE';

export default (state = initialState, action) => {
    switch (action.type) {

        case LOG_IN_REQUEST: {
            return {
                ...state,
                isLoggingIn: true,
            }
        }

        case LOG_IN_SUCCESS: {
            const {me} = action.data;
            return {
                ...state,
                me,
                isLoggingIn: false,
            };
        }

        case LOG_IN_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                isLoggingIn: false,
                info,
            }
        }

        case SIGN_UP_REQUEST: {
            return {
                ...state,
                isSigningUp: true
            }
        }
        case SIGN_UP_SUCCESS: {
            const {me} = action.data;
            return {
                ...state,
                me,
                isSigningUp: false,
            };
        }
        case SIGN_UP_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                isSigningUp: false,
                info
            };
        }

        case LOAD_ME_REQUEST: {
            return {
                ...state,
                isLoadingMe: true
            }
        }
        case LOAD_ME_SUCCESS: {
            const {user} = action.data;
            console.log(user);
            return {
                ...state,
                me: user,
                isLoadingMe: false
            }
        }
        case LOAD_ME_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                isLoadingMe: false,
                info
            }
        }


        case LOG_OUT_REQUEST: {
            return {
                ...state,
                isLoggingOut: true
            }
        }

        case LOG_OUT_SUCCESS: {
            console.log('LOG_OUT_SUCCESS 완료');
            return {
                ...state,
                me: null,
                isLoggingOut: false
            }
        }

        case LOG_OUT_FAILURE: {
            const {info} = action.data;
            return {
                ...state,
                isLoggingOut: false,
                info
            }
        }

        default: {
            return {
                ...state,
            };
        }
    }
};