DocSpace-buildtools/packages/asc-web-common/store/UserStore.js

66 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-02-03 12:42:47 +00:00
import { action, makeObservable, observable } from "mobx";
import api from "../api";
class UserStore {
user = null;
2021-02-03 12:42:47 +00:00
isLoading = false;
isLoaded = false;
2021-08-11 07:18:10 +00:00
userIsUpdate = false;
constructor() {
2021-02-01 11:01:09 +00:00
makeObservable(this, {
user: observable,
2021-02-03 12:42:47 +00:00
isLoading: observable,
isLoaded: observable,
2021-08-11 07:18:10 +00:00
userIsUpdate: observable,
2021-02-02 09:55:14 +00:00
getCurrentUser: action,
2021-02-03 12:42:47 +00:00
setIsLoading: action,
setIsLoaded: action,
setUser: action,
2021-09-06 09:30:58 +00:00
setUserIsUpdate: action,
2021-02-01 11:01:09 +00:00
});
}
2021-02-02 09:55:14 +00:00
getCurrentUser = async () => {
const user = await api.people.getUser();
2021-02-03 12:42:47 +00:00
this.setUser(user);
};
init = async () => {
this.setIsLoading(true);
await this.getCurrentUser();
this.setIsLoading(false);
this.setIsLoaded(true);
};
setIsLoading = (isLoading) => {
this.isLoading = isLoading;
};
setIsLoaded = (isLoaded) => {
this.isLoaded = isLoaded;
};
setUser = (user) => {
this.user = user;
2021-02-02 09:55:14 +00:00
};
2021-02-15 19:43:07 +00:00
changeEmail = async (userId, email, key) => {
this.setIsLoading(true);
const user = await api.people.changeEmail(userId, email, key);
this.setUser(user);
this.setIsLoading(false);
};
2021-08-11 07:18:10 +00:00
setUserIsUpdate = (isUpdate) => {
2021-09-06 09:30:58 +00:00
//console.log("setUserIsUpdate");
2021-08-11 07:18:10 +00:00
this.userIsUpdate = isUpdate;
};
}
export default UserStore;