Skip to content

Commit

Permalink
Update proof on date or currency change
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jun 21, 2024
1 parent d68799f commit e7b64fe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
62 changes: 41 additions & 21 deletions src/components/ProofInputRow.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-row>
<!-- proof image -->
<v-col cols="12">
<!-- proof image -->
<v-row>
<v-col cols="8">
<v-btn
Expand Down Expand Up @@ -52,36 +52,30 @@
</p>
</v-col>
</v-row>
</v-col>
<!-- proof date -->
<v-col cols="12">
<h3 class="mt-4 mb-1">
{{ $t('Common.Date') }}
</h3>

<!-- proof date & currency -->
<v-row>
<v-col cols="12" sm="6">
<v-col cols="6">
<h3 class="mb-1">
{{ $t('Common.Date') }}
</h3>
<v-text-field
v-model="proofForm.date"
:label="$t('Common.Date')"
type="date"
:disabled="existingProof"
:disabled="!proofForm.proof_id || existingProof"
hide-details="auto"
/>
</v-col>
</v-row>
</v-col>
<!-- proof currency -->
<v-col cols="12">
<h3 class="mb-1">
{{ $t('Common.Currency') }}
</h3>
<v-row>
<v-col cols="12" sm="6">
<v-col cols="6">
<h3 class="mb-1">
{{ $t('Common.Currency') }}
</h3>
<v-select
v-model="proofForm.currency"
:label="$t('Common.Currency')"
:items="userFavoriteCurrencies"
:disabled="existingProof"
:disabled="!proofForm.proof_id || existingProof"
hide-details="auto"
/>
</v-col>
Expand Down Expand Up @@ -170,6 +164,16 @@ export default {
return this.appStore.getUserFavoriteCurrencies
}
},
watch: {
'proofForm.date'(newProofDate, oldProofDate) {
console.log('watch proofForm.date', newProofDate, oldProofDate)
this.updateProof()
},
'proofForm.currency'(newProofCurrency, oldProofCurrency) {
console.log('watch proofForm.currency', newProofCurrency, oldProofCurrency)
this.updateProof()
},
},
mounted() {
if (this.$route.query.proof_id) {
this.getProofById(this.$route.query.proof_id)
Expand Down Expand Up @@ -203,6 +207,7 @@ export default {
return `${import.meta.env.VITE_OPEN_PRICES_APP_URL}/img/${proof.file_path}`
},
newProof(source) {
this.existingProof = false
if (source === 'gallery') {
// extract date from image exif
ExifReader.load(this.proofImage[0]).then((tags) => {
Expand All @@ -219,6 +224,7 @@ export default {
this.uploadProof()
},
uploadProof() {
console.log(this.proofForm)
this.loading = true
new Promise((resolve, reject) => {
new Compressor(this.proofImage[0], {
Expand All @@ -238,12 +244,12 @@ export default {
this.proofImagePreview = this.getProofUrl(data)
this.proofSuccessMessage = true
} else {
alert('Error: server error')
alert('Error: server error when creating proof')
console.log(data)
}
})
.catch((error) => {
alert('Error: server error')
alert('Error: server error when creating proof')
console.log(error)
this.loading = false
})
Expand All @@ -256,7 +262,21 @@ export default {
// console.log('Compress complete')
// })
},
updateProof() {
this.loading = true
api.updateProof(this.proofForm.proof_id, this.proofForm)
.then((data) => { // eslint-disable-line no-unused-vars
// nothing to do ?
})
.catch(err => { // eslint-disable-line no-unused-vars
alert('Error: server error when updating proof')
})
.finally(() => {
this.loading = false
})
},
clearProof() {
this.existingProof = false
this.proofImage = null
this.proofImagePreview = null
this.proofForm.proof_id = null
Expand Down
1 change: 1 addition & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default {
},

createProof(proofImage, type='PRICE_TAG', date=null, currency=null) {
console.log('createProof', proofImage, type, date, currency)
const store = useAppStore()
let formData = new FormData()
formData.append('file', proofImage, proofImage.name)
Expand Down

0 comments on commit e7b64fe

Please sign in to comment.