Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjcai committed Nov 8, 2023
2 parents 42c37e7 + 23cf026 commit d9d1a24
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 130 deletions.
Binary file added public/images/Arrow_Left_MD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions src/api/supabase/queries/order_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function fetchOrders(): Promise<
> {
try {
const { data: orders, error } = await supabase
.from('Order') // Update to the "Order" table
.from('order') // Update to the "Order" table
.select('*');

if (error) {
Expand All @@ -40,7 +40,7 @@ export async function fetchOrderByUUID(
): Promise<PostgrestSingleResponse<Order>> {
try {
const { data: order, error } = await supabase
.from('Order') // Update to the "Order" table
.from('order') // Update to the "Order" table
.select('*')
.eq('id', uuid)
.single();
Expand All @@ -63,7 +63,7 @@ export async function getOrdersByUserId(
> {
try {
const { data: orders, error } = await supabase
.from('Order')
.from('order')
.select('*')
.eq('user_id', userId)
.single();
Expand All @@ -86,7 +86,7 @@ export async function getOrderById(
): Promise<PostgrestSingleResponse<Order>> {
try {
const { data: order, error } = await supabase
.from('Order')
.from('order')
.select('*')
.eq('id', orderId)
.single();
Expand All @@ -108,7 +108,7 @@ export async function toggleOrderProgress(
try {
// Fetch the order by ID to get its current "approved" value
const { data: currentOrder, error: fetchError } = await supabase
.from('Order')
.from('order')
.select('approved')
.eq('id', orderId)
.single();
Expand All @@ -123,7 +123,7 @@ export async function toggleOrderProgress(

// Update the order with the new "approved" value
const { data: updatedOrder, error: updateError } = await supabase
.from('Order')
.from('order')
.update({ approved: updatedApprovedValue })
.eq('id', orderId)
.single();
Expand All @@ -146,7 +146,7 @@ export async function updateAllOrdersProgressToTrue(): Promise<
try {
// Update all orders to set "approved" to true
const { error: updateError } = await supabase
.from('Order')
.from('order')
.update({ approved: true });

if (updateError) {
Expand Down
8 changes: 3 additions & 5 deletions src/api/supabase/queries/product_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function fetchProducts(): Promise<
> {
try {
const { data: products, error } = await supabase
.from('Product')
.from('product')
.select('*');

if (error) {
Expand All @@ -35,12 +35,10 @@ export async function fetchProducts(): Promise<
}
}

export async function fetchProductByID(
productId: string,
): Promise<PostgrestSingleResponse<Product>> {
export async function fetchProductByID(productId: number) {
try {
const { data: product, error } = await supabase
.from('Product')
.from('product')
.select('*')
.eq('product_id', productId)
.single();
Expand Down
2 changes: 1 addition & 1 deletion src/api/supabase/queries/tests/product_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function testFetchProducts() {

// Test fetching a product by name
export async function testFetchProductByName() {
const productId = '1'; // Replace with a valid product name
const productId = 1; // Replace with a valid product name
try {
const result = await fetchProductByID(productId);
console.log('Fetch Product by Name Result:', result);
Expand Down
6 changes: 3 additions & 3 deletions src/api/supabase/queries/tests/user_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {



export async function testFetchUserByUUID() {
const uuid = '3b4a1317-b9ea-4cbd-95d7-e959aa80d1ea'; // Replace with a valid user ID
export async function runFetchUserByUUID() {
const testUUID = 'aeaf5f6c-a8bc-41b8-9850-5fb11e1b6dea';
try {
const result = await fetchUserByUUID();
console.log('Fetch User by UUID Result:', result);
} catch (error) {
console.error('Test Fetch User by UUID Error:', error);
console.error('Error in fetchUserByUUID:', error);
}
}

9 changes: 5 additions & 4 deletions src/api/supabase/queries/user_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function updateCart(

currentCart: Record<string, number>,
) {

const { error } = await supabase
.from('profiles')
.update({ cart: currentCart })
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function decrementCartItem(
n: number,
) {

const currentCart = await fetchUserCart(userId);
const currentCart = await fetchUserCart();

if (currentCart[itemId]) {
currentCart[itemId] -= n;
Expand All @@ -69,14 +70,14 @@ export async function decrementCartItem(
}
}

await updateCart(userId, currentCart);
await updateCart(currentCart);
}

export async function incrementCartItemByOne(userId: string, itemId: string) {
await incrementCartItem(userId, itemId, 1);
await incrementCartItem(itemId, 1);
}

export async function decrementCartItemByOne(userId: string, itemId: string) {
await decrementCartItem(userId, itemId, 1);
await decrementCartItem(itemId, 1);
}

37 changes: 37 additions & 0 deletions src/app/[productId]/Buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { useState } from 'react';
import {
ButtonsWrapper,
AddToCartButton,
QuantityButton,
PlusMinusButton,
} from './styles';

export default function Buttons() {
const [quantity, setQuantity] = useState<number>(1);

const increaseQuantity = () => {
setQuantity(quantity + 1);
};

const decreaseQuantity = () => {
if (quantity > 1) {
setQuantity(quantity - 1);
}
};

// used hyphen instead of dash for display
return (
<ButtonsWrapper>
<QuantityButton>
<PlusMinusButton type="button" onClick={decreaseQuantity}>
</PlusMinusButton>
<span>{quantity}</span>
<PlusMinusButton type="button" onClick={increaseQuantity}>
+
</PlusMinusButton>
</QuantityButton>
<AddToCartButton>Add to cart</AddToCartButton>
</ButtonsWrapper>
);
}
76 changes: 76 additions & 0 deletions src/app/[productId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use client';

import Link from 'next/link';
import Image from 'next/image';
import { useEffect, useState } from 'react';
import { fetchProductByID } from '../../api/supabase/queries/product_queries';
import {
BackButton,
ImageContainer,
TextContainer,
DescriptionContainer,
} from './styles';
import { GlobalStyle } from '../../styles/components';
import NavBar from '../../components/NavBar';
import { Product } from '../../schema/schema';
import Buttons from './Buttons';

export default function ItemDisplay({
params,
}: {
params: { productId: number };
}) {
const [Item, setItem] = useState<Product>();

useEffect(() => {
async function fetchProducts() {
try {
const response = await fetchProductByID(params.productId);
if (response) {
setItem(response);
}
} catch (error) {
// console.error(error);
}
}

fetchProducts();
}, [params.productId]);

return (
<main>
<GlobalStyle />
<NavBar />
<BackButton>
<Link href="/storefront">
<Image
src="/images/Arrow_Left_MD.png"
alt="Back Arrow"
width={20}
height={20}
/>
<span style={{ marginLeft: '8px' }}>Back</span>
</Link>
</BackButton>
<DescriptionContainer>
<ImageContainer>
<img
src={Item?.photo}
alt={Item?.name}
style={{ width: '600px', height: '600px' }}
/>
</ImageContainer>
<TextContainer>
<h1>{Item?.name}</h1>
<h4 style={{ fontWeight: 'normal', paddingTop: '5px' }}>
{Item?.category}
</h4>
<Buttons />
<p style={{ paddingTop: '50px' }}>Product ID: {Item?.product_id}</p>
<p style={{ paddingTop: '20px' }}>Product Details:</p>
<p>{Item?.description}</p>
</TextContainer>
</DescriptionContainer>
</main>
);
}
78 changes: 78 additions & 0 deletions src/app/[productId]/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import styled from 'styled-components';
import COLORS from '../../styles/colors';

export const BackButton = styled.button`
display: flex;
padding-top: 230px;
padding-left: 30px;
width: 100px;
height: 40px;
background-color: transparent;
border-color: transparent;
font-size: 15px;
`;

export const DescriptionContainer = styled.div`
display: flex;
margin: 50px;
width: 1440px;
height: 800px;
`;

export const ImageContainer = styled.div`
margin: 50px;
width: 666px;
height: 666px;
flex-shrink: 0;
`;

export const TextContainer = styled.div`
margin-left: 70px;
width: 440px;
height: 350px;
`;

export const ButtonsWrapper = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
width: 450px;
height: 50px;
margin-top: 20px;
`;

export const QuantityButton = styled.div`
display: flex;
justify-content: space-evenly;
align-items: center;
width: 165px;
height: 50px;
border-radius: 8px;
background-color: ${COLORS.white};
border: 2px solid ${COLORS.navy};
color: ${COLORS.navy};
`;

export const PlusMinusButton = styled.button`
width: 25px;
height: 25px;
align-items: center;
justify-content: center;
background-color: transparent;
border-color: transparent;
font-size: 20px;
color: ${COLORS.navy};
`;
export const AddToCartButton = styled.button`
width: 265px;
height: 50px;
border-radius: 8px;
background-color: ${COLORS.navy};
font-family: Public Sans;
font-size: 20px;
font-style: normal;
font-weight: 700;
line-height: normal;
color: ${COLORS.white};
border-color: transparent;
`;
20 changes: 19 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@
'use client';

import React, { useEffect } from 'react';

import Link from 'next/link';
import {
testFetchOrderByUUID,
testFetchOrders,
testGetOrderById,
testToggleOrderProgress,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
testUpdateAllOrdersProgressToTrue,
} from '../api/supabase/queries/tests/order_test';
import {
testFetchProducts,
testFetchProductByName,
} from '../api/supabase/queries/tests/product_test';
import {
testFetchPickupData,
testFetchPickupTimesByUUID,
} from '../api/supabase/queries/tests/pickup_test';


export default function Home() {
return (
<main>
<Link href="/login">Login</Link>
</main>
);
}
}
Loading

0 comments on commit d9d1a24

Please sign in to comment.