{"size": 1353, "ext": "js", "max_stars_repo_path": "src/DataStores/passwordStore.js", "max_stars_repo_name": "uwcirg/tb-mobile-app", "max_stars_repo_stars_event_min_datetime": "2018-02-22T22:56:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-03T17:59:35.000Z", "max_issues_repo_path": "src/DataStores/passwordStore.js", "max_issues_repo_name": "uwcirg/tb-mobile-app", "max_issues_repo_issues_event_min_datetime": "2018-02-22T04:24:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T20:26:13.000Z", "max_forks_repo_path": "src/DataStores/passwordStore.js", "max_forks_repo_name": "uwcirg/tb-mobile-app", "max_forks_repo_forks_event_min_datetime": "2018-08-17T17:15:50.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-17T17:15:50.000Z"}
{"max_stars_count": 3, "max_issues_count": 217, "max_forks_count": 1, "avg_line_length": 24.6, "max_line_length": 113, "alphanum_fraction": 0.6311899483}
import { action, observable} from "mobx";
import APIStore from "./apiStore";

const ROUTES = {
  updatePassword: ["/user/me/password", "PATCH"]
}

export class PasswordStore extends APIStore {

  //Takes in a data fetching strategy, so you can swap out the API one for testing data
  constructor(strategy) {
    super(strategy, ROUTES);
    this.strategy = strategy;
  }

  @observable currentPassword = ""
  @observable newPassword = ""
  @observable newPasswordConfirmation = ""
  @observable errors = []
  @observable message = ""
  @observable loading = false
  @observable success = false

  @action updatePassword = () => {
    this.errors = []
    this.message = ""
    this.loading = true;
    this.success = false;

    return this.executeRequest("updatePassword", this, { allowErrors: true, includeStatus: true }).then(json => {
      this.loading = false;
      if (json.httpStatus >= 400) {
        this.errors = json.fields
        this.message = json.error
        return false
      } else {
        this.success = true;
        this.message = json.message;
        return true
      }

    });
  }

  @action resetPasswordUpdateState = () => {
    this.currentPassword = ""
    this.newPassword = ""
    this.newPasswordConfirmation = ""
    this.errors = []
    this.message = ""
    this.loading = false
    this.success = false
  }

}