diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index 072f6c04d..5eae4718f 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -57,7 +57,6 @@ {{ $t('contribution.submit') }} - {{ form }} @@ -102,19 +101,12 @@ export default { return false }, lastMonthObject() { - let obj = { - month: new Date(this.lastMonth).toLocaleString(this.$i18n.locale, { month: 'long' }), - year: new Date().getFullYear(), - creation: this.$store.state.creation[1], - } - // If the current month is January then the current year must be counted back by -1. - if (new Date().getMonth === 1) { - obj = { + // new Date().getMonth === 1 If the current month is January, then one year must be gone back in the previous month + const obj = { month: new Date(this.lastMonth).toLocaleString(this.$i18n.locale, { month: 'long' }), - year: new Date().getFullYear() - 1, + year: new Date().getMonth === 1 ? new Date().getFullYear() - 1 : new Date().getFullYear(), creation: this.$store.state.creation[1], } - } return this.$t('contribution.formText.lastMonth', obj) }, thisMonthObject() { diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 27e63d568..a25c4b4f4 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -162,3 +162,25 @@ export const listTransactionLinks = gql` } } ` + +export const listContributions = gql` + query( + $currentPage: Int = 1 + $pageSize: Int = 25 + $order: Order = DESC + $filterConfirmed: Boolean = false + ) { + listContributions( + currentPage: $currentPage + pageSize: $pageSize + order: $order + filterConfirmed: $filterConfirmed + ) { + id + amount + memo + createdAt + deletedAt + } + } +` diff --git a/frontend/src/pages/Community.vue b/frontend/src/pages/Community.vue index 0559ea3e8..dc7c22aa0 100644 --- a/frontend/src/pages/Community.vue +++ b/frontend/src/pages/Community.vue @@ -20,6 +20,7 @@ import ContributionForm from '@/components/Contributions/ContributionForm.vue' import ContributionList from '@/components/Contributions/ContributionList.vue' import { createContribution } from '@/graphql/mutations' +import { listContributions } from '@/graphql/queries' export default { name: 'Community', @@ -29,39 +30,18 @@ export default { }, data() { return { - items: [ - { - id: '0', - date: '07/06/2022', - memo: 'Ich habe 10 Stunden die Elbwiesen von Müll befreit.', - amount: 200, - status: 'pending', - }, - { - id: '1', - date: '06/22/2022', - memo: 'Ich habe 30 Stunden Frau Müller beim EInkaufen und im Haushalt geholfen.', - amount: 600, - status: 'pending', - }, - { - id: '2', - date: '05/04/2022', - memo: - 'Ich habe 50 Stunden den Nachbarkindern bei ihren Hausaufgaben geholfen und Nachhilfeunterricht gegeben.', - amount: 1000, - status: 'pending', - }, - ], + currentPage: 1, + pageSize: 25, + items: [], } }, methods: { setContribution(data) { // console.log('setContribution', data) this.$apollo - .query({ + .mutate({ fetchPolicy: 'no-cache', - query: createContribution, + mutation: createContribution, variables: { creationDate: data.date, memo: data.memo, @@ -76,6 +56,31 @@ export default { this.toastError(err.message) }) }, + getListContributions(data) { + this.$apollo + .query({ + fetchPolicy: 'no-cache', + query: listContributions, + variables: { + currentPage: this.currentPage, + pageSize: this.pageSize, + }, + }) + .then((result) => { + console.log('result', result.data) + const { + data: { listContributions }, + } = result + this.items = listContributions + // this.toastSuccess(result.data) + }) + .catch((err) => { + this.toastError(err.message) + }) + }, + }, + created() { + this.getListContributions() }, }