Skip to content

Commit

Permalink
Merge pull request #1533 from hypersign-protocol/optimization
Browse files Browse the repository at this point in the history
Optimization
  • Loading branch information
Vishwas1 authored Aug 8, 2022
2 parents 4f189ea + 0178405 commit 9d1f457
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 210 deletions.
40 changes: 3 additions & 37 deletions src/components/admin/Charts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export default {
totalAvailable: 0,
totalUsed: 0,
unused: 0,
user: {},
usage: {},
user: {},
sections: [
{ label: "REQUESTS CONSUMED", value: this.totalUsed, color: "#ed5c5c" },
{ label: "REQUESTS LEFT", value: this.unused, color: "#60c860" },
Expand All @@ -55,47 +54,14 @@ export default {
this.user = {
...JSON.parse(usrStr),
};
await this.fetchSubscription();
this.totalAvailable = this.usage["totalAvailable"];
this.totalUsed = this.usage["totalUsed"];
this.totalAvailable = this.user.usage["totalAvailable"];
this.totalUsed = this.user.usage["totalUsed"];
this.unused = this.totalAvailable - this.totalUsed;
this.sections[0].value = this.totalUsed;
this.sections[1].value = this.unused;
},
methods: {
handleSectionClick() {},
async fetchSubscription() {
try {
this.isLoading = true;
// if (!this.user.id) throw new Error("No project owner found");
const url = `${this.$config.studioServer.BASE_URL}api/v1/subscription?usage=true`;
const headers = {
Authorization: `Bearer ${this.authToken}`,
AccessToken:`Bearer ${this.accessToken}`
};
const resp = await fetch(url, {
headers,
method: "GET",
});
if (!resp.ok) {
return this.notifyErr(resp.statusText);
}
const json = await resp.json();
this.usage = json["usage"];
// localStorage.setItem("subscriptions", JSON.stringify(json));
// this.notifySuccess("No. of projects fetched " + this.projects.length);
} catch (e) {
this.notifyErr(e.message);
} finally {
this.isLoading = false;
}
},
},
};
</script>
37 changes: 27 additions & 10 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ router.beforeEach((to, from, next) => {
const authToken = localStorage.getItem("authToken");

if (authToken) {
// console.log("Yes auth token");
const url = `${config.studioServer.BASE_URL}hs/api/v2/auth/protected`;
let usage = true;
if (to.path === "/admin/subscription") {
usage = false;
}
const url = `${config.studioServer.BASE_URL}hs/api/v2/auth/protected?usage=${usage}`;
fetch(url, {
headers: {
Authorization: `Bearer ${authToken}`,
Expand All @@ -214,15 +217,29 @@ router.beforeEach((to, from, next) => {
localStorage.removeItem("accessuser")
}
if (
to.meta.admin &&
!json.message.isSubscribed &&
(to.path != "/admin/subscription" && to.path != "/admin/dashboard")
to.meta.admin
) {
eventBus.$emit("UpdateAdminNav", false);
next({
path: "/admin/subscription",
params: { nextUrl: to.fullPath },
});
if (!json.message.isSubscribed &&
(to.path != "/admin/subscription" && to.path != "/admin/dashboard")) {
eventBus.$emit("UpdateAdminNav", false);
next({
path: "/admin/subscription",
params: { nextUrl: to.fullPath },
});
} else {
// if he is subscired
const usage = json.message.usage;
if (usage && usage.totalUsed >= usage.totalAvailable) {
next({
path: "/admin/subscription",
params: { nextUrl: to.fullPath },
});
eventBus.$emit("UpdateAdminNav", false);
} else {
eventBus.$emit("UpdateAdminNav", true);
next();
}
}
} else {
next();
}
Expand Down
66 changes: 1 addition & 65 deletions src/views/admin/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,76 +88,12 @@ export default {
this.accessuser={
...JSON.parse(accessUser)
}
this.fetchSubscription()
}
}
},
methods: {
async fetchSubscription() {
try {
this.isLoading = true;
// if (!this.user.id) throw new Error("No project owner found");
const url = `${this.$config.studioServer.BASE_URL}api/v1/subscription?usage=true`;
const headers = {
Authorization: `Bearer ${this.authToken}`,
AccessToken:`Bearer ${this.accessToken}`
};
const resp = await fetch(url, {
headers,
method: "GET",
});
if (!resp.ok) {
return this.notifyErr(resp.statusText);
}
const json = await resp.json();
this.subscriptions = json["subscriptions"];
this.activeSubscriptions=this.subscriptions.filter((x) => (x.paymentData?true:x.isActive===true))
this.paidSubscriptions=this.subscriptions.filter((x) => {
return x.paymentData?true:(x.isPaid===true)})
const usage = json["usage"]
if(usage && (usage.totalUsed >= usage.totalAvailable)){
this.$router.push("/admin/subscription");
eventBus.$emit('UpdateAdminNav', false);
}
if (usage && usage.totalAvailable > 0) {
eventBus.$emit('UpdateAdminNav', true);
} else {
eventBus.$emit('UpdateAdminNav', false);
}
// localStorage.setItem("subscriptions", JSON.stringify(json));
// this.notifySuccess("No. of projects fetched " + this.projects.length);
} catch (e) {
this.notifyErr(e.message);
} finally {
this.isLoading = false;
}
},
gotosubpage: id => {
this.$router.push(`${id}`);
},
logout(){
// console.log("Dashboard:: Logout method...")
// localStorage.removeItem('authToken')
// localStorage.removeItem('user')
// localStorage.removeItem("credentials")
// localStorage.removeItem("userData")
// if(this.$route.params.nextUrl != null){
// this.$router.push(this.$route.params.nextUrl)
// }else{
// this.$router.push('/login')
// }
},
},
mixins: [notificationMixins]
Expand Down
49 changes: 0 additions & 49 deletions src/views/admin/Events.vue
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ export default {
//const usrStr = localStorage.getItem("user");
//this.user = null; JSON.parse(usrStr);
this.fetchSubscription();
const usrStr = localStorage.getItem("user");
this.user = {
Expand All @@ -582,54 +581,6 @@ export default {
},
methods: {
async fetchSubscription() {
try {
this.isLoading = true;
// if (!this.user.id) throw new Error("No project owner found");
const url = `${this.$config.studioServer.BASE_URL}api/v1/subscription?usage=true`;
const headers = {
Authorization: `Bearer ${this.authToken}`,
AccessToken: `Bearer ${this.accessToken}`,
};
const resp = await fetch(url, {
headers,
method: "GET",
});
if (!resp.ok) {
return this.notifyErr(resp.statusText);
}
const json = await resp.json();
this.subscriptions = json["subscriptions"];
this.activeSubscriptions = this.subscriptions.filter((x) =>
x.paymentData ? true : x.isActive === true
);
this.paidSubscriptions = this.subscriptions.filter((x) => {
return x.paymentData ? true : x.isPaid === true;
});
const usage = json["usage"];
if (usage && usage.totalUsed >= usage.totalAvailable) {
this.$router.push("/admin/subscription");
eventBus.$emit("UpdateAdminNav", false);
}
if (usage && usage.totalAvailable > 0) {
eventBus.$emit("UpdateAdminNav", true);
} else {
eventBus.$emit("UpdateAdminNav", false);
}
// localStorage.setItem("subscriptions", JSON.stringify(json));
// this.notifySuccess("No. of projects fetched " + this.projects.length);
} catch (e) {
this.notifyErr(e.message);
} finally {
this.isLoading = false;
}
},
async getTags() {
const url = `${this.$config.studioServer.BASE_URL}api/v1/tag`;
const headers = {
Expand Down
49 changes: 0 additions & 49 deletions src/views/admin/Participants.vue
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ computed:{
},
async mounted() {
this.fetchSubscription();
if (this.$route.query.projectId) {
this.selectedProjectId = this.$route.query.projectId;
this.selectedProject = this.$route.query.projectId;
Expand All @@ -432,54 +431,6 @@ computed:{
},
methods: {
async fetchSubscription() {
try {
this.isLoading = true;
// if (!this.user.id) throw new Error("No project owner found");
const url = `${this.$config.studioServer.BASE_URL}api/v1/subscription?usage=true`;
const headers = {
Authorization: `Bearer ${this.authToken}`,
AccessToken: `Bearer ${this.accessToken}`,
};
const resp = await fetch(url, {
headers,
method: "GET",
});
if (!resp.ok) {
return this.notifyErr(resp.statusText);
}
const json = await resp.json();
this.subscriptions = json["subscriptions"];
this.activeSubscriptions = this.subscriptions.filter((x) =>
x.paymentData ? true : x.isActive === true
);
this.paidSubscriptions = this.subscriptions.filter((x) => {
return x.paymentData ? true : x.isPaid === true;
});
const usage = json["usage"];
if (usage && usage.totalUsed >= usage.totalAvailable) {
this.$router.push("/admin/subscription");
eventBus.$emit("UpdateAdminNav", false);
}
if (usage && usage.totalAvailable > 0) {
eventBus.$emit("UpdateAdminNav", true);
} else {
eventBus.$emit("UpdateAdminNav", false);
}
// localStorage.setItem("subscriptions", JSON.stringify(json));
// this.notifySuccess("No. of projects fetched " + this.projects.length);
} catch (e) {
this.notifyErr(e.message);
} finally {
this.isLoading = false;
}
},
parseActionValue(action) {
switch (action.type) {
case "DISCORD_JOIN":
Expand Down

0 comments on commit 9d1f457

Please sign in to comment.