diff --git a/resources/js/pages/admin/manage/transaction/create.tsx b/resources/js/pages/admin/manage/transaction/create.tsx index da9df82..f04171f 100644 --- a/resources/js/pages/admin/manage/transaction/create.tsx +++ b/resources/js/pages/admin/manage/transaction/create.tsx @@ -1,7 +1,7 @@ 'use no memo'; import { Form, Head, Link, usePage } from '@inertiajs/react'; -import { ArrowLeft, Minus, Plus, ShoppingCart, Trash2 } from 'lucide-react'; +import { ArrowLeft, Minus, Plus, Search, ShoppingCart, Trash2 } from 'lucide-react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { toast } from 'sonner'; import { ConfirmDialog } from '@/components/dialogs'; @@ -9,6 +9,7 @@ import { ImagePreviewModal } from '@/components/dialogs'; import { FileUpload } from '@/components/inputs'; import { NumberInput } from '@/components/inputs'; import { RupiahInput } from '@/components/inputs'; +import { Input } from '@/components/ui/input'; import { InputError } from '@/components/ui'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; @@ -117,6 +118,7 @@ export default function TransactionCreate({ const [cartRemoveKey, setCartRemoveKey] = useState(null); const [tiktokOrderId, setTiktokOrderId] = useState(draft?.tiktokOrderId ?? ''); const [shopeeOrderId, setShopeeOrderId] = useState(draft?.shopeeOrderId ?? ''); + const [variantSearch, setVariantSearch] = useState(''); const quantitiesRef = useRef(quantities); @@ -162,6 +164,19 @@ export default function TransactionCreate({ [products, selectedProductId], ); + const groupedVariants = useMemo(() => { + if (!variantSearch) return []; + const search = variantSearch.toLowerCase(); + return products + .map((p) => ({ + ...p, + product_variants: p.product_variants.filter((v) => + v.name.toLowerCase().includes(search), + ), + })) + .filter((p) => p.product_variants.length > 0); + }, [products, variantSearch]); + const variantById = useMemo( () => new Map( @@ -414,7 +429,84 @@ export default function TransactionCreate({ /> - {selectedProduct && ( +
+ +
+ + setVariantSearch(e.target.value)} + className="pl-8" + /> +
+
+ + {variantSearch && groupedVariants.length > 0 && ( +
+ {groupedVariants.map((p) => ( +
+

{p.name}

+
+ {p.product_variants.map((variant) => { + const currentStock = + stockType === 'reject' + ? variant.reject_stock + : (isCashier ? variant.retail_stock : variant.stock); + + return ( +
0 + ? 'flex flex-wrap items-center justify-between gap-2 rounded-lg border border-primary p-3' + : 'flex flex-wrap items-center justify-between gap-2 rounded-lg border p-3' + } + > +
+ {variant.photo_url ? ( + {variant.name} + ) : ( +
N/A
+ )} +
+

{variant.name}

+

+ Stok: {formatQuantity(Number(currentStock))} pcs ยท {getUnitPrice(variant.id) <= 0 ? ( + Harga belum diatur + ) : ( + formatCurrency( + stockType === 'reject' + ? (variant.prices?.reject_selling ?? 0) + : (isCashier ? (variant.prices?.retail ?? 0) : (variant.prices?.[priceType] ?? 0)), + ) + )} +

+
+
+
+ + updateQuantity(variant.id, val)} /> + +
+
+ ); + })} +
+
+ ))} +
+ )} + + {variantSearch && groupedVariants.length === 0 && ( +

Tidak ada varian ditemukan.

+ )} + + {!variantSearch && selectedProduct && (
{selectedProduct.product_variants.map( (variant) => {