Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add admin dashboard page on lab #754

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/NavigationDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export default {
{ text: "Orders", auth: true, route: { name: "lab-dashboard" } },
{ text: "Account", auth: false, route: { name: "lab-dashboard-account" } },
{ text: "Services", auth: false, route: { name: "lab-dashboard-services" } },
{ text: "Order History", auth: false, route: { name: "lab-dashboard-order-history" } }
{ text: "Order History", auth: false, route: { name: "lab-dashboard-order-history" } },
{ text: "Admin Dashboard", auth: true, route: { name: "lab-dashboard-admin" } }
]
}),

Expand Down
13 changes: 13 additions & 0 deletions src/router/routes/lab.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ const labRoutes = [
else next()
},
component: () => import(/* webpackChunkName */ "@/views/Dashboard/Lab/OrderHistory/ProcessOrder")
},
{
path: "/lab/admin",
name: "lab-dashboard-admin",
meta: {
pageHeader: "Admin Dashboard",
breadcrumbs: [
{ text: "Lab", href: "/lab" },
{ text: "Admin", href: "/lab/admin" },
{ text: "Admin Dashboard", disabled: true }
]
},
component: () => import(/* webpackChunkName */ "@/views/Dashboard/Lab/Admin")
}
]
}
Expand Down
239 changes: 239 additions & 0 deletions src/views/Dashboard/Lab/Admin/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
<template>
<div>
<v-container>
<DialogErrorBalance :show="isShowError" @close="closeDialog" />
<Dialog :show="showActiveOrder" :showClose="false" :width="330">
<template v-slot:body>
<div class="text-center">
<h2 class="mb-8">Admin Dashboard</h2>
<v-icon class="mb-8" inline color="primary" :size="100">
mdi-alert-circle-outline
</v-icon>
</div>
<p>
You still have active orders to complete. Resume any pending orders
before continuing with this process.
</p>
</template>
<template v-slot:actions>
<Button elevation="2" color="primary" :to="{ name: 'lab-dashboard' }" dark>
Go to Dashboard
</Button>
</template>
</Dialog>
<v-row>
<v-col cols="12" xl="8" lg="8" md="8" order-md="1" order="2">
<v-card class="dg-card" elevation="0" outlined>
<v-card-text class="px-8 mt-5">
<div class="d-flex justify-space-between align-center">
<div class="secondary--text text-h6">
<b>Menstrual Calender Admin Pricing</b>
</div>
<v-btn small dark color="#75DEE4" fab style="border-radius:10px;"
@click="isEditable = !isEditable">
<v-icon>mdi-pencil</v-icon>
</v-btn>
</div>

<v-form class="mt-5" ref="form">
<label style="font-size: 12px;"> Monthly </label>
<v-text-field dense placeholder="4200 USD" autocomplete="off" outlined :disabled="!isEditable || isLoading
" v-model="document.monthly_price"></v-text-field>

<label style="font-size: 12px;"> Quarterly Price </label>
<v-text-field dense placeholder="5600 USD" autocomplete="off" outlined :disabled="!isEditable || isLoading
" v-model="document.quarterly_price"></v-text-field>

<label style="font-size: 12px;"> Annually Price </label>
<v-text-field dense placeholder="7200 USD" autocomplete="off" outlined :disabled="!isEditable || isLoading
" v-model="document.annually_price"></v-text-field>

</v-form>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import {
updateLab,

Check failure on line 63 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 2 spaces but found 4
unstakeLabFee

Check failure on line 64 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 2 spaces but found 4
} from "@/lib/polkadotProvider/command/labs";
import { getOrdersData } from "@/lib/api";
import Kilt from "@kiltprotocol/sdk-js";
import CryptoJS from "crypto-js";
import { u8aToHex } from "@polkadot/util";
import serviceHandler from "@/lib/serviceHandler";
import { generalDebounce } from "@/utils";
import Dialog from "@/components/Dialog";
import Button from "@/components/Button";
import DialogErrorBalance from "@/components/Dialog/DialogErrorBalance";

export default {
name: "MenstrualCalendarAdmin",

Check failure on line 77 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 2 spaces but found 4
mixins: [serviceHandler],

Check failure on line 78 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 2 spaces but found 4

components: { Dialog, Button, DialogErrorBalance },

Check failure on line 80 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 2 spaces but found 4

data: () => ({

Check failure on line 82 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 2 spaces but found 4
document: {

Check failure on line 83 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 4 spaces but found 8
monthly_price: "",

Check failure on line 84 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 6 spaces but found 12
quarterly_price: "",

Check failure on line 85 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 6 spaces but found 12
annually_price: ""

Check failure on line 86 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Expected indentation of 6 spaces but found 12
},
isEditable: false,
isUploading: false,
showActiveOrder: false,
stakeStatus: "",
unstakeAt: "",
stakingAmount: "",
unstakeDialog: false,
unstakeLoading: false,
unstakeFee: 0,
verificationStatus: "",
isVerify: false,
isShowError: false,
fee: 0
}),

computed: {
...mapGetters({
api: "substrate/getAPI",
pair: "substrate/wallet",
labAccount: "substrate/labAccount"
}),

...mapState({
mnemonic: (state) => state.substrate.mnemonicData,
web3: (state) => state.metamask.web3
}),

isRequired() {
return [(val) => !!val || "This field is required"];
},

computeUnstakeDate() {
let date = new Date(this.unstakeAt);
date.setDate(date.getDate() + 6);
return date.toLocaleDateString("en-US");
},
},

watch: {
mnemonic(val) {
if (val) this.getKiltBoxPublicKey()
},

document: {
deep: true,
immediate: true,
handler: generalDebounce(async function () {
if (this.mnemonic) await this.getUpdateLabFee();
}, 500)
},
},

async created() {
await this.getUnstakeFee();
},

methods: {
async getLabInfo() {
const {
monthly_price,
quarterly_price,
annually_price
} = this.labAccount.info;

this.document = {
monthly_price,
quarterly_price,
annually_price
}
},

getKiltBoxPublicKey() {
const cred = Kilt.Identity.buildFromMnemonic(
this.mnemonic.toString(CryptoJS.enc.Utf8)
);
return u8aToHex(cred.boxKeyPair.publicKey);
},

async getUnstakeFee() {
const fee = await unstakeLabFee(this.api, this.pair);

this.unstakeFee = Number(
this.web3.utils.fromWei(String(fee.partialFee), "ether")
);
},

async handleShowUnstake() {
const { data } = await getOrdersData(this.pair.address, null, null, null);
const hasActiveOrder = data?.some(
(order) => order._source.status === "Paid"
);

if (hasActiveOrder) this.showActiveOrder = true;
else this.unstakeDialog = true;
},

async updateLab() {
if (!this.$refs.form.validate()) {
return;
}
try {
this.isLoading = true;
const boxPublicKey = this.getKiltBoxPublicKey();
const {
monthly_price,
quarterly_price,
annually_price
} = this.document;

await updateLab(
this.api,
this.pair,
{
monthly_price,
quarterly_price,
annually_price

},
() => {
this.isLoading = false;
this.isEditable = false;
}
);
} catch (err) {
console.error(err);

Check warning on line 212 in src/views/Dashboard/Lab/Admin/index.vue

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( build )

Unexpected console statement
}
},

closeDialog() {
this.isShowError = false;
this.isUploading = false;
},
},
};
</script>

<style lang="scss" scoped>
.on-hover {
cursor: pointer;
}

.support-url {
text-decoration: none;
color: gray;
}

.unstake-alert {
font-size: 13px;
padding-bottom: 12px;
color: #363636;
}
</style>
Loading