Skip to content

Commit

Permalink
fix(Price add): fix init Product type (via store). ref #1099
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Dec 8, 2024
1 parent 816c053 commit 675130d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/ProductInputRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default {
utils.getLocaleOriginTags(this.appStore.getUserLanguage).then((module) => {
this.originTags = module.default
})
this.productForm.type = this.productForm.type ? this.productForm.type : (this.productForm.product_code ? 'PRODUCT' : this.appStore.user.last_product_mode_used)
this.productForm.type = this.productForm.type ? this.productForm.type : (this.productForm.product_code ? 'PRODUCT' : this.appStore.user.last_product_product_used)
if (this.productForm.product_code) {
this.getProduct(this.productForm.product_code)
}
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default {
OPF_URL: 'https://world.openproductsfacts.org',
OPF_ICON: OPF_ICON,
SOURCE_PARAM: 'source',
PRICE_TYPE_PRODUCT: PRICE_TYPE_PRODUCT,
PRICE_TYPE_CATEGORY: PRICE_TYPE_CATEGORY,
PRICE_TYPE_LIST: [
{key: PRICE_TYPE_PRODUCT, value: 'Barcode', icon: PRICE_TYPE_PRODUCT_ICON},
{key: PRICE_TYPE_CATEGORY, value: 'Category', icon: PRICE_TYPE_CATEGORY_ICON}
Expand Down
2 changes: 1 addition & 1 deletion src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default {
createPrice(inputData, source = null) {
const data = filterBodyWithAllowedKeys(inputData, PRICE_CREATE_FIELDS)
const store = useAppStore()
store.user.last_product_mode_used = data.product_code ? 'barcode' : 'category'
store.user.last_product_product_used = data.product_code ? constants.PRICE_TYPE_PRODUCT : constants.PRICE_TYPE_CATEGORY
const url = `${import.meta.env.VITE_OPEN_PRICES_API_URL}/prices?${buildURLParams({'app_version': source})}`
return fetch(url, {
method: 'POST',
Expand Down
3 changes: 2 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { defineStore } from 'pinia'
import constants from './constants'
import utils from './utils.js'

export const useAppStore = defineStore('app', {
state: () => ({
user: {
username: null,
token: null,
last_product_mode_used: 'barcode',
last_product_type_used: constants.PRICE_TYPE_PRODUCT, // or 'BARCODE'
last_currency_used: import.meta.env.VITE_DEFAULT_CURRENCY, // 'EUR'
recent_locations: [],
language: import.meta.env.VITE_DEFAULT_LOCALE, // 'en'
Expand Down
2 changes: 1 addition & 1 deletion src/views/AddPriceMultiple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default {
initNewProductPriceForm() {
this.clearProductPriceForm()
this.productPriceForm = JSON.parse(JSON.stringify(this.productPriceNew)) // deep copy
this.productPriceForm.type = this.appStore.user.last_product_mode_used // can be overriden in ProductInputRow
this.productPriceForm.type = this.appStore.user.last_product_type_used // can be overriden in ProductInputRow
this.productPriceForm.price_per = this.categoryPricePerList[0].key // init to 'KILOGRAM' because it's the most common use-case
this.productPriceForm.currency = this.addPriceMultipleForm.currency || this.appStore.getUserLastCurrencyUsed // get currency from proof first
// scroll to the form
Expand Down

0 comments on commit 675130d

Please sign in to comment.