const actionPend = name => ({ type: 'UPLOAD', status: 'PENDING', name });
const actionResolv = (name, payload) => ({ type: 'UPLOAD', status: 'RESOLVED', name, payload });
const actionReject = (name, error) => ({ type: 'UPLOAD', status: 'REJECTED', name, error });

const actionUploadFirstImg = (name, promise) =>
  async (dispatch) => {
    dispatch(actionPend(name));
    try {
      const payload = await promise;
      dispatch(actionResolv(name, payload));
      return payload;
    } catch (error) {
      dispatch(actionReject(name, error));
    }
  };

export default actionUploadFirstImg;
