This commit is contained in:
2024-02-27 16:19:55 +08:00
commit feebeffcd9
141 changed files with 25124 additions and 0 deletions

1
app/stores/README.md Executable file
View File

@@ -0,0 +1 @@
# Store data here

23
app/stores/api.js Executable file
View File

@@ -0,0 +1,23 @@
import { create } from 'apisauce'
import config from '../config'
const api = {
login:"http://takeawayapp.nirons.com:8080/app-login/",
signup: "http://takeawayapp.nirons.com:8080/reg/",
logout:"http://takeawayapp.nirons.com:8080/logout/",
getMenu:"http://takeawayapp.nirons.com:8080/menu/",
pickUpLocation:"http://takeawayapp.nirons.com:8080/pick-up-location/",
check:"http://takeawayapp.nirons.com:8080/check/",
order:"http://takeawayapp.nirons.com:8080/order/",
creditCard:"http://takeawayapp.nirons.com:8080/credit-card/",
regPushToken:"http://takeawayapp.nirons.com:8080/reg-push-token",
sysTime:"http://takeawayapp.nirons.com:8080/sys-time",
coupon:"http://takeawayapp.nirons.com:8080/coupon/",
smsVerify:'http://takeawayapp.nirons.com:8080/sms_verify_start/',
forgotPassword:'http://takeawayapp.nirons.com:8080/forgot-pwd/',
member:'http://takeawayapp.nirons.com:8080/member/'
}
export default api

565
app/stores/menu_store.js Executable file
View File

@@ -0,0 +1,565 @@
import { observable, transaction, action, computed } from "mobx";
import api from "./api";
import axios from "axios";
import Toast, { DURATION } from "react-native-easy-toast";
import AsyncStorageHelper from "../config/asyncStorageHelper";
import moment from "moment";
import language from '../config/language'
import { Alert,Platform } from "react-native";
const asyncStorageHelper = new AsyncStorageHelper();
class menu_store {
@observable menu = [];
@observable
date = {
days: 0,
hours: 0,
min: 0,
sec: 0
};
@observable errorMessage = "";
@observable loading = false;
@observable flatListWidth = 0;
@observable selected = false;
@observable orderHistory = { data: { content: [] } };
@observable currentOrder = [];
@observable passOrder = [];
@observable coupons = {};
@observable
cutoffDateTime = new Date();
@observable
timestamp = new Date();
@observable
menuDetails = {
id: 0,
tel: "",
count: 0,
price: 0,
tags: [],
name: "",
nameEn: "",
imageURL: "",
intro_ch: "",
intro_en: "",
restaurant: {
name: "",
nameEn: "",
addrEn: "",
addr: ""
}
};
orderList = [];
items = [];
orderReturn = {};
pageNo = 1;
totalPage = 0;
@observable
pickupPointId = null;
@observable
sharemessage = {}
couponLabel = []
//for test
date1 = new Date(Date.UTC(2018, 9, 31, 3, 0, 0));
pickupDate = "?date=today";
constructor() {}
@action
async getMenuItem(self) {
this.selected = false;
this.loading = true;
this.pageNo = 1;
var requestURL = api.getMenu;
asyncStorageHelper.getData("pickupPointId", pickupPointId => {
let num = parseInt(pickupPointId);
this.pickupPointId = num;
pickupPointId = num.toString();
requestURL =
requestURL +
this.pickupDate +
"&pick-up-location-id=" +
pickupPointId.toString();
console.log("request:" + pickupPointId);
this.getMenu(self, requestURL, pickupPointId);
});
}
async updateMenu() {
this.selected = false;
this.loading = true;
this.pageNo = 1;
var requestURL = api.getMenu;
requestURL =
requestURL +
this.pickupDate +
"&pick-up-location-id=" +
this.pickupPointId.toString();
this.getMenuByUpdate(requestURL, this.pickupPointId);
}
@action
async updateMenuByMap(self, id) {
this.selected = false;
this.loading = true;
this.pageNo = 1;
var requestURL = api.getMenu;
let num = parseInt(id);
pickupPointId = num.toString();
requestURL =
requestURL +
this.pickupDate +
"&pick-up-location-id=" +
pickupPointId.toString();
console.log("request:" + pickupPointId);
self.autoPlaceFocus = false;
this.getMenu(self, requestURL, num);
}
@action
async getOrder(self, token) {
try {
var passOrder = [];
var currentOrder = [];
this.loading = true;
var nowDate = new Date();
nowDate.setDate(nowDate.getDate()-30)
//nowDate.format('yyyy-mm-dd')
console.log(nowDate.toISOString().substring(0, 10))
apiLink = api.order+'created-start='+nowDate.toISOString().substring(0, 10)
const response = await axios.get(api.order, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
console.log(response);
response.data.content.reverse();
response.data.content.forEach(e => console.log(e.status));
var content = response.data.content;
for (var i = 0; i < content.length; i++) {
if (content[i].status == "P" || content[i].status == "D") {
currentOrder.push(content[i]);
} else if (content[i].status == "F" || content[i].status == "V") {
passOrder.push(content[i]);
}
}
transaction(() => {
this.passOrder = passOrder;
this.currentOrder = currentOrder;
this.loading = false;
this.orderHistory = response;
});
} catch (error) {
this.loading = false;
console.log(error.response);
}
}
@action
async goOrderDetail(data, self) {
this.loading = true;
try {
this.loading = false;
const response = await axios.get(api.sysTime, { timeout: 5000 });
console.log(response);
var momentDate = moment(response.data.timestamp);
var timestamp = momentDate.toDate();
var momentCancelDate = moment(data.items[0].cancellation)
var cancelDate = momentCancelDate.toDate();
console.log(timestamp)
console.log(cancelDate);
if (timestamp >= cancelDate) {
self.go(data, true);
} else {
console.log("false");
self.go(data, false);
}
} catch (error) {
this.loading = false;
console.log(error);
Alert.alert("", error.response.data, [
{ text: "Ok", onPress: () => console.log("Cancel") }
]);
}
}
@action
async getMenuByUpdate(requestURL, id) {
this.loading = true;
try {
console.log("request:" + requestURL);
const response = await axios.get(requestURL, { timeout: 5000 });
response.data.content.forEach(e => (e.count = 0));
var newMenu = this.menuHandler(response, id);
transaction(() => {
this.menu = newMenu;
this.totalPage = response.totalPages;
this.loading = false;
});
// self.navigatieAction('menu')
console.log(this.menu);
} catch (error) {
this.loading = false;
console.log(error.response);
// self.refs.toast.show(error);
}
}
@action
async getMenu(self, requestURL, id) {
try {
console.log("request:" + requestURL);
const response = await axios.get(requestURL, { timeout: 5000 });
this.sharemessage = response.data.promotions;
//language.en.referFriendContent = response.data.promotions[0].contentEn
// language.zh.referFriendContent = response.data.promotions[0].content
//console.log(language.en.referFriendContent)
response.data.content.forEach(e => (e.count = 0));
console.log(response);
var newMenu = this.menuHandler(response, id);
transaction(() => {
this.menu = newMenu;
this.totalPage = response.totalPages;
this.loading = false;
});
self.navigatieAction("menu");
console.log(response);
} catch (error) {
this.loading = false;
console.log(error);
self.refs.toast.show(error);
}
}
@action
menuHandler(menu, id) {
console.log(menu.data.content);
var momentDate = moment(menu.data.timestamp);
var timestamp = momentDate.toDate();
this.timestamp = timestamp;
var newContent = [];
if (menu.data.content.length <= 0) {
return menu;
} else {
for (var i = 0; i < menu.data.content.length; i++) {
var index = menu.data.content[i].locations.findIndex(
x => x.location.id == id
);
var momentOrderEndDate = moment(
menu.data.content[i].locations[index].orderEnd
);
var orderEndDate = momentOrderEndDate.toDate();
console.log(timestamp.getDate() + " " + orderEndDate.getDate());
if (timestamp < orderEndDate) {
if (timestamp.getHours() < orderEndDate.getHours()) {
console.log(timestamp.getUTCDate()+" "+orderEndDate.getUTCDate())
if (timestamp.getDate() == orderEndDate.getDate()) {
newContent.push(menu.data.content[i]);
}
} else {
if (timestamp.getDate() < orderEndDate.getDate()) {
newContent.push(menu.data.content[i]);
}
}
}
}
console.log(newContent);
if (newContent.length > 0) {
menu.data.content = newContent;
var indexOfLocation = newContent[0].locations.findIndex(
x => x.location.id == id
);
var momentCutoffDateTime = moment(
newContent[0].locations[indexOfLocation].orderEnd
);
this.cutoffDateTime = momentCutoffDateTime.toDate();
console.log(this.cutoffDateTime);
} else {
var indexOfLocation = menu.data.content[0].locations.findIndex(
x => x.location.id == id
);
var momentCutoffDateTime = moment(
menu.data.content[0].locations[indexOfLocation].orderEnd
);
this.cutoffDateTime = momentCutoffDateTime.toDate();
menu.data.content = newContent;
console.log(this.cutoffDateTime);
}
// console.log(this.cutoffDateTime)
return menu;
}
}
@action
async menuloadmore(self) {
this.loading = true;
try {
const requestURL =
api.getMenu + "?page_no=" + toString(this.pageNo) + "&page_size=10";
const response = await axios.get(requestURL, { timeout: 5000 });
response.data.content.forEach(e => (e.count = 0));
transaction(() => {
//this.menu.content = this.menu.content.concat(response.content);
this.loading = false;
});
console.log(response);
} catch (error) {
this.loading = false;
console.log(error);
self.refs.toast.show(error);
}
}
@action
async order(token, data, self) {
this.loading = true;
var requestURL = api.order;
try {
const response = await axios.post(requestURL, data, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
this.loading = false;
console.log(this.loading);
console.log(response);
this.orderReturn = response;
setTimeout(function() {
self.pay();
}, 200);
} catch (e) {
this.loading = false;
self.refs.toast.show(e.response.data);
console.log(e)
}
}
@action
async cancelOrder(token) {
console.log(token);
var requestURL =
"http://takeawayapp.nirons.com:8080/order/" +
this.orderReturn.data.id +
"/cancel/";
try {
const response = await axios.put(requestURL, null, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
console.log(response);
} catch (e) {
console.log(e.response);
}
}
@action
async voidOrder(token, id, self) {
this.loading = true;
var requestURL =
"http://takeawayapp.nirons.com:8080/order/" + id + "/void/";
console.log(requestURL);
console.log(token);
try {
const response = await axios.put(requestURL, null, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
this.loading = false;
console.log(response);
self.back();
} catch (e) {
this.loading = false;
console.log(e.response);
self.refs.toast.show(e.response.data[0]);
}
}
@action
async userCoupon(self,token,check){
this.loading = true
var requestURL = api.coupon
try {
const response = await axios.get(requestURL, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
this.loading = false
this.couponLabel = []
response.data.content.forEach(item => {
if (item.used) {
var value = {value:item.id}
// this.couponLabel.push(value)
} else {
if (item.hasOwnProperty("expiry")) {
var nowDatemoment = moment(response.data.timestamp);
var nowDate = nowDatemoment.toDate();
var expiryDatemoment = moment(item.expiry);
var expiryDate = expiryDatemoment.toDate();
if (nowDate < expiryDate) {
var value = {value:item.id}
this.couponLabel.push(value)
} else {
}
} else {
}
}
});
this.coupons = response
console.log('userCoupon')
if(!check){
self.navigatieAction("ConfirmOrder");
}else{
self.navigatieAction("myCoupons");
}
console.log(response);
} catch (e) {
this.loading = false
console.log(e.response);
// self.refs.toast.show(e.response.data)
}
}
@action
async coupon(token, self, coupon) {
var requestURL = api.coupon + coupon;
console.log("token: " + token + " coupon: " + coupon);
var data = {};
try {
const response = await axios.get(requestURL, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
console.log(response);
self.discountAction(response.data);
} catch (e) {
console.log(e.response);
// self.refs.toast.show(e.response.data)
}
}
@action
async pay(token, self, creditCardId) {
this.loading = true;
let data = { creditCardId: creditCardId };
console.log(data);
var requestURL =
"http://takeawayapp.nirons.com:8080/order/" +
this.orderReturn.data.id +
"/pay/";
try {
const response = await axios.put(requestURL, data, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
this.loading = false;
console.log(response);
if(Platform.OS === 'ios'){
self.navigatieAction("myOrders");
}else{
self.navigatieAction("menu");
}
} catch (e) {
this.loading = false;
console.log(e.response);
self.refs.toast.show(e.response.data);
}
}
@action
getCount(id) {
index = this.menu.data.content.findIndex(obj => obj.id == id);
return this.menu.data.content[index].count;
}
@action
addCount(id) {
index = this.menu.data.content.findIndex(obj => obj.id == id);
this.menu.data.content[index].count += 1;
this.check();
}
@action
sumCount(id) {
index = this.menu.data.content.findIndex(obj => obj.id == id);
if (this.menu.data.content[index].count > 0)
this.menu.data.content[index].count -= 1;
this.check();
}
@action
check() {
var index = this.menu.data.content.findIndex(obj => obj.count > 0);
if (index != -1) {
this.selected = true;
} else {
this.selected = false;
}
}
@action
cancel() {
this.menu.data.content.forEach(e => (e.count = 0));
this.selected = false;
}
@action
getOrderedItems(self,token) {
this.orderList = [];
this.items = [];
for (var i = 0; i < this.menu.data.content.length; i++) {
if (this.menu.data.content[i].count > 0) {
this.orderList.push(this.menu.data.content[i]);
var data = {
menu: {
id: this.menu.data.content[i].id
},
qty: this.menu.data.content[i].count
};
this.items.push(data);
}
}
this.userCoupon(self,token,false)
// self.navigatieAction("ConfirmOrder");
console.log(this.orderList);
}
@action
cleanAll() {
transaction(() => {
this.menu.data.content.forEach(e => (e.count = 0));
this.selected = false;
});
}
@computed get totalMoney() {
let money = 0;
this.menu.data.content.forEach(e => (money += e.price * e.count));
return money;
}
}
const menuStore = new menu_store();
export default menuStore;

7
app/stores/stores_index.js Executable file
View File

@@ -0,0 +1,7 @@
import menuStore from "./menu_store"
import userStore from "./user_store"
const store = {menuStore,userStore };
export default store;

613
app/stores/user_store.js Executable file
View File

@@ -0,0 +1,613 @@
import { observable, action, transaction, AsyncStorage } from "mobx";
import api from "./api";
import axios from "axios";
import { Alert } from "react-native";
import AsyncStorageHelper from "../config/asyncStorageHelper";
import Toast, { DURATION } from "react-native-easy-toast";
import Permissions from "react-native-permissions";
import firebase from "react-native-firebase";
import { Notification } from "react-native-firebase";
import { Geolocation } from "react-native";
import language from "../config/language";
import Global from "../../app/Global";
import ConnectFail from "../config/connectFail";
const asyncStorageHelper = new AsyncStorageHelper();
const connectFail = new ConnectFail();
class User_store {
@observable
logined = false;
@observable
userData = {};
@observable
signUpData = {};
@observable
loading = false;
@observable
resend = false;
@observable
addedCard = false;
@observable
creditCardinfo = {};
@observable
countdown = 10;
@observable
pickupPointId = null;
pickupLoactionPoint = {};
pickupPointLabel = [];
pickupIndex = 0;
cardInfo = null;
cardNumber = null;
@observable
userLocation = null;
perdefinedPlaces = [];
@observable
isSignUp = false;
@observable
isSignUpVerify = false;
@observable
text = language.en;
@observable
languageSelection = "english";
@observable
OrderEndTime = { orderEndTime: "", orderStartTime: "" };
notificationInit(mid) {
firebase
.messaging()
.hasPermission()
.then(enabled => {
if (enabled) {
firebase
.messaging()
.getToken()
.then(notificationToken => {
console.log("LOG: ", notificationToken);
this.regUserNotificationToken(notificationToken, mid);
});
// user has permissions
} else {
firebase
.messaging()
.requestPermission()
.then(() => {
// alert("User Now Has Permission");
})
.catch(error => {
console.log(error);
// alert("Error", error);
// User has rejected permissions
});
}
});
this.notificationListener = firebase
.notifications()
.onNotification(notification => {
// Process your notification as required
const {
body,
data,
notificationId,
sound,
subtitle,
title
} = notification;
console.log("LOG: ", title, body, JSON.stringify(data));
});
}
@action
async regUserNotificationToken(notificationToken, mid) {
var token = this.userData.data.token;
var requestURL = api.regPushToken;
var data = {
mid: mid,
token: notificationToken
};
try {
const response = await axios.put(requestURL, data, {
headers: {
Authorization: token,
"Content-Type": "application/json"
}
});
asyncStorageHelper.saveString("notificationToken", notificationToken);
console.log(response);
} catch (e) {
// this.loading = false;
console.log(e);
}
}
@action
async regUserNotificationTokenWithNoMid(notificationToken) {
//var token = this.userData.data.token;
var requestURL = api.regPushToken;
var data = {
token: notificationToken
};
try {
const response = await axios.put(requestURL, data, {
headers: {
// Authorization: token,
"Content-Type": "application/json"
}
});
asyncStorageHelper.saveString("notificationToken", notificationToken);
console.log(response);
} catch (e) {
// this.loading = false;
console.log(e);
}
}
@action
async savePickupPointToServer(pickuppointid){
var token = this.userData.data.token;
var id = this.userData.data.member.id;
var requestURL = api.member+'id'+'/select_pickup_location/'+pickuppointid
try {
const response = await axios.post(requestURL, token);
} catch (e) {
console.log(e);
}
}
@action
async sendsmsVerify(data,self){
this.loading = true;
var requestURL = api.smsVerify;
try {
const response = await axios.post(requestURL,data, {
headers: {
"Content-Type":'multipart/form-data'
},
timeout: 5000
});
this.loading = false;
self.startToCountDown()
console.log(response);
} catch (e) {
console.log(e);
this.loading = false;
self.handleNetworkFailed()
self.refs.toast.show(e.response);
}
}
@action
async loginPost(data, self, navAction) {
this.loading = true;
var requestURL = api.login;
try {
const response = await axios.post(requestURL, data, {
headers: {
"Content-Type": "application/json"
},
timeout: 5000
});
Global.login = true;
transaction(() => {
this.userData = response;
this.logined = true;
this.loading = false;
});
this.getCreditCard();
this.notificationInit(response.data.member.id);
console.log(response);
if (navAction) {
asyncStorageHelper.saveData("userInfo", data);
self.navigatieAction("menu");
}
} catch (e) {
self.refs.toast.show("Login Fail");
this.loading = false;
//connectFail.fail();
console.log(e);
}
}
@action
async languageInit() {
asyncStorageHelper.getData("language", lang => {
if (lang != null) {
console.log(lang);
this.languageSelection = lang;
this.changeLanguage(lang);
console.log(this.languageSelection);
}
});
}
@action
changeLanguage(lang) {
console.log(lang);
if (lang == "english") {
console.log("select english");
this.text = language.en;
} else if (lang == "chinese") {
console.log("select chinese");
this.text = language.zh;
}
}
@action
dataLanguage(data, value) {
if (this.languageSelection == "english") {
switch (value) {
case "name":
return data.nameEn;
break;
case "addr":
return data.addrEn;
break;
case "intro":
return data.intro_en
break;
case 'placeName':
return data.descriptionEn
break;
}
} else {
switch (value) {
case "name":
return data.name;
break;
case "addr":
return data.addr;
break;
case "intro":
return data.intro_ch
break;
case 'placeName':
return data.description
break;
}
}
}
@action
saveLanguage(lang) {
this.languageSelection = lang;
this.changeLanguage(lang);
asyncStorageHelper.saveString("language", lang);
}
@action
async logoutPost(self,reset,data) {
this.loading = true;
var token = this.userData.data.token;
var requestURL = api.logout;
try {
const response = await axios.post(requestURL, token);
Global.login = false;
this.regUserNotificationToken("");
asyncStorageHelper.removeItemValue("userInfo");
//asyncStorageHelper.removeItemValue("pickupPointId");
if(reset){
this.loginPost(data, self, true);
}else{
self.navigatieAction("menu");
transaction(() => {
this.userData = [];
this.logined = false;
this.creditCardinfo = {};
this.addedCard = false;
this.loading = false;
});
}
} catch (e) {
this.loading = false;
console.log(e);
}
}
@action
async pickupLoaction(self, pickupPointExist, pickupPointId) {
var requestURL = api.pickUpLocation;
console.log("userStore pickupPointId: " + pickupPointId);
this.pickupPointId = pickupPointId;
try {
const response = await axios.get(requestURL);
response.data.content.sort((a, b) => a.id - b.id);
this.pickupLoactionPoint = response;
console.log(this.pickupLoactionPoint);
this.pickupPointLabel = [];
response.data.content.forEach(element => {
if(element.status == 'A'){
var label = {
value: element.name,
id: element.id,
name: element.name,
nameEn: element.nameEn,
pickupStartTime: element.pickupStartTime,
pickupEndTime: element.pickupEndTime,
photo: element.photo,
lat: element.lat,
lng: element.lng
};
var place = {
description: element.name,
descriptionEn: element.nameEn,
geometry: { location: { lat: element.lat, lng: element.lng } },
id: element.id,
pickupTime: {
pickupEndTime: element.pickupEndTime,
pickupStartTime: element.pickupStartTime,
orderEndTime: element.orderEndTime,
orderStartTime: element.orderStartTime
}
};
this.pickupPointLabel.push(label);
this.perdefinedPlaces.push(place);
}
});
if (!pickupPointExist) {
this._requestPermission(self);
} else {
if(this.getIndex(pickupPointId) === -1){
console.log("can't find index")
self.navigatieAction('LocationRequest');
}else{
console.log("find index");
self.getMenuItemFromInit();
}
}
} catch (e) {
console.log(e.message);
Alert.alert(
e.message,
e.message,
[
{
text: "Try again",
onPress: () => {
this.pickupLoaction(self, pickupPointExist, pickupPointId);
}
}
],
{ cancelable: false }
);
}
}
getIndex(id){
var index = this.pickupPointLabel.findIndex(function(item, i){
return item.id == parseInt(id)
});
return index
}
_requestPermission(self) {
Permissions.request("location").then(response => {
// Returns once the user has chosen to 'allow' or to 'not allow' access
// Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
// this.setState({ photoPermission: response })
if (
response == "allow" ||
response == "restricted" ||
response == "authorized"
) {
navigator.geolocation.getCurrentPosition(
position => {
this.userLocation = position;
console.log(position);
// self.navigatieAction("LocationRequest");
self.navigatieAction('Tutorial',{data:'store'})
},
error => {
console.log(error);
//self.navigatieAction("LocationRequest");
self.navigatieAction('Tutorial',{data:'store'})
},
{ enableHighAccuracy: false, timeout: 4000, maximumAge: 10000 }
);
} else {
// self.navigatieAction("LocationRequest");
self.navigatieAction('Tutorial',{data:'store'})
}
});
}
@action
async getCreditCard() {
var data = {};
var requestURL = api.creditCard;
var token = this.userData.data.token;
try {
const response = await axios.get(requestURL, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
console.log(response.data);
if (response.data.content.length > 0) {
this.addedCard = true;
this.creditCardinfo = response.data.content[0];
}
//self.navigatieAction("menu");
} catch (e) {
console.log(e);
}
}
@action
async deleCreditCard(self) {
this.loading = true;
var token = this.userData.data.token;
var requestURL = api.creditCard + "/" + this.creditCardinfo.id.toString();
try {
const response = await axios.delete(requestURL, {
headers: {
Authorization: token,
"Content-Type": "application/json"
},
timeout: 5000
});
this.creditCardinfo = {}
this.loading = false;
this.addedCard = false;
console.log(response);
} catch (e) {
this.loading = false;
console.log(e);
}
}
@action
async postCreditCard(self, data) {
console.log(data);
this.loading = true;
var token = this.userData.data.token;
var requestURL = api.creditCard;
var testString = "cvc: " + data.cvc+" expiry: "+data.expiry+" num: "+data.num
// self.testing(token,testString)
try {
const response = await axios.post(requestURL, data, {
headers: {
Authorization: token,
"Content-Type": "application/json"
}
});
transaction(() => {
this.creditCardinfo = response.data;
this.loading = false;
this.addedCard = true;
});
console.log(response);
self.addCard = false;
self.cardData = null;
//navigation.goBack();
// self.navigatieAction("menu");
} catch (e) {
this.loading = false;
console.log(e);
self.refs.toast.show(e.message);
}
}
@action
async signupPost(self) {
this.loading = true;
var requestURL = api.signup;
try {
const response = await axios.post(requestURL, this.signUpData, {
headers: {
"Content-Type": "application/json"
}
});
transaction(() => {
this.loading = false;
this.isSignUp = false;
this.isSignUpVerify = false;
this.userData = response;
});
console.log(response);
// self.navigatieAction("menu");
var data = { id: this.signUpData.email, pwd: this.signUpData.pwd };
this.loginPost(data, self, true);
} catch (e) {
console.log(e.response.data);
self.refs.toast.show("SignUp Fail: "+ e.response.data);
this.loading = false;
}
}
@action
async forgotPassword(data,self) {
this.loading = true;
var requestURL = api.forgotPassword;
try {
const response = await axios.post(requestURL, data, {
headers: {
"Content-Type": "application/json"
}
});
this.loading = false;
if(!this.logined){
self.backAction()
}else{
self.password = "";
self.verificationCode = "";
self.handleStopCountdown()
self.refs.toast.show("Reset Password success");
// self.navigatieAction('menu');
var data = {id:this.userData.data.member.email,pwd:data.password}
this.logoutPost(self,true,data)
}
console.log(response);
} catch (e) {
console.log(e.response.data);
self.refs.toast.show("Reset Password Fail: "+ e.response.data);
this.loading = false;
}
}
@action
async checkMember(data, self) {
this.loading = true;
var requestURL = api.check;
var checkData = {
email: data.email,
mobileWithCountryCode: data.countryCode + data.mobile
};
try {
const response = await axios.post(requestURL, checkData, {
headers: {
"Content-Type": "application/json"
}
});
console.log( response)
console.log( response.data[Object.keys(response.data)[1]] +" "+response.data[Object.keys(response.data)[0]])
if (
response.data[Object.keys(response.data)[1]] &&
response.data[Object.keys(response.data)[0]]
) {
transaction(() => {
this.signUpData = data;
this.loading = false;
});
self.navigatieAction("SignUpVerify");
//this.isSignUpVerify = true;
} else if (!response.data[Object.keys(response.data)[1]] && response.data[Object.keys(response.data)[0]]) {
self.refs.toast.show("Sign up failed. Phone number already in use.");
this.loading = false;
} else if (!response.data[Object.keys(response.data)[0]]&& response.data[Object.keys(response.data)[1]]) {
self.refs.toast.show("Sign up failed. Email already in use.");
this.loading = false;
}
} catch (e) {
self.refs.toast.show("SignUp Fail");
this.loading = false;
console.log(e);
}
}
}
const userStore = new User_store();
export default userStore;