fix: cart
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<div class="flex flex-col md:flex-row justify-between items-center gap-4">
|
<div class="flex flex-col md:flex-row justify-between items-center gap-4">
|
||||||
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Shopping Carts') }}</h1>
|
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Shopping Carts') }}</h1>
|
||||||
<div class="flex gap-3">
|
<div class="flex gap-3">
|
||||||
<UButton color="primary" @click="showCreateModal = true"
|
<UButton color="primary" @click="showCreateModal = true" :disabled="cartStore.carts?.length >= 10"
|
||||||
class="bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) text-white hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light)">
|
class="bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) text-white hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light)">
|
||||||
<UIcon name="mdi:plus" class="mr-1" />
|
<UIcon name="mdi:plus" class="mr-1" />
|
||||||
{{ t('New Cart') }}
|
{{ t('New Cart') }}
|
||||||
@@ -27,10 +27,8 @@
|
|||||||
: 'hover:bg-gray-50 dark:hover:bg-gray-800 border-l-4 border-transparent'">
|
: 'hover:bg-gray-50 dark:hover:bg-gray-800 border-l-4 border-transparent'">
|
||||||
<div class="flex-1 min-w-0">
|
<div class="flex-1 min-w-0">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<p class="text-red-600 font-medium truncate">{{ cart.cart_id }}</p>
|
|
||||||
<p class="text-black dark:text-white font-medium truncate cursor-pointer"
|
<p class="text-black dark:text-white font-medium truncate cursor-pointer"
|
||||||
@click="openCart(cart)">{{
|
@click="openCart(cart)">{{ cart.name }}</p>
|
||||||
cart.name }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input type="checkbox" :checked="cartStore.activeCartId === cart.cart_id"
|
<input type="checkbox" :checked="cartStore.activeCartId === cart.cart_id"
|
||||||
@@ -89,12 +87,10 @@ async function createCart() {
|
|||||||
showCreateModal.value = false
|
showCreateModal.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
cartStore.fetchCarts()
|
cartStore.fetchCarts()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function openCart(cart) {
|
function openCart(cart) {
|
||||||
router.push({ name: 'customer-cart', params: { id: cart.cart_id } });
|
router.push({ name: 'customer-cart', params: { id: cart.cart_id } });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,57 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default">
|
|
||||||
<div class="pt-70! flex flex-col items-center justify-center bg-gray-50 dark:bg-(--main-dark)">
|
<div class="pt-70! flex flex-col items-center justify-center bg-gray-50 dark:bg-(--main-dark)">
|
||||||
<h1 class="text-6xl font-bold text-black dark:text-white mb-14">Search Products</h1>
|
<h1 class="text-6xl font-bold text-black dark:text-white mb-14">
|
||||||
|
Search Products
|
||||||
|
</h1>
|
||||||
|
|
||||||
<div class="w-full max-w-4xl">
|
<div class="w-full max-w-4xl">
|
||||||
<UInput icon="i-lucide-search" type="text" placeholder="Type product name or ID..."
|
<UInput icon="i-lucide-search" type="text" placeholder="Type product name or ID..."
|
||||||
v-model="searchQuery" class="w-full!" :ui="{ base: 'py-4! rounded-full!' }" />
|
v-model="searchQuery" class="w-full!" :ui="{ base: 'py-4! rounded-full!' }" />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="products.length" class="mt-6">
|
|
||||||
<UTable :data="products" :columns="columns" class="flex-1 w-full" :ui="{
|
<div v-if="loading" class="mt-6">
|
||||||
root: 'max-w-100wv overflow-auto!'
|
Loading...
|
||||||
}" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p v-else-if="searchQuery">
|
<div v-else-if="products.length" class="mt-6 w-full">
|
||||||
|
<UTable :data="products" :columns="columns" class="flex-1 w-full"
|
||||||
|
:ui="{ root: 'max-w-100wv overflow-auto!' }" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-else-if="searchQuery" class="mt-6">
|
||||||
No products found
|
No products found
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useFetchJson } from '@/composable/useFetchJson';
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
import Default from '@/layouts/default.vue';
|
import { ref, watch, computed, resolveComponent } from 'vue'
|
||||||
import { watch } from 'vue';
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { ref } from 'vue';
|
import { debounce } from 'chart.js/helpers'
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
|
import type { TableColumn } from '@nuxt/ui'
|
||||||
|
import type { Product } from '@/types/product'
|
||||||
|
import errorImg from '@/assets/error.svg'
|
||||||
|
|
||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
const products = ref([])
|
const products = ref<Product[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
|
|
||||||
async function fetchProducts() {
|
async function fetchProducts() {
|
||||||
|
if (!searchQuery.value.trim()) {
|
||||||
|
products.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
error.value = null
|
error.value = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const query = searchQuery.value
|
const query = `name=~${searchQuery.value.trim()}`
|
||||||
? `name=~${searchQuery.value}`
|
|
||||||
: ''
|
|
||||||
|
|
||||||
const result = await useFetchJson(
|
const result = await useFetchJson(
|
||||||
`/api/v1/restricted/list-products/get-listing?${query}`
|
`/api/v1/restricted/list-products/get-listing?${query}`
|
||||||
@@ -52,125 +65,90 @@ async function fetchProducts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const debouncedFetch = debounce(fetchProducts, 400)
|
||||||
|
|
||||||
watch(searchQuery, () => {
|
watch(searchQuery, () => {
|
||||||
fetchProducts()
|
debouncedFetch()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
import errorImg from '@/assets/error.svg'
|
const sortField = computed({
|
||||||
import type { TableColumn } from '@nuxt/ui';
|
get: () => [
|
||||||
import type { Product } from '@/types/product';
|
route.query.sort as string | undefined,
|
||||||
// const columns: TableColumn<Product>[] = [
|
route.query.direction as 'asc' | 'desc' | undefined
|
||||||
// {
|
],
|
||||||
// accessorKey: 'product_id',
|
set: ([sort]: [string, 'asc' | 'desc']) => {
|
||||||
// header: ({ column }) => {
|
const query = { ...route.query, sort, direction: 'asc' }
|
||||||
// return h('div', { class: 'flex flex-col gap-1' }, [
|
router.push({ query })
|
||||||
// h('div', {
|
}
|
||||||
// class: 'flex items-center gap-2 cursor-pointer',
|
})
|
||||||
// onClick: () => {
|
|
||||||
// sortField.value = ['product_id', 'asc']
|
|
||||||
// }
|
|
||||||
// }, [
|
|
||||||
// h('span', 'ID'),
|
|
||||||
// h(UIcon, {
|
|
||||||
// name: getIcon('product_id')
|
|
||||||
// })
|
|
||||||
// ]),
|
|
||||||
|
|
||||||
// h(UInput, {
|
function getIcon(name: string) {
|
||||||
// placeholder: 'Search...',
|
if (sortField.value[0] === name) {
|
||||||
// modelValue: filters.value[column.id] ?? '',
|
return sortField.value[1] === 'asc'
|
||||||
// 'onUpdate:modelValue': (val: string) => {
|
? 'i-lucide-arrow-up-narrow-wide'
|
||||||
// updateFilter(column.id, val)
|
: 'i-lucide-arrow-down-wide-narrow'
|
||||||
// },
|
}
|
||||||
// size: 'xs'
|
return 'i-lucide-arrow-up-down'
|
||||||
// })
|
}
|
||||||
// ])
|
|
||||||
// },
|
|
||||||
// // header: '#',
|
|
||||||
// cell: ({ row }) => `#${row.getValue('product_id') as number}`
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// accessorKey: 'image_link',
|
|
||||||
// header: 'Image',
|
|
||||||
// cell: ({ row }) => {
|
|
||||||
// return h('img', {
|
|
||||||
// src: row.getValue('image_link') as string,
|
|
||||||
// style: 'width:40px;height:40px;object-fit:cover;',
|
|
||||||
// onError: (e: Event) => {
|
|
||||||
// const target = e.target as HTMLImageElement
|
|
||||||
// target.src = errorImg
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// accessorKey: 'name',
|
|
||||||
// header: ({ column }) => {
|
|
||||||
// return h('div', { class: 'flex flex-col gap-1' }, [
|
|
||||||
// h('div', {
|
|
||||||
// class: 'flex items-center gap-2 cursor-pointer',
|
|
||||||
// onClick: () => {
|
|
||||||
// sortField.value = ['name', 'asc']
|
|
||||||
// }
|
|
||||||
// }, [
|
|
||||||
// h('span', 'Name'),
|
|
||||||
// h(UIcon, {
|
|
||||||
// name: getIcon('name')
|
|
||||||
// })
|
|
||||||
// ]),
|
|
||||||
|
|
||||||
// h(UInput, {
|
|
||||||
// placeholder: 'Search...',
|
const UInput = resolveComponent('UInput')
|
||||||
// modelValue: filters.value[column.id] ?? '',
|
const UButton = resolveComponent('UButton')
|
||||||
// 'onUpdate:modelValue': (val: string) => {
|
const UIcon = resolveComponent('UIcon')
|
||||||
// updateFilter(column.id, val)
|
|
||||||
// },
|
const columns: TableColumn<Product>[] = [
|
||||||
// size: 'xs'
|
{
|
||||||
// })
|
accessorKey: 'product_id',
|
||||||
// ])
|
header: 'ID',
|
||||||
// },
|
cell: ({ row }) => `#${row.getValue('product_id')}`
|
||||||
// cell: ({ row }) => row.getValue('name') as string,
|
},
|
||||||
// filterFn: (row, columnId, value) => {
|
{
|
||||||
// const name = row.getValue(columnId) as string
|
accessorKey: 'image_link',
|
||||||
// return name.toLowerCase().includes(value.toLowerCase())
|
header: 'Image',
|
||||||
// }
|
cell: ({ row }) =>
|
||||||
// },
|
h('img', {
|
||||||
// {
|
src: row.getValue('image_link'),
|
||||||
// accessorKey: 'quantity',
|
style: 'width:40px;height:40px;object-fit:cover;',
|
||||||
// header: ({ }) => {
|
onError: (e: Event) => {
|
||||||
// return h('div', { class: 'flex flex-col gap-1' }, [
|
(e.target as HTMLImageElement).src = errorImg
|
||||||
// h('div', {
|
}
|
||||||
// class: 'flex items-center gap-2 cursor-pointer',
|
})
|
||||||
// onClick: () => {
|
},
|
||||||
// sortField.value = ['quantity', 'asc']
|
{
|
||||||
// }
|
accessorKey: 'name',
|
||||||
// }, [
|
header: 'Name',
|
||||||
// h('span', 'In stock'),
|
cell: ({ row }) => row.getValue('name')
|
||||||
// h(UIcon, {
|
},
|
||||||
// name: getIcon('quantity')
|
{
|
||||||
// })
|
accessorKey: 'quantity',
|
||||||
// ]),
|
header: 'In stock',
|
||||||
// ])
|
cell: ({ row }) => row.getValue('quantity')
|
||||||
// },
|
},
|
||||||
// cell: ({ row }) => row.getValue('quantity') as number
|
{
|
||||||
// },
|
accessorKey: 'action',
|
||||||
// {
|
header: '',
|
||||||
// accessorKey: 'count',
|
cell: ({ row }) =>
|
||||||
// header: '',
|
h(
|
||||||
// cell: ({ row }) => {
|
UButton,
|
||||||
// return h(UButton, {
|
{
|
||||||
// onClick: () => {
|
onClick: () =>
|
||||||
// goToProduct(row.original.product_id, row.original.link_rewrite)
|
router.push({
|
||||||
// },
|
name: 'admin-product-details',
|
||||||
// class: 'cursor-pointer',
|
params: {
|
||||||
// color: 'info',
|
product_id: row.original.product_id,
|
||||||
// variant: 'soft'
|
link_rewrite: row.original.link_rewrite
|
||||||
// }, () => 'Show product')
|
}
|
||||||
// },
|
}),
|
||||||
// }
|
color: 'info',
|
||||||
// ]
|
variant: 'soft'
|
||||||
|
},
|
||||||
|
() => 'Show product'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -37,10 +37,15 @@ export const useCartStore = defineStore('cart', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addNewCart(name: string) {
|
async function addNewCart(name: string) {
|
||||||
|
if (!name.trim()) {
|
||||||
|
error.value = 'Cart name is required'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
error.value = null
|
error.value = null
|
||||||
|
|
||||||
const url = `/api/v1/restricted/carts/add-new-cart`
|
const url = `/api/v1/restricted/carts/add-new-cart?name=${name}`
|
||||||
const response = await useFetchJson<ApiResponse>(url)
|
const response = await useFetchJson<ApiResponse>(url)
|
||||||
|
|
||||||
const newCart: Cart = {
|
const newCart: Cart = {
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ INSERT IGNORE INTO `b2b_routes` (`id`, `name`, `path`, `component`, `meta`, `act
|
|||||||
}', 1),
|
}', 1),
|
||||||
(20, 'customer-products', 'products', '/components/customer/PageProducts.vue', '{ "guest":true, "name": "Products" }', 1),
|
(20, 'customer-products', 'products', '/components/customer/PageProducts.vue', '{ "guest":true, "name": "Products" }', 1),
|
||||||
(21, 'customer-product-details', 'products/:product_id', '/components/customer/PageProduct.vue', '{ "guest":true, "name": "Products" }', 1),
|
(21, 'customer-product-details', 'products/:product_id', '/components/customer/PageProduct.vue', '{ "guest":true, "name": "Products" }', 1),
|
||||||
(22, 'customer-page-carts', 'carts', '/components/customer/PageCarts.vue', '{ "guest":true, "name": "Carts" }', 1);
|
(22, 'customer-page-carts', 'carts', '/components/customer/PageCarts.vue', '{ "guest":true, "name": "Carts" }', 1),
|
||||||
|
(24, 'customer-search-products', 'search-products', '/components/customer/PageSearchProducts.vue', '{ "guest":true, "name": "Carts" }', 1);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS b2b_top_menu (
|
CREATE TABLE IF NOT EXISTS b2b_top_menu (
|
||||||
menu_id INT AUTO_INCREMENT NOT NULL,
|
menu_id INT AUTO_INCREMENT NOT NULL,
|
||||||
@@ -286,6 +287,28 @@ INSERT IGNORE INTO `b2b_top_menu` (`menu_id`, `label`, `parent_id`, `params`, `a
|
|||||||
"locale": ""
|
"locale": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}', 1, 1),
|
||||||
|
(17, '{
|
||||||
|
"name": "customer-search-products",
|
||||||
|
"trans": {
|
||||||
|
"pl": {
|
||||||
|
"label": "Search-Products"
|
||||||
|
},
|
||||||
|
"en": {
|
||||||
|
"label": "Search-Products"
|
||||||
|
},
|
||||||
|
"de": {
|
||||||
|
"label": "Search-Products"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"icon": "proicons:cart1"
|
||||||
|
}', 1, '{
|
||||||
|
"route": {
|
||||||
|
"name": "customer-search-products",
|
||||||
|
"params": {
|
||||||
|
"locale": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
}', 1, 1);
|
}', 1, 1);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -114,5 +114,6 @@ INSERT INTO `b2b_route_roles` (`route_id`, `role_id`) VALUES
|
|||||||
(19, '1'),
|
(19, '1'),
|
||||||
(20, '1'),
|
(20, '1'),
|
||||||
(21, '1'),
|
(21, '1'),
|
||||||
(22, '1');
|
(22, '1'),
|
||||||
|
(24, '1');
|
||||||
-- +goose Down
|
-- +goose Down
|
||||||
Reference in New Issue
Block a user