export default function actionChatsPromise(name, promise) {
    const actionPending = (name) => ({
        type: "MSG",
        status: "PENDING",
        name,
    });
    
    const actionFulfilled = (name, payload) => ({
        type: "MSG",
        status: "FULFILLED",
        name,
        payload,
    });
    
    const actionRejected = (name, error) => ({
        type: "MSG",
        status: "REJECTED",
        name,
        error,
    });

    return async dispatch => {
        try {
            dispatch(actionPending())
            let payload = await promise
            dispatch(actionFulfilled(name, payload));
            return payload
        }
        catch (error) {
            dispatch(actionRejected(name, error))
        }
    }
}
