first step to get edit working again

This commit is contained in:
Moriz Wahl 2023-03-10 11:35:08 +01:00
parent 91c74331ff
commit 774f9e6b81
6 changed files with 42 additions and 40 deletions

View File

@ -97,15 +97,16 @@ export default {
type: Object,
required: true,
},
creation: {
type: Array,
default: () => [1000, 1000, 1000],
},
},
data() {
return {
text: !this.creationUserData.memo ? '' : this.creationUserData.memo,
value: !this.creationUserData.amount ? 0 : Number(this.creationUserData.amount),
rangeMin: 0,
rangeMax: 1000,
selected: '',
creation: [0, 0, 0],
}
},
methods: {
@ -115,14 +116,12 @@ export default {
mutation: adminUpdateContribution,
variables: {
id: this.item.id,
email: this.item.email,
creationDate: this.selected.date,
amount: Number(this.value),
memo: this.text,
},
})
.then((result) => {
this.$emit('update-user-data', this.item, result.data.adminUpdateContribution.creation)
this.$emit('update-creation-data', {
amount: Number(result.data.adminUpdateContribution.amount),
date: result.data.adminUpdateContribution.date,
@ -149,32 +148,23 @@ export default {
})
},
},
apollo: {
OpenCreations: {
query() {
return openCreations
},
fetchPolicy: 'network-only',
variables() {
return {
userId: this.item.userId,
}
},
update({ openCreations }) {
this.creation = openCreations.map((c) => c.amount)
},
error({ message }) {
this.toastError(message)
},
computed: {
creationIndex() {
const month = this.$d(new Date(this.item.contributionDate), 'month')
return this.radioOptions.findIndex((obj) => obj.item.short === month)
},
selected() {
return this.radioOptions[this.creationIndex].item
},
rangeMax() {
console.log('index', this.creationIndex, this.creation[this.creationIndex])
return Number(this.creation[this.creationIndex]) + Number(this.item.amount)
},
},
created() {
if (this.creationUserData.date) {
const month = this.$d(new Date(this.creationUserData.date), 'month')
const index = this.radioOptions.findIndex((obj) => obj.item.short === month)
this.selected = this.radioOptions[index].item
this.rangeMax = Number(this.creation[index]) + Number(this.creationUserData.amount)
}
watch: {
creation() {
console.log('watch', this.creation)
},
},
}
</script>

View File

@ -95,6 +95,7 @@
type="singleCreation"
:item="row.item"
:row="row"
:creation="getOpenCreations(row.item.userId)"
:creationUserData="creationUserData"
@update-creation-data="updateCreationData"
/>
@ -104,7 +105,6 @@
:contributionId="row.item.id"
:contributionState="row.item.state"
@update-state="updateState"
@update-user-data="updateUserData"
/>
</div>
</template>
@ -119,6 +119,7 @@ import { toggleRowDetails } from '../../mixins/toggleRowDetails'
import RowDetails from '../RowDetails'
import EditCreationFormular from '../EditCreationFormular'
import ContributionMessagesList from '../ContributionMessages/ContributionMessagesList'
import { openCreations } from '../../graphql/openCreations'
const iconMap = {
IN_PROGRESS: 'question-square',
@ -187,6 +188,22 @@ export default {
updateState(id) {
this.$emit('update-state', id)
},
getOpenCreations(userId) {
this.$apollo
.query({
query: openCreations,
variables: {
userId,
},
})
.then(({ data: { openCreations } }) => {
console.log(openCreations.map((obj) => obj.amount))
return openCreations.map((obj) => obj.amount)
})
.catch((error) => {
console.log(error)
})
},
},
}
</script>

View File

@ -31,6 +31,7 @@ export const adminListAllContributions = gql`
deletedAt
deletedBy
moderatorId
userId
}
}
}

View File

@ -1,14 +1,8 @@
import gql from 'graphql-tag'
export const adminUpdateContribution = gql`
mutation ($id: Int!, $email: String!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
adminUpdateContribution(
id: $id
email: $email
amount: $amount
memo: $memo
creationDate: $creationDate
) {
mutation ($id: Int!, $amount: Decimal!, $memo: String!, $creationDate: String!) {
adminUpdateContribution(id: $id, amount: $amount, memo: $memo, creationDate: $creationDate) {
amount
date
memo

View File

@ -2,7 +2,7 @@ import gql from 'graphql-tag'
export const openCreations = gql`
query ($userId: Int) {
openCreations(userId: $userID) {
openCreations(userId: $userId) {
year
month
amount

View File

@ -44,7 +44,7 @@
:fields="fields"
@show-overlay="showOverlay"
@update-state="updateStatus"
@update-contributions="$apollo.queries.AllContributions.refetch()"
@update-contributions="$apollo.queries.ListAllContributions.refetch()"
/>
<b-pagination