{"size": 589, "ext": "js", "max_stars_repo_path": "js/front/commands/upload-image.js", "max_stars_repo_name": "getdatakick/revws", "max_stars_repo_stars_event_min_datetime": "2018-01-09T18:17:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:16:02.000Z", "max_issues_repo_path": "js/front/commands/upload-image.js", "max_issues_repo_name": "getdatakick/revws", "max_issues_repo_issues_event_min_datetime": "2018-02-07T21:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T01:30:29.000Z", "max_forks_repo_path": "js/front/commands/upload-image.js", "max_forks_repo_name": "getdatakick/revws", "max_forks_repo_forks_event_min_datetime": "2018-02-08T02:48:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-13T17:35:18.000Z"}
{"max_stars_count": 35, "max_issues_count": 150, "max_forks_count": 15, "avg_line_length": 34.6470588235, "max_line_length": 82, "alphanum_fraction": 0.6689303905}
// @flow

import type { Api } from 'common/types';
import type { UploadImageAction } from 'front/actions';
import { setSnackbar, setImage, uploadImageFailed } from 'front/actions/creators';

export const uploadImage = (action: UploadImageAction, store: any, api: Api) => {
  api('uploadImage', { file: action.file }).then(result => {
    if (result.type === 'success') {
      store.dispatch(setImage(action.id, result.data));
    } else {
      store.dispatch(setSnackbar(__('Failed to upload file: %s', result.error)));
      store.dispatch(uploadImageFailed(action.id));
    }
  });
};
