feat: enhance Restock feature by adding photo URLs to Restock model and displaying images in RestockCard

This commit is contained in:
Yoga Pangestu 2026-08-15 16:26:12 +07:00
parent bac9f79087
commit a10519ab9d
3 changed files with 25 additions and 0 deletions

View File

@ -46,6 +46,16 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
->orderBy($sort, $direction)
->paginate($perPage);
$paginator->getCollection()->each(function (Restock $restock) {
$restockMedia = $restock->getMedia('photos');
$restock->photo_urls = $restockMedia->map(
fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath())
)->toArray();
$restock->photo_conversion_urls = $restockMedia->map(
fn ($media) => $this->s3Service->getTemporaryUrl($media->getPath('thumb'))
)->toArray();
});
return $paginator;
}

View File

@ -28,6 +28,8 @@ export type Restock = {
items_count: number;
total_qty: number;
product_names: string | null;
photo_urls: string[];
photo_conversion_urls: string[];
created_by: {
id: number;
user_profile: {

View File

@ -1,4 +1,5 @@
import { ChevronDown, Pencil, Trash2 } from 'lucide-react';
import { ImagePreviewButton } from '@/components/dialogs';
import { RowActions } from '@/components/data-display';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
@ -118,6 +119,18 @@ export function RestockCardRow({
{formatCurrency(restock.total)}
</span>
</div>
{restock.photo_urls && restock.photo_urls.length > 0 && (
<div className="mt-2">
<ImagePreviewButton
srcs={restock.photo_conversion_urls?.length ? restock.photo_conversion_urls : restock.photo_urls}
modalSrcs={restock.photo_urls}
title={productNames.length > 0 ? productNames.join(', ') : 'Restock'}
description={formatDateTime(restock.created_at)}
className="h-16 w-16"
/>
</div>
)}
</div>
{(can('restocks.update') || can('restocks.delete')) && (