diff --git a/app/(main)/request/[storeId]/[storeItemId]/page.tsx b/app/(main)/request/[storeId]/[storeItemId]/page.tsx new file mode 100644 index 0000000..1185112 --- /dev/null +++ b/app/(main)/request/[storeId]/[storeItemId]/page.tsx @@ -0,0 +1,96 @@ +import { createClient } from '@/app/lib/supabase/server-client'; +// exports server component RequestStoreItemPage +export default async function RequestStoreItemPage({ + params, +}: { + params: Promise<{ storeId: string; storeItemId: string }>; +}) { + const { storeId, storeItemId } = await params; // page takes storeId and storeItemId as props + + const supabase = await createClient(); + + // select store_item_id and quantity_available from store_items + // select name, description, and photo_url from inventory_items + // select subcategories.name and categories.name + const { data: storeItem, error: itemError } = await supabase + .from('store_items') + .select( + ` + store_item_id, + quantity_available, + inventory_items ( + name, + description, + photo_url, + subcategories ( + name, + categories ( + name + ) + ) + ) + ` + ) + // match storeItemId + .eq('store_item_id', storeItemId) + .single(); + + if (itemError) { + console.error('Error fetching store item:', itemError); + return
Failed to load data.
; + } +// extract nested values: name description, category, subcategory + const inv = storeItem.inventory_items?.[0]; + const subcat = inv?.subcategories?.[0]; + const category = subcat?.categories?.[0]; + + return ( +
+

Request Item Details

+ {/* display inventory item name */} +

{inv?.name}

+ + {inv?.photo_url && ( + {inv?.name} + )} + +{/* Display inventory item description */} +

+ Description:{' '} + {inv?.description ?? 'No description available'} +

+ +{/* display category name */} +

+ Category: {category?.name ?? 'None'} +

+ +{/* display subcategory name */} +

+ Subcategory: {subcat?.name ?? 'None'} +

+ +{/* display quantity available */} +

+ Quantity Available:{' '} + {storeItem.quantity_available ?? 'Unknown'} +

+ + + + +
+ ); +} diff --git a/app/(main)/request/[storeId]/page.tsx b/app/(main)/request/[storeId]/page.tsx new file mode 100644 index 0000000..068bcb6 --- /dev/null +++ b/app/(main)/request/[storeId]/page.tsx @@ -0,0 +1,88 @@ +import { createClient } from '@/app/lib/supabase/server-client'; +import RequestStoreItemCard from '@/app/(main)/request/components/RequestStoreItemCard'; + +// server component exported +export default async function RequestStorePage({ + params, +}: { + // takes in storeId as prop + params: Promise<{ storeId: string }>; +}) { + const { storeId } = await params; + + const supabase = await createClient(); + const { + data: { user }, + } = await supabase.auth.getUser(); + + //fetch store's entry in stores table (filters on store_id) + const { data: store } = await supabase + .from('stores') + .select('*') + .eq('store_id', storeId) + .single(); + +// get all non-hidden store items for store +// fetch nested inventory + category data + const { data: storeItems } = await supabase + .from('store_items') + .select( + ` + store_item_id, + inventory_items ( + name, + photo_url, + subcategories ( + name, + categories ( + name + ) + ) + ) + ` + ) + .eq('store_id', storeId) + .eq('hidden', false); + + return ( + // display store's name and street address +
+

Store – {store.name}

+

Street Address: {store.street_address}

+ +

Available Items

+ {/* iterates through store items */} + {storeItems && storeItems.length > 0 ? ( +
+ {storeItems.map((item) => { + const inv = item.inventory_items?.[0]; + const subcat = inv?.subcategories?.[0]; + const category = subcat?.categories?.[0]; + + return ( + + {/* pass each store item to a RequestItemCard component */} + + + ); + })} +
+ ) : ( +

N/A. No items to display.

+ )} + + + + +
+ ); +} diff --git a/app/(main)/request/components/RequestStoreItemCard.tsx b/app/(main)/request/components/RequestStoreItemCard.tsx new file mode 100644 index 0000000..bc29dcc --- /dev/null +++ b/app/(main)/request/components/RequestStoreItemCard.tsx @@ -0,0 +1,25 @@ +export default function RequestStoreItemCard({ + name, + subcategoryName, + categoryName, +}: { + name: string | undefined; + subcategoryName: string | undefined; + categoryName: string | undefined; +}) { + return ( +
+

{name}

+

Category: {categoryName}

+

Subcategory: {subcategoryName}

+
+ ); +} \ No newline at end of file