Skip to main content
se añadieron 986 caracteres en el cuerpo
Origen Enlace

ACTIONS

//crear un servicio ADMIN
export const newService=(serviceData)=>async(dispatch)=>{
    try {
        dispatch({type: CREATE_SERVICE_REQUEST})
        const config={
            header:{'Content-Type':'application/json'}
        }
        const {data}=await axios.post('/api/services/nuevo',serviceData,config)
        
        dispatch({
                type: CREATE_SERVICE_SUCCESS,
                payload:data,
            })
        return data
    } catch (error) {
        dispatch({
            type: CREATE_SERVICE_FAIL,
            payload: error.response.data.message
        })
    }
}

CONSTANTS

export const CREATE_SERVICE_REQUEST="CREATE_SERVICE_REQUEST"
export const CREATE_SERVICE_SUCCESS="CREATE_SERVICE_SUCCESS"
export const CREATE_SERVICE_RESET="CREATE_SERVICE_RESET"
export const CREATE_SERVICE_FAIL="CREATE_SERVICE_SUCCESS"

ACTIONS

//crear un servicio ADMIN
export const newService=(serviceData)=>async(dispatch)=>{
    try {
        dispatch({type: CREATE_SERVICE_REQUEST})
        const config={
            header:{'Content-Type':'application/json'}
        }
        const {data}=await axios.post('/api/services/nuevo',serviceData,config)
        
        dispatch({
                type: CREATE_SERVICE_SUCCESS,
                payload:data,
            })
        return data
    } catch (error) {
        dispatch({
            type: CREATE_SERVICE_FAIL,
            payload: error.response.data.message
        })
    }
}

CONSTANTS

export const CREATE_SERVICE_REQUEST="CREATE_SERVICE_REQUEST"
export const CREATE_SERVICE_SUCCESS="CREATE_SERVICE_SUCCESS"
export const CREATE_SERVICE_RESET="CREATE_SERVICE_RESET"
export const CREATE_SERVICE_FAIL="CREATE_SERVICE_SUCCESS"
se añadieron 895 caracteres en el cuerpo
Origen Enlace

reducer

export const newServiceReducer = (state = { service: {} }, action) =>{
switch (action.type) {
    case CREATE_SERVICE_REQUEST:
        return{
            ...state,
            loading:true
        }
    case CREATE_SERVICE_SUCCESS:
        return{
            loading: false,
            success:action.payload.success,
            service:action.payload.service
        }
    case CREATE_SERVICE_FAIL:
        return{
            ...state,
            error:action.payload
        }
    case CREATE_SERVICE_RESET:
        return{
            ...state,
            success:false
        }
    case CLEAR_ERRORS:
        return{
            ...state,
            error:null
        }
    default:
        return state
}

}

reducer

export const newServiceReducer = (state = { service: {} }, action) =>{
switch (action.type) {
    case CREATE_SERVICE_REQUEST:
        return{
            ...state,
            loading:true
        }
    case CREATE_SERVICE_SUCCESS:
        return{
            loading: false,
            success:action.payload.success,
            service:action.payload.service
        }
    case CREATE_SERVICE_FAIL:
        return{
            ...state,
            error:action.payload
        }
    case CREATE_SERVICE_RESET:
        return{
            ...state,
            success:false
        }
    case CLEAR_ERRORS:
        return{
            ...state,
            error:null
        }
    default:
        return state
}

}

se añadieron 2 caracteres en el cuerpo
Origen Enlace
Origen Enlace
Loading