feat: enhance Restock feature by adding photo URLs to Restock model and displaying images in RestockCard
This commit is contained in:
parent
bac9f79087
commit
a10519ab9d
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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: {
|
||||
|
||||
@ -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')) && (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user