Files
negareh-console/src/pages/request/components/RequestItemsList.tsx
T
morteza c06415536a
deploy to danak / build_and_deploy (push) Has been cancelled
up
2026-06-26 16:25:30 +03:30

112 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { type FC } from 'react'
import Button from '@/components/Button'
import { Edit, ShoppingCart, TickSquare, Trash } from 'iconsax-react'
import { useGetProducts } from '../hooks/useRequestData'
import type { RequestType } from '../type/Types'
import { clx } from '@/helpers/utils'
type Props = {
items: RequestType[]
editingIndex: number | null
onEdit: (index: number) => void
onRemove: (index: number) => void
onSubmit: () => void
isPending: boolean
}
const RequestItemsList: FC<Props> = ({
items,
editingIndex,
onEdit,
onRemove,
onSubmit,
isPending,
}) => {
const { data: productsData } = useGetProducts()
const getProductTitle = (productId?: string) =>
productsData?.data?.find((p) => p.id === productId)?.title ?? 'محصول'
return (
<div className='bg-white w-full xl:w-[320px] shrink-0 py-6 px-5 h-fit rounded-3xl xl:sticky xl:top-6'>
<div className='flex items-center gap-2'>
<ShoppingCart size={20} color='black' />
<span className='text-sm font-medium'>اقلام درخواست</span>
{items.length > 0 && (
<span className='text-xs bg-primary/20 text-black rounded-full px-2 py-0.5 mr-auto'>
{items.length}
</span>
)}
</div>
{items.length === 0 ? (
<p className='text-description text-xs mt-6 leading-6'>
هنوز قلمی اضافه نشده. فرم را پر کنید و روی «افزودن به لیست» بزنید.
</p>
) : (
<ul className='mt-4 space-y-3 max-h-[360px] overflow-y-auto'>
{items.map((item, index) => (
<li
key={index}
className={clx(
'border rounded-2xl p-3 transition-colors',
editingIndex === index
? 'border-primary bg-primary/5'
: 'border-[#f0f2f8]'
)}
>
<div className='text-sm font-medium truncate'>
{getProductTitle(item.productId)}
</div>
{item.attachments.length > 0 && (
<div className='text-description text-xs mt-1'>
{item.attachments.length} پیوست
</div>
)}
<div className='flex gap-2 mt-3'>
<button
type='button'
onClick={() => onEdit(index)}
className='flex items-center gap-1 text-xs text-[#3B82F6] hover:opacity-80'
>
<Edit size={16} color='#3B82F6' />
ویرایش
</button>
<button
type='button'
onClick={() => onRemove(index)}
className='flex items-center gap-1 text-xs text-red-500 hover:opacity-80 mr-auto'
>
<Trash size={16} color='#ef4444' />
حذف
</button>
</div>
</li>
))}
</ul>
)}
<div className='mt-6 pt-4 border-t border-[#f0f2f8]'>
<Button
className='w-full'
onClick={onSubmit}
isLoading={isPending}
disabled={items.length === 0}
>
<div className='flex gap-2 items-center justify-center'>
<TickSquare size={20} color='black' />
<span>ثبت نهایی درخواست</span>
</div>
</Button>
{items.length === 0 && (
<p className='text-description text-[10px] text-center mt-2'>
حداقل یک قلم برای ثبت لازم است
</p>
)}
</div>
</div>
)
}
export default RequestItemsList