feat: improve owner verification notifications by adding search parameters to index routes and updating product variant UI layout.
This commit is contained in:
parent
16fe9a3d9f
commit
62e6995191
@ -511,6 +511,63 @@ private function requestTitle(OwnerVerificationRequest $request): string
|
||||
return 'Item Baru';
|
||||
}
|
||||
|
||||
private function requestSearchTerm(OwnerVerificationRequest $request): ?string
|
||||
{
|
||||
if ($request->subject_type === Product::class) {
|
||||
if ($request->subject instanceof Product) {
|
||||
return $request->subject->name;
|
||||
}
|
||||
$payload = is_array($request->payload) ? $request->payload : [];
|
||||
foreach (['new', 'old'] as $key) {
|
||||
$section = $payload[$key] ?? null;
|
||||
if (is_array($section) && isset($section['name'])) {
|
||||
return (string) $section['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->subject_type === ProductVariant::class) {
|
||||
$payload = is_array($request->payload) ? $request->payload : [];
|
||||
$newData = $payload['new'] ?? [];
|
||||
if (isset($newData['product_name']) && $newData['product_name'] !== '-') {
|
||||
return $newData['product_name'];
|
||||
}
|
||||
if ($request->subject instanceof ProductVariant) {
|
||||
return $request->subject->product?->name ?? $request->subject->name;
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->subject_type === RawMaterial::class) {
|
||||
if ($request->subject instanceof RawMaterial) {
|
||||
return $request->subject->name;
|
||||
}
|
||||
$payload = is_array($request->payload) ? $request->payload : [];
|
||||
foreach (['new', 'old'] as $key) {
|
||||
$section = $payload[$key] ?? null;
|
||||
if (is_array($section) && isset($section['name'])) {
|
||||
return (string) $section['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->subject_type === Purchase::class) {
|
||||
if ($request->subject instanceof Purchase) {
|
||||
$request->subject->loadMissing('supplier');
|
||||
|
||||
return $request->subject->supplier?->name;
|
||||
}
|
||||
$payload = is_array($request->payload) ? $request->payload : [];
|
||||
foreach (['new', 'old'] as $key) {
|
||||
$section = $payload[$key] ?? null;
|
||||
if (is_array($section) && isset($section['supplier_name'])) {
|
||||
return (string) $section['supplier_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function notifyRequestSubmitter(
|
||||
OwnerVerificationRequest $request,
|
||||
string $title,
|
||||
@ -520,10 +577,13 @@ private function notifyRequestSubmitter(
|
||||
return;
|
||||
}
|
||||
|
||||
$searchTerm = $this->requestSearchTerm($request);
|
||||
$routeParams = $searchTerm !== null ? ['search' => $searchTerm] : [];
|
||||
|
||||
$url = match ($request->subject_type) {
|
||||
Product::class, ProductVariant::class => route('admin.master.products.index'),
|
||||
RawMaterial::class => route('admin.master.raw_materials.index'),
|
||||
Purchase::class => route('admin.manage.purchases.index'),
|
||||
Product::class, ProductVariant::class => route('admin.master.products.index', $routeParams),
|
||||
RawMaterial::class => route('admin.master.raw_materials.index', $routeParams),
|
||||
Purchase::class => route('admin.manage.purchases.index', $routeParams),
|
||||
MarketplaceSettings::class => route('admin.system.settings.index'),
|
||||
default => route('admin.dashboard'),
|
||||
};
|
||||
|
||||
@ -269,7 +269,8 @@ public function create(array $validated, User $user): Purchase
|
||||
$user,
|
||||
'Tambah Belanja',
|
||||
"Pengajuan belanja dari supplier {$purchase->supplier->name} senilai {$purchase->total_formatted} menunggu verifikasi owner.",
|
||||
route('admin.manage.purchases.index'),
|
||||
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
|
||||
$purchase->supplier->name,
|
||||
);
|
||||
|
||||
return $purchase;
|
||||
@ -315,7 +316,8 @@ public function update(Purchase $purchase, array $validated, User $user): void
|
||||
$user,
|
||||
'Ubah Belanja',
|
||||
"Pengajuan ubah belanja dari supplier {$purchase->supplier->name} menunggu verifikasi owner.",
|
||||
route('admin.manage.purchases.index'),
|
||||
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
|
||||
$purchase->supplier->name,
|
||||
);
|
||||
}
|
||||
|
||||
@ -351,7 +353,8 @@ public function delete(Purchase $purchase, User $user): void
|
||||
$user,
|
||||
'Hapus Belanja',
|
||||
"Pengajuan hapus belanja dari supplier {$purchase->supplier->name} menunggu verifikasi owner.",
|
||||
route('admin.manage.purchases.index'),
|
||||
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
|
||||
$purchase->supplier->name,
|
||||
);
|
||||
}
|
||||
|
||||
@ -502,13 +505,18 @@ private function decrementStock(PurchaseItem $item): void
|
||||
->decrement('stock', $item->quantity);
|
||||
}
|
||||
|
||||
private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl): void
|
||||
private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl, ?string $search = null): void
|
||||
{
|
||||
$ownerUrl = route('admin.manage.purchases.index');
|
||||
if ($search !== null) {
|
||||
$ownerUrl = route('admin.manage.purchases.index', ['search' => $search]);
|
||||
}
|
||||
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel} Menunggu Persetujuan Owner",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
route('admin.manage.purchases.index'),
|
||||
$ownerUrl,
|
||||
);
|
||||
|
||||
$this->pushNotificationService->sendToUser(
|
||||
|
||||
@ -27,7 +27,7 @@ public function transfer(int $variantId, int $quantity, User $user, ?string $not
|
||||
]);
|
||||
}
|
||||
|
||||
$variant = ProductVariant::query()->findOrFail($variantId);
|
||||
$variant = ProductVariant::query()->with('product')->findOrFail($variantId);
|
||||
|
||||
if ($variant->stock < $quantity) {
|
||||
throw ValidationException::withMessages([
|
||||
@ -71,18 +71,20 @@ public function transfer(int $variantId, int $quantity, User $user, ?string $not
|
||||
],
|
||||
]);
|
||||
|
||||
$productName = $variant->product?->name ?? $variant->name;
|
||||
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
'📦 Transfer Stok Ecer Menunggu Persetujuan Owner',
|
||||
"Pengajuan transfer {$quantity} pcs stok ecer untuk varian '{$variant->name}' menunggu verifikasi owner.",
|
||||
['owner', 'developer'],
|
||||
route('admin.master.products.index'),
|
||||
route('admin.master.products.index', ['search' => $productName]),
|
||||
);
|
||||
|
||||
$this->pushNotificationService->sendToUser(
|
||||
'📤 Pengajuan Transfer Terkirim',
|
||||
"Pengajuan transfer {$quantity} pcs stok ecer untuk varian '{$variant->name}' telah dikirim dan menunggu verifikasi owner.",
|
||||
$user->id,
|
||||
route('admin.master.products.index'),
|
||||
route('admin.master.products.index', ['search' => $productName]),
|
||||
);
|
||||
|
||||
return $request;
|
||||
|
||||
@ -163,7 +163,8 @@ public function create(array $validated, User $user): void
|
||||
$user,
|
||||
'Tambah Produk',
|
||||
"Pengajuan tambah produk '{$validated['name']}' menunggu verifikasi owner.",
|
||||
route('admin.master.products.index'),
|
||||
route('admin.master.products.index', ['search' => $validated['name']]),
|
||||
$validated['name'],
|
||||
);
|
||||
}
|
||||
|
||||
@ -204,7 +205,8 @@ public function update(Product $product, array $validated, User $user): void
|
||||
$user,
|
||||
'Ubah Produk',
|
||||
"Pengajuan ubah produk '{$product->name}' menunggu verifikasi owner.",
|
||||
route('admin.master.products.index'),
|
||||
route('admin.master.products.index', ['search' => $product->name]),
|
||||
$product->name,
|
||||
);
|
||||
}
|
||||
|
||||
@ -236,7 +238,8 @@ public function delete(Product $product, User $user): void
|
||||
$user,
|
||||
'Hapus Produk',
|
||||
"Pengajuan hapus produk '{$product->name}' menunggu verifikasi owner.",
|
||||
route('admin.master.products.index'),
|
||||
route('admin.master.products.index', ['search' => $product->name]),
|
||||
$product->name,
|
||||
);
|
||||
}
|
||||
|
||||
@ -276,7 +279,8 @@ public function toggleStatus(Product $product, array $validated, User $user): vo
|
||||
$user,
|
||||
'Ubah Status Produk',
|
||||
"Pengajuan ubah status produk '{$product->name}' menjadi {$statusLabel} menunggu verifikasi owner.",
|
||||
route('admin.master.products.index'),
|
||||
route('admin.master.products.index', ['search' => $product->name]),
|
||||
$product->name,
|
||||
);
|
||||
}
|
||||
|
||||
@ -441,13 +445,18 @@ public function applyToggleStatus(OwnerVerificationRequest $verificationRequest)
|
||||
]);
|
||||
}
|
||||
|
||||
private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl): void
|
||||
private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl, ?string $search = null): void
|
||||
{
|
||||
$ownerUrl = route('admin.master.products.index');
|
||||
if ($search !== null) {
|
||||
$ownerUrl = route('admin.master.products.index', ['search' => $search]);
|
||||
}
|
||||
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel} Menunggu Persetujuan Owner",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
route('admin.master.products.index'),
|
||||
$ownerUrl,
|
||||
);
|
||||
|
||||
$this->pushNotificationService->sendToUser(
|
||||
|
||||
@ -149,7 +149,8 @@ public function create(array $validated, User $user): void
|
||||
$user,
|
||||
'Tambah Bahan Baku',
|
||||
"Pengajuan tambah bahan baku '{$validated['name']}' menunggu verifikasi owner.",
|
||||
route('admin.master.raw_materials.index'),
|
||||
route('admin.master.raw_materials.index', ['search' => $validated['name']]),
|
||||
$validated['name'],
|
||||
);
|
||||
}
|
||||
|
||||
@ -190,7 +191,8 @@ public function update(RawMaterial $rawMaterial, array $validated, User $user):
|
||||
$user,
|
||||
'Ubah Bahan Baku',
|
||||
"Pengajuan ubah bahan baku '{$rawMaterial->name}' menunggu verifikasi owner.",
|
||||
route('admin.master.raw_materials.index'),
|
||||
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
|
||||
$rawMaterial->name,
|
||||
);
|
||||
}
|
||||
|
||||
@ -222,7 +224,8 @@ public function delete(RawMaterial $rawMaterial, User $user): void
|
||||
$user,
|
||||
'Hapus Bahan Baku',
|
||||
"Pengajuan hapus bahan baku '{$rawMaterial->name}' menunggu verifikasi owner.",
|
||||
route('admin.master.raw_materials.index'),
|
||||
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
|
||||
$rawMaterial->name,
|
||||
);
|
||||
}
|
||||
|
||||
@ -262,7 +265,8 @@ public function toggleStatus(RawMaterial $rawMaterial, array $validated, User $u
|
||||
$user,
|
||||
'Ubah Status Bahan Baku',
|
||||
"Pengajuan ubah status bahan baku '{$rawMaterial->name}' menjadi {$statusLabel} menunggu verifikasi owner.",
|
||||
route('admin.master.raw_materials.index'),
|
||||
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
|
||||
$rawMaterial->name,
|
||||
);
|
||||
}
|
||||
|
||||
@ -302,13 +306,18 @@ public function clearVerificationRequestMedia(OwnerVerificationRequest $verifica
|
||||
}
|
||||
}
|
||||
|
||||
private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl): void
|
||||
private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl, ?string $search = null): void
|
||||
{
|
||||
$ownerUrl = route('admin.master.raw_materials.index');
|
||||
if ($search !== null) {
|
||||
$ownerUrl = route('admin.master.raw_materials.index', ['search' => $search]);
|
||||
}
|
||||
|
||||
$this->pushNotificationService->sendToRoles(
|
||||
"📦 {$typeLabel} Menunggu Persetujuan Owner",
|
||||
$body,
|
||||
['owner', 'developer'],
|
||||
route('admin.master.raw_materials.index'),
|
||||
$ownerUrl,
|
||||
);
|
||||
|
||||
$this->pushNotificationService->sendToUser(
|
||||
|
||||
@ -76,6 +76,9 @@ async function markAsRead(notification: NotificationItem): Promise<void> {
|
||||
}
|
||||
|
||||
function openNotification(notification: NotificationItem): void {
|
||||
if (!notification.is_read) {
|
||||
void markAsRead(notification);
|
||||
}
|
||||
if (notification.url) {
|
||||
isOpen.value = false;
|
||||
router.visit(notification.url);
|
||||
@ -201,7 +204,7 @@ onUnmounted(() => {
|
||||
<CheckCheck class="size-3.5" />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Tandai semua dibaca</TooltipContent>
|
||||
<TooltipContent class="z-[300]">Tandai semua dibaca</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip v-if="notifications.length > 0">
|
||||
<TooltipTrigger as-child>
|
||||
@ -212,7 +215,7 @@ onUnmounted(() => {
|
||||
<Trash2 class="size-3.5" />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Hapus semua</TooltipContent>
|
||||
<TooltipContent class="z-[300]">Hapus semua</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
@ -269,7 +272,7 @@ onUnmounted(() => {
|
||||
<Eye class="size-3.5" />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Tandai dibaca</TooltipContent>
|
||||
<TooltipContent class="z-[300]">Tandai dibaca</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
@ -280,7 +283,7 @@ onUnmounted(() => {
|
||||
<X class="size-3.5" />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Hapus</TooltipContent>
|
||||
<TooltipContent class="z-[300]">Hapus</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -52,7 +52,7 @@ const emit = defineEmits<{
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<FieldGroup>
|
||||
<FieldSet class="grid gap-4 md:grid-cols-2">
|
||||
<FieldSet class="grid gap-4 md:grid-cols-3">
|
||||
<Field>
|
||||
<FieldLabel :for="`variant_name_${variant.client_id}`" required>
|
||||
Nama Varian
|
||||
|
||||
Loading…
Reference in New Issue
Block a user