fix: added page PageProductCardFull and Addresses
This commit is contained in:
@@ -1,222 +0,0 @@
|
||||
<template>
|
||||
<div class="container my-10 ">
|
||||
|
||||
<div
|
||||
class="flex items-end justify-between gap-4 mb-6 bg-(--second-light) dark:bg-(--main-dark) border border-(--border-light) dark:border-(--border-dark) p-4 rounded-md">
|
||||
<div class="flex items-end gap-3">
|
||||
<USelect v-model="selectedLanguage" :items="availableLangs" variant="outline" class="w-40!" valueKey="iso_code">
|
||||
<template #default="{ modelValue }">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-md">{{availableLangs.find(x => x.iso_code == modelValue)?.flag}}</span>
|
||||
<span class="font-medium dark:text-white text-black">{{availableLangs.find(x => x.iso_code ==
|
||||
modelValue)?.name}}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template #item-leading="{ item }">
|
||||
<div class="flex items-center rounded-md cursor-pointer transition-colors">
|
||||
<span class="text-md">{{ item.flag }}</span>
|
||||
<span class="ml-2 dark:text-white text-black font-medium">{{ item.name }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</USelect>
|
||||
</div>
|
||||
<UButton @click="translateToSelectedLanguage" color="primary" :loading="translating"
|
||||
class="text-white bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) px-12!">
|
||||
Translate
|
||||
</UButton>
|
||||
</div>
|
||||
|
||||
<!-- Loading Overlay -->
|
||||
<div v-if="translating" class="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
|
||||
<div class="flex flex-col items-center gap-4 p-8 bg-(--main-light) dark:bg-(--main-dark) rounded-lg shadow-xl">
|
||||
<UIcon name="svg-spinners:ring-resize" class="text-4xl text-primary" />
|
||||
<p class="text-lg font-medium dark:text-white text-black">Translating...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-start gap-30">
|
||||
<p class="p-80 bg-(--second-light)">img</p>
|
||||
<div class="flex flex-col gap-2">
|
||||
<p class="text-[25px] font-bold text-black dark:text-white">
|
||||
{{ productStore.productDescription.name }}
|
||||
</p>
|
||||
<p v-html="productStore.productDescription.description_short" class="text-black dark:text-white"></p>
|
||||
<div class="space-y-[10px]">
|
||||
<div class="flex items-center gap-1">
|
||||
<UIcon name="lets-icons:done-ring-round-fill" class="text-[20px] text-green-600" />
|
||||
<p class="text-[16px] font-bold text-(--accent-blue-light) dark:text-(--accent-blue-dark)">
|
||||
{{ productStore.productDescription.available_now }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<UIcon name="marketeq:car-shipping" class="text-[25px] text-green-600" />
|
||||
<p class="text-[18px] font-bold text-black dark:text-white">
|
||||
{{ productStore.productDescription.delivery_in_stock }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-16">
|
||||
<div class="flex gap-4 my-6">
|
||||
<UButton @click="activeTab = 'description'"
|
||||
:class="['cursor-pointer', activeTab === 'description' ? 'bg-blue-500 text-white' : '']" color="neutral"
|
||||
variant="outline">
|
||||
<p class="dark:text-white">Description</p>
|
||||
</UButton>
|
||||
|
||||
<UButton @click="activeTab = 'usage'"
|
||||
:class="['cursor-pointer', activeTab === 'usage' ? 'bg-blue-500 text-white' : '']" color="neutral"
|
||||
variant="outline">
|
||||
<p class="dark:text-white">Usage</p>
|
||||
</UButton>
|
||||
</div>
|
||||
|
||||
<div v-if="activeTab === 'usage'"
|
||||
class="px-8 py-4 border border-(--border-light) dark:border-(--border-dark) rounded-md bg-(--second-light) dark:bg-(--main-dark)">
|
||||
|
||||
<div class="flex justify-end items-center gap-3 mb-4">
|
||||
<UButton v-if="!isEditing" @click="enableEdit"
|
||||
class="flex items-center gap-2 m-2 cursor-pointer bg-(--accent-blue-light)! dark:bg-(--accent-blue-dark)!">
|
||||
<p class="text-white">Change Text</p>
|
||||
<UIcon name="material-symbols-light:stylus-note-sharp" class="text-[30px] text-white!" />
|
||||
</UButton>
|
||||
<UButton v-if="isEditing" @click="saveText" color="neutral" variant="outline" class="p-2.5 cursor-pointer">
|
||||
<p class="dark:text-white text-black">Save the edited text</p>
|
||||
</UButton>
|
||||
<UButton v-if="isEditing" @click="cancelEdit" color="neutral" variant="outline" class="p-2.5 cursor-pointer">
|
||||
Cancel
|
||||
</UButton>
|
||||
</div>
|
||||
<p ref="usageRef" v-html="productStore.productDescription.usage"
|
||||
class="flex flex-col justify-center w-full text-start dark:text-white! text-black!"></p>
|
||||
|
||||
</div>
|
||||
|
||||
<div v-if="activeTab === 'description'"
|
||||
class="px-8 py-4 border border-(--border-light) dark:border-(--border-dark) rounded-md bg-(--second-light) dark:bg-(--main-dark)">
|
||||
<div class="flex items-center justify-end gap-3 mb-4">
|
||||
<UButton v-if="!descriptionEdit.isEditing.value" @click="enableDescriptionEdit"
|
||||
class="flex items-center gap-2 m-2 cursor-pointer bg-(--accent-blue-light)! dark:bg-(--accent-blue-dark)!">
|
||||
<p class="text-white">Change Text</p>
|
||||
<UIcon name="material-symbols-light:stylus-note-sharp" class="text-[30px] text-white!" />
|
||||
</UButton>
|
||||
<UButton v-if="descriptionEdit.isEditing.value" @click="saveDescription" color="neutral" variant="outline" class="p-2.5 cursor-pointer">
|
||||
<p class="dark:text-white text-black ">Save the edited text</p>
|
||||
</UButton>
|
||||
<UButton v-if="descriptionEdit.isEditing.value" @click="cancelDescriptionEdit" color="neutral" variant="outline" class="p-2.5 cursor-pointer">Cancel</UButton>
|
||||
</div>
|
||||
<div ref="descriptionRef" v-html="productStore.productDescription.description"
|
||||
class="flex flex-col justify-center dark:text-white text-black">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { useProductStore } from '@/stores/product'
|
||||
import { useEditable } from '@/composable/useConteditable'
|
||||
import { langs } from '@/router/langs'
|
||||
import type { Language } from '@/types'
|
||||
|
||||
const activeTab = ref('description')
|
||||
const productStore = useProductStore()
|
||||
const translating = ref(false)
|
||||
|
||||
// const availableLangs = computed(() => {
|
||||
// return langs.filter((l: Language) => ['cs', 'pl', 'der'].includes(l.iso_code))
|
||||
// })
|
||||
|
||||
const isEditing = ref(false)
|
||||
|
||||
const availableLangs = computed(() => langs)
|
||||
|
||||
const selectedLanguage = ref('pl')
|
||||
|
||||
const currentLangId = ref(2)
|
||||
|
||||
const fetchForLanguage = async (langCode: string) => {
|
||||
const lang = langs.find((l: Language) => l.iso_code === langCode)
|
||||
if (lang) {
|
||||
await productStore.getProductDescription(lang.id)
|
||||
currentLangId.value = lang.id
|
||||
}
|
||||
}
|
||||
|
||||
const translateToSelectedLanguage = async () => {
|
||||
const targetLang = langs.find((l: Language) => l.iso_code === selectedLanguage.value)
|
||||
if (targetLang && currentLangId.value) {
|
||||
translating.value = true
|
||||
try {
|
||||
await productStore.translateProductDescription(currentLangId.value, targetLang.id)
|
||||
currentLangId.value = targetLang.id
|
||||
} finally {
|
||||
translating.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await fetchForLanguage(selectedLanguage.value)
|
||||
const descriptionRef = ref<HTMLElement | null>(null)
|
||||
const usageRef = ref<HTMLElement | null>(null)
|
||||
|
||||
const descriptionEdit = useEditable(descriptionRef)
|
||||
const usageEdit = useEditable(usageRef)
|
||||
|
||||
const originalDescription = ref('')
|
||||
const originalUsage = ref('')
|
||||
|
||||
const saveDescription = async () => {
|
||||
descriptionEdit.disableEdit()
|
||||
await productStore.saveProductDescription()
|
||||
}
|
||||
|
||||
const cancelDescriptionEdit = () => {
|
||||
if (descriptionRef.value) {
|
||||
descriptionRef.value.innerHTML = originalDescription.value
|
||||
}
|
||||
descriptionEdit.disableEdit()
|
||||
}
|
||||
|
||||
const enableDescriptionEdit = () => {
|
||||
if (descriptionRef.value) {
|
||||
originalDescription.value = descriptionRef.value.innerHTML
|
||||
}
|
||||
descriptionEdit.enableEdit()
|
||||
}
|
||||
|
||||
const enableEdit = () => {
|
||||
if (usageRef.value) {
|
||||
originalUsage.value = usageRef.value.innerHTML
|
||||
}
|
||||
isEditing.value = true
|
||||
usageEdit.enableEdit()
|
||||
}
|
||||
|
||||
const saveText = () => {
|
||||
usageEdit.disableEdit()
|
||||
isEditing.value = false
|
||||
productStore.saveProductDescription()
|
||||
}
|
||||
|
||||
const cancelEdit = () => {
|
||||
if (usageRef.value) {
|
||||
usageRef.value.innerHTML = originalUsage.value
|
||||
}
|
||||
usageEdit.disableEdit()
|
||||
isEditing.value = false
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.images {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 70px;
|
||||
margin: 20px 0 20px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,257 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useProductStore, type Product } from '@/stores/product'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { TableColumn } from '@nuxt/ui'
|
||||
import { h } from 'vue'
|
||||
|
||||
const router = useRouter()
|
||||
const authStore = useAuthStore()
|
||||
const productStore = useProductStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
const searchName = ref('')
|
||||
const searchCode = ref('')
|
||||
const priceFromFilter = ref<number | null>(null)
|
||||
const priceToFilter = ref<number | null>(null)
|
||||
|
||||
// Pagination
|
||||
const page = ref(1)
|
||||
const pageSize = 5
|
||||
|
||||
// Fetch products on mount
|
||||
onMounted(() => {
|
||||
productStore.getProductDescription()
|
||||
})
|
||||
|
||||
// Filtered products
|
||||
// const filteredProducts = computed(() => {
|
||||
// console.log(productStore.products);
|
||||
|
||||
// return productStore.products.filter(product => {
|
||||
// const matchesName = product.name.toLowerCase().includes(searchName.value.toLowerCase())
|
||||
// const matchesCode = product.code.toLowerCase().includes(searchCode.value.toLowerCase())
|
||||
// const matchesPriceFrom = priceFromFilter.value === null || product.priceFrom >= priceFromFilter.value
|
||||
// const matchesPriceTo = priceToFilter.value === null || product.priceTo <= priceToFilter.value
|
||||
|
||||
// return matchesName && matchesCode && matchesPriceFrom && matchesPriceTo
|
||||
// })
|
||||
// })
|
||||
|
||||
// const totalItems = computed(() => filteredProducts.value.length)
|
||||
|
||||
// const paginatedProducts = computed(() => {
|
||||
// const start = (page.value - 1) * pageSize
|
||||
// const end = start + pageSize
|
||||
// return filteredProducts.value.slice(start, end)
|
||||
// })
|
||||
|
||||
// Reset page when filters change
|
||||
function resetPage() {
|
||||
page.value = 1
|
||||
}
|
||||
|
||||
// Navigate to product detail
|
||||
function goToProduct(product: Product) {
|
||||
router.push({ name: 'product-detail', params: { id: product.id } })
|
||||
}
|
||||
|
||||
// Table columns
|
||||
const columns = computed<TableColumn<Product>[]>(() => [
|
||||
{
|
||||
accessorKey: 'image',
|
||||
header: () => h('div', { class: 'text-center' }, t('products.image')),
|
||||
cell: ({ row }) => h('img', {
|
||||
src: row.getValue('image'),
|
||||
alt: 'Product',
|
||||
class: 'w-12 h-12 object-cover rounded'
|
||||
})
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('products.product_name'),
|
||||
cell: ({ row }) => {
|
||||
const product = row.original
|
||||
return h('button', {
|
||||
class: 'text-primary hover:underline font-medium text-left',
|
||||
onClick: (e: Event) => { e.stopPropagation(); goToProduct(product) }
|
||||
}, product.name)
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: 'code',
|
||||
header: t('products.product_code'),
|
||||
},
|
||||
{
|
||||
accessorKey: 'description',
|
||||
header: t('products.description'),
|
||||
cell: ({ row }) => {
|
||||
const desc = row.getValue('description') as string
|
||||
return h('span', { class: 'text-sm text-gray-500 dark:text-gray-400' }, desc?.substring(0, 50) + (desc && desc.length > 50 ? '...' : ''))
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: 'inStock',
|
||||
header: t('products.in_stock'),
|
||||
cell: ({ row }) => {
|
||||
const inStock = row.getValue('inStock')
|
||||
return h('span', {
|
||||
class: inStock ? 'text-green-600 font-medium' : 'text-red-600 font-medium'
|
||||
}, inStock ? t('products.yes') : t('products.no'))
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: 'price',
|
||||
header: t('products.price'),
|
||||
cell: ({ row }) => {
|
||||
const priceFromVal = row.original.priceFrom
|
||||
const priceToVal = row.original.priceTo
|
||||
return `${priceFromVal} - ${priceToVal}`
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: 'count',
|
||||
header: t('products.count'),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: ({ row }) => {
|
||||
const product = row.original
|
||||
return h('div', { class: 'flex gap-2' }, [
|
||||
h('button', {
|
||||
class: 'px-3 py-1.5 text-sm font-medium bg-primary text-white rounded-lg hover:bg-blue-600 transition-colors',
|
||||
onClick: (e: Event) => { e.stopPropagation(); addToCart(product) }
|
||||
}, t('products.add_to_cart')),
|
||||
h('button', {
|
||||
class: 'px-3 py-1.5 text-sm font-medium bg-gray-200 dark:bg-gray-700 text-black dark:text-white rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors',
|
||||
onClick: (e: Event) => { e.stopPropagation(); incrementCount(product) }
|
||||
}, '+')
|
||||
])
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
// Actions
|
||||
function addToCart(product: Product) {
|
||||
console.log('Add to cart:', product)
|
||||
}
|
||||
|
||||
function incrementCount(product: Product) {
|
||||
product.count++
|
||||
}
|
||||
|
||||
function clearFilters() {
|
||||
searchName.value = ''
|
||||
searchCode.value = ''
|
||||
priceFromFilter.value = null
|
||||
priceToFilter.value = null
|
||||
resetPage()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="container">
|
||||
<div class="p-6 bg-white dark:bg-(--black) min-h-screen font-sans">
|
||||
<div >
|
||||
<!-- v-html="productStore.products" -->
|
||||
</div>
|
||||
<h1 class="text-2xl font-bold mb-6 text-black dark:text-white">{{ t('products.title') }}</h1>
|
||||
|
||||
<div v-if="!authStore.isAuthenticated" class="mb-4 p-3 bg-yellow-100 text-yellow-700 rounded">
|
||||
{{ t('products.login_to_view') }}
|
||||
</div>
|
||||
|
||||
<!-- Loading State -->
|
||||
<div v-if="productStore.loading" class="mb-4 p-3 bg-blue-100 text-blue-700 rounded">
|
||||
{{ t('products.loading') }}...
|
||||
</div>
|
||||
|
||||
<!-- Error State -->
|
||||
<div v-if="productStore.error" class="mb-4 p-3 bg-red-100 text-red-700 rounded">
|
||||
{{ productStore.error }}
|
||||
</div>
|
||||
|
||||
<div v-if="authStore.isAuthenticated && !productStore.loading && !productStore.error" class="space-y-4">
|
||||
<!-- Filter Block -->
|
||||
<div class="flex flex-wrap gap-4 mb-4 p-4 border border-(--border-light) dark:border-(--border-dark) rounded bg-gray-50 dark:bg-gray-800">
|
||||
<div class="flex flex-col min-w-[180px]">
|
||||
<label class="mb-1 text-sm font-medium text-black dark:text-white">{{ t('products.search_by_name') }}</label>
|
||||
<UInput
|
||||
v-model="searchName"
|
||||
:placeholder="t('products.search_name_placeholder')"
|
||||
@update:model-value="resetPage"
|
||||
class="dark:text-white text-black"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col min-w-[180px]">
|
||||
<label class="mb-1 text-sm font-medium text-black dark:text-white">{{ t('products.search_by_code') }}</label>
|
||||
<UInput
|
||||
v-model="searchCode"
|
||||
:placeholder="t('products.search_code_placeholder')"
|
||||
@update:model-value="resetPage"
|
||||
class="dark:text-white text-black"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col min-w-[120px]">
|
||||
<label class="mb-1 text-sm font-medium text-black dark:text-white">{{ t('products.price_from') }}</label>
|
||||
<UInput
|
||||
v-model="priceFromFilter"
|
||||
type="number"
|
||||
:placeholder="t('products.price_from')"
|
||||
@update:model-value="resetPage"
|
||||
class="dark:text-white text-black"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col min-w-[120px]">
|
||||
<label class="mb-1 text-sm font-medium text-black dark:text-white">{{ t('products.price_to') }}</label>
|
||||
<UInput
|
||||
v-model="priceToFilter"
|
||||
type="number"
|
||||
:placeholder="t('products.price_to')"
|
||||
@update:model-value="resetPage"
|
||||
class="dark:text-white text-black"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex items-end">
|
||||
<button
|
||||
@click="clearFilters"
|
||||
class="px-4 py-2 text-sm font-medium text-black dark:text-white bg-gray-200 dark:bg-gray-700 rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors"
|
||||
>
|
||||
{{ t('products.clear_filters') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Products Table -->
|
||||
<!-- <div class="border border-(--border-light) dark:border-(--border-dark) rounded overflow-hidden">
|
||||
<UTable
|
||||
:data="paginatedProducts"
|
||||
:columns="columns"
|
||||
class="dark:text-white! text-dark"
|
||||
/>
|
||||
</div> -->
|
||||
|
||||
<!-- Empty State -->
|
||||
<!-- <div v-if="filteredProducts.length === 0" class="text-center py-10 text-gray-500 dark:text-gray-400">
|
||||
{{ t('products.no_products') }}
|
||||
</div> -->
|
||||
|
||||
<!-- Pagination -->
|
||||
<!-- <div v-if="filteredProducts.length > 0" class="pt-4 flex justify-center items-center dark:text-white! text-dark">
|
||||
<UPagination
|
||||
v-model:page="page"
|
||||
:page-count="pageSize"
|
||||
:total="totalItems"
|
||||
/>
|
||||
</div> -->
|
||||
|
||||
<!-- Results count -->
|
||||
<!-- <div v-if="filteredProducts.length > 0" class="text-sm text-gray-600 dark:text-gray-400 text-center">
|
||||
{{ t('products.showing') }} {{ paginatedProducts.length }} {{ t('products.of') }} {{ totalItems }} {{ t('products.products') }}
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user