import {
    UPLOAD_MEDIA_CV_REQUEST,
    UPLOAD_MEDIA_CV_FAILURE,
    UPLOAD_MEDIA_CV_SUCCESS,
} from "../types";

export function mediaCv(state = {
}, action = {}) {
    switch (action.type) {
        case UPLOAD_MEDIA_CV_REQUEST:
            return {
                ...state,
                loading: true
            };
        case UPLOAD_MEDIA_CV_SUCCESS:
            return {
                ...state,
                ...action.res.data,
                loading: false
            };
        case UPLOAD_MEDIA_CV_FAILURE:
            return {
                ...state,
                errors: action.errors,
                loading: false
            };
        default:
            return state;
    }
}

export const mediaCvErrorsSelector = state => {return !!state.mediaCv.errors ?state.mediaCv.errors.response.data:null};

export const errorMessageSelector = (state) => {
    let err = mediaCvErrorsSelector(state)
    if (!!!err)
        return null;
    switch(err.code)
    {
        case 500:
            return {message: "Le téléversement de votre video à échoué."}
    }
}