Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 from beohoang98/feature/partner_management
Browse files Browse the repository at this point in the history
Feature/partner management
  • Loading branch information
Hoang Dan An authored Aug 18, 2020
2 parents 8b45c35 + db2ea54 commit 565c89f
Show file tree
Hide file tree
Showing 14 changed files with 932 additions and 793 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"@fortawesome/vue-fontawesome": "^0.1.10",
"axios": "^0.19.2",
"core-js": "^3.6.5",
"dayjs": "^1.8.31",
"dayjs": "^1.8.33",
"element-theme-dark": "^1.0.3",
"element-ui": "^2.13.2",
"register-service-worker": "^1.7.1",
"vee-validate": "^3.3.7",
"vee-validate": "^3.3.9",
"vue": "^2.6.11",
"vue-class-component": "^7.2.5",
"vue-property-decorator": "^8.5.1",
"vue-recaptcha": "^1.3.0",
"vue-router": "^3.3.4",
"vue-router": "^3.4.3",
"vuesax": "^4.0.1-alpha.20",
"vuex": "^3.5.1",
"vuex-class": "^0.3.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
@back="handleOnClose"
/>
</template>
<el-tabs tab-position="top">
<el-tab-pane label="Info">
<el-tabs tab-position="top" value="trans">
<el-tab-pane label="Info" name="info">
<el-form
ref="form"
label-position="left"
Expand Down Expand Up @@ -49,7 +49,7 @@
</el-collapse>
</el-form>
</el-tab-pane>
<el-tab-pane label="Transactions">
<el-tab-pane label="Transactions" name="trans">
<el-row>
<el-col>
<el-card>
Expand All @@ -69,26 +69,54 @@
</el-col>
</el-row>
<el-divider />
<el-table :data="transactions">
<el-table-column prop="id" label="ID" />
<el-table-column prop="createdAt" label="Created At">
<template :slot-scope="{ row: { createdAt } }">
{{ createdAt | datetime }}
</template>
</el-table-column>
</el-table>
<!-- <el-table :data="transactions">-->
<!-- <el-table-column prop="id" label="ID" />-->
<!-- <el-table-column prop="createdAt" label="Created At">-->
<!-- <template :slot-scope="{ row: { createdAt } }">-->
<!-- {{ createdAt | datetime }}-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- </el-table>-->
<el-form>
<el-form-item label="Filter">
<el-date-picker
v-model="dateRangeFilter"
start-placeholder="Start"
end-placeholder="End"
format="dd/MM/yyyy"
type="daterange"
range-separator="To"
:clearable="true"
editable
append-to-body
/>
</el-form-item>
</el-form>
<app-paginate-table
:queries="transQueries"
:api_url="`/admin/partner/${partnerId}/transactions`"
:fields="{
id: `ID`,
createdAt: `Created At`,
'transaction.amount': `Amount`,
}"
:formatter="formatter"
/>
</el-tab-pane>
</el-tabs>
</el-dialog>
</template>

<script lang="ts">
import { Component, Ref, Vue } from "vue-property-decorator";
import Vue from "vue";
import { Component, Ref } from "vue-property-decorator";
import { Form } from "element-ui";
import { axiosInstance } from "@/utils/axios";
import AppPaginateTable from "@/components/PaginateTable/PaginateTable.vue";
@Component({
name: "partner-detail-modal",
components: { AppPaginateTable },
})
export default class PartnerDetailModal extends Vue {
@Ref("form") form!: Form;
Expand All @@ -98,6 +126,7 @@ export default class PartnerDetailModal extends Vue {
isLoaded = false;
transactions: Transaction[] = [];
dateRangeFilter: Date[] = [];
info = {
publicKey: "",
Expand Down Expand Up @@ -128,14 +157,6 @@ export default class PartnerDetailModal extends Vue {
}
fetchTransaction() {
axiosInstance
.get<Paginate<PartnerTransLog>>(
`/admin/partner/${this.partnerId}/transactions`,
)
.then(({ data }) => {
this.transactions = data.items.map((item) => item.transaction);
});
axiosInstance
.get(`/admin/partner/${this.partnerId}/transaction-total`)
.then(({ data }) => {
Expand Down Expand Up @@ -167,6 +188,25 @@ export default class PartnerDetailModal extends Vue {
});
}
get formatter() {
return {
createdAt: (val: PartnerTransLog) =>
this.globalFilter("datetime")(val.createdAt),
"transaction.amount": (val: PartnerTransLog) =>
this.globalFilter("vndFormat")(val.transaction.amount),
};
}
get transQueries() {
return {
from: this?.dateRangeFilter?.[0],
to: this?.dateRangeFilter?.[1],
};
}
globalFilter(name: string) {
return (Vue as any).options.filters[name] || ((val: any) => val);
}
mounted() {
this.localVisible = true;
this.fetchInfo();
Expand Down
83 changes: 83 additions & 0 deletions packages/client/src/components/PaginateTable/PaginateTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<template>
<div class="app-paginate-table" v-loading="loading">
<el-table border fit height="500" show-header stripe :data="localData">
<el-table-column
v-for="field in fieldList"
:prop="field"
:key="field"
:label="fields[field]"
:formatter="formatter[field]"
/>
</el-table>
<el-pagination
background
:current-page="page"
:page-size="limit"
:page-count="totalPage"
@current-change="handlePageChange.bind(this)"
/>
</div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { axiosInstance } from "@/utils/axios";
@Component({
name: "app-paginate-table",
})
export default class PaginateTable extends Vue {
@Prop({ required: true, type: String }) api_url!: string;
@Prop({ required: false, type: Object, default: () => ({}) })
queries!: Record<string, string | number>;
@Prop({ required: false, type: Object, default: () => [] }) fields!: any;
@Prop({ required: false, type: Object, default: () => ({}) })
formatter!: Record<string, (value: any) => any>;
localData: any[] = [];
page = 1;
limit = 20;
totalPage = 1;
loading = true;
get fieldList(): string[] {
return Object.keys(this.fields);
}
handlePageChange(page: number) {
this.fetchData(page, this.limit);
}
@Watch("queries")
onQueryChange() {
this.fetchData(this.page, this.limit);
}
fetchData(page = 1, limit = 20) {
this.loading = true;
axiosInstance
.get<Paginate>(this.api_url, {
params: {
...this.queries,
page,
limit,
},
})
.then(({ data }) => {
this.localData = data.items;
this.totalPage = data.meta.totalPages;
this.page = data.meta.currentPage;
})
.finally(() => {
this.loading = false;
});
}
mounted() {
this.fetchData(this.page, this.limit);
}
}
</script>

<style lang="scss"></style>
19 changes: 7 additions & 12 deletions packages/client/src/filters/date.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { VueConstructor } from "vue";
import Vue from "vue";
import dayjs from "dayjs";

export default {
install: (Vue: VueConstructor) => {
Vue.filter("date", (value: string | number) => {
return dayjs(value).format("DD MMM yyyy");
});
Vue.filter("datetime", (value: string | number) => {
return dayjs(value).format("DD/MM/yy HH:mm:ss");
});
},
};
Vue.filter("date", (value: string | number) => {
return dayjs(value).format("DD MMM YYYY");
});
Vue.filter("datetime", (value: string | number) => {
return dayjs(value).format("DD/MM/YY HH:mm:ss");
});
1 change: 1 addition & 0 deletions packages/client/src/filters/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./number";
export * from "./date";
5 changes: 2 additions & 3 deletions packages/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"removeComments": true,
"resolveJsonModule": true,
"incremental": true,
Expand Down Expand Up @@ -41,9 +42,7 @@
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"src/**/*",
"tests/**/*.ts",
"tests/**/*.tsx"
],
Expand Down
Loading

1 comment on commit 565c89f

@vercel
Copy link

@vercel vercel bot commented on 565c89f Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.