fix: currency/county

This commit is contained in:
2026-04-01 10:52:08 +02:00
parent 980fb1543b
commit 729b54ca1a
12 changed files with 161 additions and 49 deletions

View File

@@ -1,12 +1,16 @@
import { useCookie } from "@/composable/useCookie"
import { useFetchJson } from "@/composable/useFetchJson"
import type { Language } from "@/types"
import type { Country, Language } from "@/types"
import { reactive, ref } from "vue"
export const langs = reactive([] as Language[])
export const currentLang = ref<Language>()
const deflang = ref<Language>()
export const countries = reactive([] as Country[])
export const currentCountry = ref<Country>()
const defLang = ref<Language>()
const defCountry = ref<Country>()
const cookie = useCookie()
// Get available language codes for route matching
// export const availableLocales = computed(() => langs.map((l) => l.lang_code))
@@ -22,8 +26,27 @@ export async function initLangs() {
if (cc) {
idfromcookie = langs.find((x) => x.id == parseInt(cc))
}
deflang.value = items.find((x) => x.is_default == true)
currentLang.value = idfromcookie ?? deflang.value
defLang.value = items.find((x) => x.is_default == true)
currentLang.value = idfromcookie ?? defLang.value
} catch (error) {
console.error('Failed to fetch languages:', error)
}
}
// Initialize country/currency from API
export async function initCountryCurrency() {
try {
const { items } = await useFetchJson<Country[]>('/api/v1/restricted/langs-and-countries/get-countries')
countries.push(...items)
let idfromcookie = null
const cc = cookie.getCookie('country_id')
if (cc) {
idfromcookie = langs.find((x) => x.id == parseInt(cc))
}
defCountry.value = items.find((x) => x.id === defLang.value?.id)
currentCountry.value = idfromcookie ?? defCountry.value
} catch (error) {
console.error('Failed to fetch languages:', error)
}