Skip to content

Commit

Permalink
Merge pull request #56 from SolidStateGroup/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
kyle-ssg authored Dec 1, 2021
2 parents 3b86808 + 74ba387 commit 21c292e
Show file tree
Hide file tree
Showing 387 changed files with 16,483 additions and 6,130 deletions.
5 changes: 3 additions & 2 deletions common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ var Constants = {
pages: {},
strings: {},

simulate: {
simulate: false ? {
SUBSCRIBED: false,
MANAGE_SUBSCRIPTION: true,
LOGGED_IN: false,
PRE_FILLED_REGISTER: false,
ALL_FAVES_REMOVED_EXTERNALLY: false,
EXPIRY: false, // Doesn't work unless subscribed is set to true
SHOW_WELCOME: false
},
}: {},

tagColours: {
'CORE_CONDITION': 'rgba(81, 204, 81, 0.8)',
Expand Down
4 changes: 4 additions & 0 deletions common/dispatcher/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ module.exports = Object.assign({}, require('./base/_app-actions'), {
});
},
setSubscription: function (details) {
if (details && details.result && details.result.acknowledgementState === 1) {
console.log("Receipt already acknowledged, skipping")
return
}
Dispatcher.handleViewAction({
actionType: Actions.SET_SUBSCRIPTION,
details,
Expand Down
13 changes: 9 additions & 4 deletions common/project.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = {
debug: true,
api: 'https://api-staging.diagnosisview.org/api/',
public: 'https://api-staging.diagnosisview.org/public/',
debug: false,
api: 'https://api.diagnosisview.org/api/',
baseUrl: "https://diagnosisview.org/",
public: 'https://api.diagnosisview.org/public/',
codepushIOS: "n_v9269jFN38lTv8i3Mbe0p8t6Xw0e4BjVrJp",
codepushAndroid: "JHGFbOmwdHWqtkE-Ck4osQ_aJxBD9Sj_nU5Mr",
captchaSiteKey: "6LdekQAdAAAAANSJB5HNaHO0fOV8yJUsORpEaM2A",
captchaBaseUrl: "https://www.diagnosisview.org",
ga: ''
};
};
80 changes: 39 additions & 41 deletions common/stores/account-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,35 @@ var data = require('./base/_data');
var controller = {
register: (details) => {
store.saving();
var favouritesToSync = controller.getFavouritesToSync(FavouritesStore.model);
var historyToSync = controller.getHistoryToSync(HistoryStore.model);

data.post(Project.api + 'register', details)
.then(async res => {
.then(res => {
// Get device favourites and history to sync with server
var favouritesToSync = controller.getFavouritesToSync(res.favourites);
var historyToSync = await AsyncStorage.getItem("history");
if(historyToSync) {
historyToSync = JSON.parse(historyToSync)
controller.onLogin(res);
store.saved();
if (!SubscriptionStore.isSubscribed()) {
AppActions.buySubscription();
} else {
historyToSync = []
controller.subscribe(SubscriptionStore.getPurchase(), true);
}
return (favouritesToSync.length ? data.put(Project.api + 'user/sync/favourites', favouritesToSync) : Promise.resolve(res))
.then(res => historyToSync.length ? data.put(Project.api + 'user/sync/history', historyToSync) : Promise.resolve(res))
.then(res => {
controller.onLogin(res);
store.saved();
if (!SubscriptionStore.isSubscribed()) {
AppActions.buySubscription();
} else {
controller.subscribe(SubscriptionStore.getPurchase(), true);
}
})

})
.then(res => favouritesToSync.length ? data.put(Project.api + 'user/sync/favourites', favouritesToSync) : Promise.resolve(res)) // Sync favourites
.then(res => historyToSync.length ? data.put(Project.api + 'user/sync/history', historyToSync) : Promise.resolve(res)) // Sync history
.catch(e => AjaxHandler.error(AccountStore, e));
},
setToken: (token) => {
data.setToken(token);
},
adminLogin: (details) => {
store.loading();
data.post(Project.api + 'admin/login', details)
.then(res => {
controller.onLogin(res);
store.loaded();
})
.catch(e => {
controller.login(details)
});
//deprecated
return controller.login(details)
},
login: (details) => {
store.loading();
AsyncStorage.setItem("history","")
AsyncStorage.setItem("favourites","")
data.post(Project.api + 'login', details)
.then(res => {
controller.setToken(res && res.token);
Expand All @@ -58,12 +46,8 @@ var controller = {
controller.subscribe(SubscriptionStore.getPurchase(), true);
}

if (SubscriptionStore.isSubscribed()) {
controller.setToken(res && res.token);
return controller.processUser(res);
} else {
return res;
}
return res;
})
.then(res => {
controller.onLogin(res);
Expand All @@ -79,6 +63,7 @@ var controller = {
} else {
AsyncStorage.setItem('user', JSON.stringify(res));
}
SubscriptionStore.trigger("changed")
controller.setToken(res && res.token);
},

Expand All @@ -93,7 +78,9 @@ var controller = {
controller.setUser(null);
AppActions.clearDeviceFavourites();
AppActions.clearDeviceHistory();
AsyncStorage.setItem("subscriptionLinkedTo", "")
AsyncStorage.setItem("history","")
SubscriptionStore.subscription = null;
AsyncStorage.setItem("favourites","")
API.push && API.push.cancelAllNotifications();
},
Expand Down Expand Up @@ -127,11 +114,7 @@ var controller = {

store.saving();

const renewal = store.model.paymentData && store.model.paymentData.length ? true : false;

// Get device favourites and history to sync with server
var favouritesToSync = controller.getFavouritesToSync(store.model.favourites);
var historyToSync = controller.getHistoryToSync(store.model.history);

// Validate purchase
// console.log(JSON.stringify(purchase));
Expand All @@ -143,8 +126,13 @@ var controller = {
return Promise.reject(new Error('Attempted to activate subscription on device which already linked subscription to another account'));
}
return data.post(`${Project.api}user/validate/${Platform.OS}`, purchase)
.then((res)=>{
API.finalisePurchases()
return res
})
})
.then(res => {
AppActions.getAccount()
AsyncStorage.setItem("subscriptionLinkedTo", store.model.id.toString());
AsyncStorage.removeItem("retrySubscription");
return res;
Expand Down Expand Up @@ -173,8 +161,6 @@ var controller = {
return data.get(Project.api + 'account');
})
})
.then(res => favouritesToSync.length ? data.put(Project.api + 'user/sync/favourites', favouritesToSync) : Promise.resolve(res)) // Sync favourites
.then(res => historyToSync.length ? data.put(Project.api + 'user/sync/history', historyToSync) : Promise.resolve(res)) // Sync history
.then(res => {
// console.log(res);
store.model = this.processUser(res);
Expand Down Expand Up @@ -247,14 +233,26 @@ var controller = {
getUser: function () {
return store.model
},
getExpiryDate: function () {
if(store.model) {
return moment(store.model.expiryDate)
}
return SubscriptionStore.subscription && moment(SubscriptionStore.subscription.expiryDate);
},
neverSubscribed: function () {
if (API.isMobile && !store.model) {
return !SubscriptionStore.subscription;
}
return !store.model || !store.model.expiryDate
},
hasActiveSubscription: function () {
if (store.isAdmin())
return true

if (API.isMobile) {
return store.model && SubscriptionStore.isSubscribed();
if (API.isMobile && !store.model) {
return SubscriptionStore.isSubscribed();
}
return !store.hasExpiredSubscription() && store.model && store.model.activeSubscription && SubscriptionStore.isSubscribed();
return !store.hasExpiredSubscription() && store.model && store.model.activeSubscription;
},
hasExpiredSubscription: function () {
if (store.isAdmin())
Expand Down
2 changes: 1 addition & 1 deletion common/stores/diagnosis-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var controller = {
var results = [];
term = term.toLowerCase();
results = _.sortBy(_.filter(store.model, diagnosis => {
return !diagnosis.deleted && diagnosis.friendlyName && diagnosis.friendlyName.toLowerCase().indexOf(term) !== -1;
return !diagnosis.deleted && diagnosis.friendlyName && Format.removeAccents(diagnosis.friendlyName).toLowerCase().indexOf(term) !== -1;
}), 'friendlyName');
return results;
},
Expand Down
1 change: 1 addition & 0 deletions common/stores/history-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var controller = {
"date": v.dateAdded
}
});
AsyncStorage.setItem("history", JSON.stringify(store.model))
store.loaded();
})
},
Expand Down
Loading

0 comments on commit 21c292e

Please sign in to comment.