-
-
+
+
-
+
- {{ langOptions.find(l => l.id === modelValue)?.name }}
+ {{langOptions.find(l => l.id === modelValue)?.name}}
@@ -27,24 +24,15 @@
-
+
Translate
-
+
Back to Polish
@@ -101,7 +89,6 @@
-
@@ -113,31 +100,37 @@
-
-
+
Edit Usage
Save
Cancel
-
+
+
-
-
+
Edit Description
- Save
- Cancel
+
+ Save
+
+
+ Cancel
-
+
-
@@ -158,8 +151,6 @@ const settingsStore = useSettingsStore()
const activeTab = ref('description')
const translating = ref(false)
const noTranslation = ref(false)
-
-const defaultLangId = ref(0)
const selectedLangId = ref(0)
const activeLangId = ref(0)
const productID = ref(0)
@@ -179,72 +170,59 @@ const langOptions = computed(() => langs.filter(l => l.active !== false))
watch(selectedLangId, async (newLang) => {
if (!productID.value) return
- if (newLang === defaultLangId.value) {
+ if (newLang === productStore.defaultLangId.value) {
noTranslation.value = false
- activeLangId.value = defaultLangId.value
- await productStore.getProductDescription(defaultLangId.value, productID.value)
- await productStore.getDefaultProductDescription(defaultLangId.value, productID.value)
+ activeLangId.value = productStore.defaultLangId.value
+ await productStore.getProductDescription(productStore.defaultLangId.value, productID.value)
return
}
-
- await productStore.getProductDescription(newLang, productID.value)
-
const desc = productStore.productDescription
-
- if (!desc || (!desc.description && !desc.description_short && !desc.usage)) {
- noTranslation.value = true
- activeLangId.value = defaultLangId.value
- await productStore.getDefaultProductDescription(defaultLangId.value, productID.value)
- } else {
- noTranslation.value = false
- activeLangId.value = newLang
- }
})
-const isViewingExistingTranslation = computed(() => activeLangId.value !== defaultLangId.value && !noTranslation.value)
+const isViewingExistingTranslation = computed(() => activeLangId.value !== productStore.defaultLangId.value && !noTranslation.value)
const productName = computed(() => {
- if (activeLangId.value !== defaultLangId.value && !noTranslation.value) {
+ if (activeLangId.value !== productStore.defaultLangId.value && !noTranslation.value) {
return productStore.productDescription?.name || ''
}
return productStore.defaultProductDescription?.name || productStore.productDescription?.name || ''
})
const displayedDescription = computed(() => {
- if (activeLangId.value !== defaultLangId.value && !noTranslation.value) {
+ if (activeLangId.value !== productStore.defaultLangId.value && !noTranslation.value) {
return productStore.productDescription?.description || ''
}
return productStore.defaultProductDescription?.description || ''
})
const displayedShortDescription = computed(() => {
- if (activeLangId.value !== defaultLangId.value && !noTranslation.value) {
+ if (activeLangId.value !== productStore.defaultLangId.value && !noTranslation.value) {
return productStore.productDescription?.description_short || ''
}
return productStore.defaultProductDescription?.description_short || ''
})
const displayedUsage = computed(() => {
- if (activeLangId.value !== defaultLangId.value && !noTranslation.value) {
+ if (activeLangId.value !== productStore.defaultLangId.value && !noTranslation.value) {
return productStore.productDescription?.usage || ''
}
return productStore.defaultProductDescription?.usage || ''
})
const goBackToDefault = async () => {
- selectedLangId.value = defaultLangId.value
- activeLangId.value = defaultLangId.value
+ selectedLangId.value = productStore.defaultLangId.value
+ activeLangId.value = productStore.defaultLangId.value
noTranslation.value = false
- await productStore.getProductDescription(defaultLangId.value, productID.value)
- await productStore.getDefaultProductDescription(defaultLangId.value, productID.value)
+ await productStore.getProductDescription(productStore.defaultLangId.value, productID.value)
+ await productStore.getDefaultProductDescription(productStore.defaultLangId.value, productID.value)
}
const translateOrSave = async () => {
- if (!productID.value || selectedLangId.value === defaultLangId.value) return
+ if (!productID.value || selectedLangId.value === productStore.defaultLangId.value) return
translating.value = true
try {
- const res = await productStore.translateProductDescription(productID.value, defaultLangId.value, selectedLangId.value)
+ const res = await productStore.translateProductDescription(productID.value, productStore.defaultLangId.value, selectedLangId.value)
if (res) {
activeLangId.value = selectedLangId.value
noTranslation.value = false
@@ -256,7 +234,7 @@ const translateOrSave = async () => {
const btnClass = (tab: string) => ['cursor-pointer px-4 py-2', activeTab.value === tab ? 'bg-blue-500 text-white' : '']
-/* USAGE EDIT */
+
const enableUsageEdit = () => {
originalUsage.value = displayedUsage.value
usageEdit.enableEdit()
@@ -277,7 +255,6 @@ const cancelUsageEdit = () => {
isEditing.value = false
}
-/* DESCRIPTION EDIT */
const enableDescriptionEdit = () => {
originalDescription.value = displayedDescription.value
descriptionEdit.enableEdit()
@@ -298,23 +275,15 @@ const cancelDescriptionEdit = () => {
onMounted(async () => {
const settings = await settingsStore.getSettings()
if (settings) {
- defaultLangId.value = settings.app.shop_default_language
- selectedLangId.value = defaultLangId.value
- activeLangId.value = defaultLangId.value
+ productStore.defaultLangId.value = settings.app.shop_default_language
+ selectedLangId.value = productStore.defaultLangId.value
+ activeLangId.value = productStore.defaultLangId.value
}
const id = route.params.product_id
if (id) {
productID.value = Number(id)
- await productStore.getProductDescription(defaultLangId.value, productID.value)
- await productStore.getDefaultProductDescription(defaultLangId.value, productID.value)
+ await productStore.getProductDescription(productStore.defaultLangId.value, productID.value)
+ await productStore.getDefaultProductDescription(productStore.defaultLangId.value, productID.value)
}
})
-
-
\ No newline at end of file
diff --git a/bo/src/stores/product.ts b/bo/src/stores/product.ts
index 9380645..9fa8164 100644
--- a/bo/src/stores/product.ts
+++ b/bo/src/stores/product.ts
@@ -1,3 +1,4 @@
+import { useSettingsStore } from '../stores/settings'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useFetchJson } from '@/composable/useFetchJson'
@@ -28,6 +29,9 @@ export const useProductStore = defineStore('product', () => {
const currentProduct = ref
(null)
const loading = ref(false)
const error = ref(null)
+ const settingsStore = useSettingsStore()
+
+ const defaultLangId = settingsStore.shopDefaultLanguage
async function getProductDescription(langId = 1, productID: number) {
loading.value = true
@@ -45,17 +49,6 @@ export const useProductStore = defineStore('product', () => {
}
}
- async function getDefaultProductDescription(langId: number, productID: number) {
- try {
- const response = await useFetchJson(
- `/api/v1/restricted/product-translation/get-product-description?productID=${productID}&productLangID=${langId}`
- )
- defaultProductDescription.value = response.items
- } catch (e: unknown) {
- console.error('Failed to load default product description:', e)
- }
- }
-
async function saveProductDescription(productID?: number, langId?: number, shopId = 1) {
const id = productID || 1
try {
@@ -83,7 +76,7 @@ export const useProductStore = defineStore('product', () => {
error.value = null
try {
- const response = await useFetchJson(`/api/v1/restricted/product-description/translate-product-description?productID=${productID}&productShopID=1&productFromLangID=${fromLangId}&productToLangID=${toLangId}&model=OpenAI`)
+ const response = await useFetchJson(`/api/v1/restricted/product-description/translate-product-description?productID=${productID}&productShopID=1&productFromLangID=${fromLangId}&productToLangID=${defaultLangId}&model=OpenAI`)
productDescription.value = response.items
return response.items
} catch (e: any) {
@@ -104,8 +97,8 @@ export const useProductStore = defineStore('product', () => {
currentProduct,
loading,
error,
+ defaultLangId,
getProductDescription,
- getDefaultProductDescription,
clearCurrentProduct,
saveProductDescription,
translateProductDescription,
diff --git a/bo/src/stores/settings.ts b/bo/src/stores/settings.ts
index 5fff967..784e085 100644
--- a/bo/src/stores/settings.ts
+++ b/bo/src/stores/settings.ts
@@ -7,6 +7,7 @@ import { ref } from 'vue'
export const useSettingsStore = defineStore('settings', () => {
const settings = ref(null)
const loaded = ref(false)
+ const shopDefaultLanguage= settings?.app?.shop_default_language
async function getSettings(): Promise {
if (loaded.value && settings.value) return settings.value
@@ -16,5 +17,5 @@ export const useSettingsStore = defineStore('settings', () => {
return resp.items
}
- return { settings, loaded, getSettings }
+ return { settings, loaded, shopDefaultLanguage, getSettings }
})