update: login function and purchased item store

This commit is contained in:
Rifqy Zacky Ariadhy
2019-01-06 15:18:00 +07:00
parent 02c17264b7
commit d7b2b8fdd1
12 changed files with 122 additions and 195 deletions

View File

@@ -57,6 +57,7 @@ import Surf from './surf';
import Odoo from './odoo';
import Vouchers from './vouchers';
import {PurchasedItemStore} from "./purchased_item";
export default class AppState {
http = new Http(this.token);
@@ -115,7 +116,7 @@ export default class AppState {
notification = new Notification(this);
tags = new Tags(this);
surf_turf = new Surf(this);
purchased_items = new PurchasedItemStore(this);
constructor(initialState) {
this.token = initialState.token;

View File

@@ -71,29 +71,31 @@ export class Authentication {
@action
logout() {
return this.http.post("authentication/logout", {token : localStorage.getItem('tokens')})
.then(res => {
this.context.setToken("");
this.context.setUserData({});
localStorage.removeItem('id_token');
localStorage.removeItem('user.name');
localStorage.removeItem('user.profile_image');
localStorage.setItem('isLoggingIn', false);
let cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
this.eraseCookie(cookies[i].split("=")[0]);
}
if (window && window.Tawk_API && window.Tawk_API.isChatHidden()) {
window.Tawk_API.hideWidget()
}
return res;
})
.catch(err => {
throw err;
})
this.context.setToken("");
this.context.setUserData({});
// return this.http.post("authentication/logout", {token : localStorage.getItem('tokens')})
// .then(res => {
// this.context.setToken("");
// this.context.setUserData({});
//
// localStorage.removeItem('id_token');
// localStorage.removeItem('user.name');
// localStorage.removeItem('user.profile_image');
// localStorage.setItem('isLoggingIn', false);
// let cookies = document.cookie.split(";");
// for (let i = 0; i < cookies.length; i++) {
// this.eraseCookie(cookies[i].split("=")[0]);
// }
//
// if (window && window.Tawk_API && window.Tawk_API.isChatHidden()) {
// window.Tawk_API.hideWidget()
// }
//
// return res;
// })
// .catch(err => {
// throw err;
// })
}
@@ -248,6 +250,7 @@ export class Authentication {
@computed
get isLoggedIn() {
// alert(!!(this.context.token));
return !!(this.context.token);
}

View File

@@ -0,0 +1,11 @@
import { BaseStore } from "./base_store";
import {observable, action} from "mobx/lib/mobx";
export class PurchasedItemStore extends BaseStore {
constructor(context) {
super(context);
this.url = "purchased_items";
}
}