fix available gifts filter
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
// app/(public)/invite/[slug]/gifts/page.tsx
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
@@ -121,21 +122,23 @@ export default function GiftRegistryPage() {
|
|||||||
|
|
||||||
// Process gifts into available and reserved categories
|
// Process gifts into available and reserved categories
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (items && guestPurchases.length >= 0) {
|
if (items && Array.isArray(items)) {
|
||||||
// Get IDs of gifts that this guest has reserved
|
// Get IDs of gifts that this guest has reserved
|
||||||
const reservedGiftIds = new Set(
|
const reservedGiftIds = new Set(
|
||||||
guestPurchases.map((purchase) => purchase.gift_id),
|
guestPurchases.map((purchase) => purchase.gift_id),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Available gifts (visible and not fully reserved)
|
// Available gifts:
|
||||||
|
// Only filter out gifts that:
|
||||||
|
// 1. Are not visible (is_visible === false)
|
||||||
|
// 2. Are already reserved by this guest (in reservedGiftIds)
|
||||||
|
// 3. Are completely received (is_fully_received === true)
|
||||||
|
// 4. Have been removed (status === "removed")
|
||||||
const available = items.filter(
|
const available = items.filter(
|
||||||
(item) =>
|
(item) =>
|
||||||
item.is_visible &&
|
item.is_visible &&
|
||||||
!reservedGiftIds.has(item.id) &&
|
item.status !== "removed" &&
|
||||||
(item.status === "available" ||
|
!item.is_fully_received,
|
||||||
(item.quantity_requested &&
|
|
||||||
item.quantity_received &&
|
|
||||||
item.quantity_received < item.quantity_requested)),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reserved gifts (this guest has reserved them)
|
// Reserved gifts (this guest has reserved them)
|
||||||
@@ -145,7 +148,6 @@ export default function GiftRegistryPage() {
|
|||||||
setReservedGifts(reserved);
|
setReservedGifts(reserved);
|
||||||
}
|
}
|
||||||
}, [items, guestPurchases]);
|
}, [items, guestPurchases]);
|
||||||
|
|
||||||
// Format priority for display
|
// Format priority for display
|
||||||
const formatPriority = (priority: string) => {
|
const formatPriority = (priority: string) => {
|
||||||
switch (priority) {
|
switch (priority) {
|
||||||
@@ -210,13 +212,10 @@ export default function GiftRegistryPage() {
|
|||||||
|
|
||||||
// Confirm reservation handler
|
// Confirm reservation handler
|
||||||
const handleConfirmReservation = async () => {
|
const handleConfirmReservation = async () => {
|
||||||
console.debug("Confirm reservation:", currentGuest);
|
|
||||||
if (!selectedGift || !currentGuest) {
|
if (!selectedGift || !currentGuest) {
|
||||||
console.error("Missing information ", { selectedGift, currentGuest });
|
|
||||||
setErrorMessage("Required information missing.");
|
setErrorMessage("Required information missing.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("Reserving: ", { selectedGift, currentGuest });
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await reserveItem(
|
await reserveItem(
|
||||||
@@ -284,7 +283,7 @@ export default function GiftRegistryPage() {
|
|||||||
<div className="container max-w-4xl mx-auto px-4 py-8">
|
<div className="container max-w-4xl mx-auto px-4 py-8">
|
||||||
<div className="flex flex-col items-center mb-8">
|
<div className="flex flex-col items-center mb-8">
|
||||||
<h1 className="text-3xl font-bold mb-2 text-center">
|
<h1 className="text-3xl font-bold mb-2 text-center">
|
||||||
Gift Registry 🎁
|
🎁 Gift Registry 🎁
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-muted-foreground text-center">
|
<p className="text-muted-foreground text-center">
|
||||||
Choose a gift from the wishlist to help celebrate Emma's 1st birthday
|
Choose a gift from the wishlist to help celebrate Emma's 1st birthday
|
||||||
@@ -394,7 +393,7 @@ export default function GiftRegistryPage() {
|
|||||||
<TableHead>Name</TableHead>
|
<TableHead>Name</TableHead>
|
||||||
<TableHead>Priority</TableHead>
|
<TableHead>Priority</TableHead>
|
||||||
<TableHead>Link</TableHead>
|
<TableHead>Link</TableHead>
|
||||||
<TableHead>Quantity</TableHead>
|
{/*<TableHead>Quantity</TableHead>*/}
|
||||||
<TableHead>Description</TableHead>
|
<TableHead>Description</TableHead>
|
||||||
<TableHead></TableHead>
|
<TableHead></TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@@ -430,7 +429,7 @@ export default function GiftRegistryPage() {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{quantity}</TableCell>
|
{/*<TableCell>{quantity}</TableCell>*/}
|
||||||
<TableCell>{gift.description || ""}</TableCell>
|
<TableCell>{gift.description || ""}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user