Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlotteLaw committed Apr 7, 2024
2 parents 922accf + de20104 commit 8c30afc
Show file tree
Hide file tree
Showing 50 changed files with 5,729 additions and 6,514 deletions.
Binary file added holder.zip
Binary file not shown.
10,642 changes: 4,512 additions & 6,130 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions public/ready.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/right_arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/api/supabase/queries/button_queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { StorefrontButtons } from '../../../schema/schema';
import supabase from '../createClient';

export async function fetchButtonCategories(): Promise<StorefrontButtons[]> {
const { data: buttons, error } = await supabase
.from('storefront_buttons')
.select('*');
if (error) {
throw new Error(`Error fetching buttons: ${error.message}`);
}

return buttons;
}

export async function fetchButton() {
return 0;
}
98 changes: 68 additions & 30 deletions src/api/supabase/queries/order_queries.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* eslint-disable no-console */
//

import {
Order,
OrderProduct,
ProductWithQuantity,
} from '../../../schema/schema';
import { Order, OrderProduct, Product } from '../../../schema/schema';
import { fetchUser } from './user_queries';
import { fetchProductByID } from './product_queries';
import supabase from '../createClient';

/**
Expand Down Expand Up @@ -36,6 +33,7 @@ export async function createOrder() {
.insert({ user_id: user.id })
.select('*')
.single();

if (error) {
throw new Error(`Error creating order: ${error.message}`);
}
Expand All @@ -58,11 +56,6 @@ function sortOrdersByCreated(orders: Order[]): Order[] {
);
}

/**
* user = fetch_use()
* cart_id = user.cart_id
*
*/
/**
* gets all orders by user id and sorted it by creation data
* @param Order[] - An array of Order objects.
Expand Down Expand Up @@ -103,6 +96,12 @@ export async function fetchNOrdersByUserIdSorted(n: number): Promise<Order[]> {
return sortOrdersByCreated(orders).slice(0, n);
}

export async function fetchOrderIdsByUserIdSorted(): Promise<number[]> {
const ordersProm = await fetchOrdersByUser();
const orders = sortOrdersByCreated(ordersProm);
return orders.map(order => order.id);
}

export async function fetchOrderProductById(
productId: number,
): Promise<OrderProduct> {
Expand All @@ -117,9 +116,32 @@ export async function fetchOrderProductById(
return orderProduct;
}

export async function fetchProductFromOrderProduct(
orderProductId: number,
): Promise<Product> {
const orderProduct = await fetchOrderProductById(orderProductId);
const product = await fetchProductByID(orderProduct.product_id);
return product;
}

export async function fetchProductsFromOrder(
orderId: number,
): Promise<Product[]> {
const order = await getOrderById(orderId);
const products = order.order_product_id_array;

const productPromises = products.map(async (productID: number) => {
const product = await fetchProductFromOrderProduct(productID);
return product;
});
const fetchedProducts = await Promise.all(productPromises);

return fetchedProducts;
}

export async function fetchProductWithQuantityById(
productId: number,
): Promise<ProductWithQuantity> {
): Promise<Product> {
const { data: orderProduct, error } = await supabase
.from('product')
.select('*')
Expand All @@ -131,27 +153,9 @@ export async function fetchProductWithQuantityById(
return orderProduct;
}

export async function fetchRecentOrderProducts(): Promise<OrderProduct[]> {
const order = await fetchNOrdersByUserIdSorted(1);
const orderProductIds = order[0].order_product_id_array;

const orderProducts = await Promise.all(
orderProductIds.map(async orderProductId => {
try {
const orderProduct = await fetchOrderProductById(orderProductId);
return orderProduct;
} catch (error) {
throw new Error(`Error fetching order product array.`);
}
}),
);

return orderProducts;
}

export async function fetchOrderProductsbyOrderId(
orderId: number,
): Promise<ProductWithQuantity[]> {
): Promise<Product[]> {
const order = await getOrderById(orderId);
const orderProductIds = order.order_product_id_array;

Expand Down Expand Up @@ -189,3 +193,37 @@ export async function fetchCurrentOrdersByUser(): Promise<Order[]> {

return data;
}

export async function fetchRecentOrderProducts(): Promise<OrderProduct[]> {
const order = await fetchNOrdersByUserIdSorted(1);
const orderProductIds = order[0].order_product_id_array;

const orderProducts = await Promise.all(
orderProductIds.map(async orderProductId => {
try {
const orderProduct = await fetchOrderProductById(orderProductId);
return orderProduct;
} catch (error) {
throw new Error(`Error fetching order product array.`);
}
}),
);

return orderProducts;
}

export async function updateOrderPickupId(orderId: number, pickupId: number) {
await supabase
.from('order')
.update({ pickup_time_id: pickupId })
.eq('id', orderId);
}

export async function updateCartPickupId(pickupId: number) {
const user = await fetchUser();
const cartId = user.cart_id;
await supabase
.from('order')
.update({ pickup_time_id: pickupId })
.eq('id', cartId);
}
17 changes: 17 additions & 0 deletions src/api/supabase/queries/pickup_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,20 @@ export async function fetchRecentPickupTimes(): Promise<Pickup[]> {
}
return getTimes;
}

/**
*
* @returns 2 most recent pickup times
*/
export async function fetchNRecentPickupTimes(n: number): Promise<Pickup[]> {
const { data: getTimes, error } = await supabase
.from('pickup_times')
.select('*')
.order('start_time', { ascending: false })
.limit(n);

if (error) {
throw new Error(`Error fetching pickup times: ${error.message}`);
}
return getTimes;
}
1 change: 1 addition & 0 deletions src/api/supabase/queries/product_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export async function filterUserProducts(
.select('*')
.eq('prescribed', true)
.eq('category', productType);

if (error) {
throw new Error(`Error fetching products: ${error.message}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/supabase/queries/user_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function fetchUserAddress(uuid: string) {
.eq('user_id', uuid)
.single();

console.log('test', error);
console.log('test', user);

if (error) {
console.error('Error fetching user data:', error);
Expand Down
8 changes: 4 additions & 4 deletions src/app/[productId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
TextContainer,
DescriptionContainer,
ToastPopUP,
Fullscreen,
} from './styles';
import { GlobalStyle } from '../../styles/components';

import NavBar from '../../components/NavBarFolder/NavBar';
import { Product } from '../../schema/schema';
import Buttons from './Buttons';
Expand Down Expand Up @@ -39,8 +40,7 @@ export default function ItemDisplay({
}, [params.productId]);

return (
<main>
<GlobalStyle />
<Fullscreen>
<NavBar />
<ToastPopUP
position="top-right"
Expand Down Expand Up @@ -68,6 +68,6 @@ export default function ItemDisplay({
<p>{Item?.description}</p>
</TextContainer>
</DescriptionContainer>
</main>
</Fullscreen>
);
}
5 changes: 5 additions & 0 deletions src/app/[productId]/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ export const ToastPopUP = styled(ToastContainer)`
z-index: 100;
transform: translatey(130px);
`;

export const Fullscreen = styled.div`
width: 100%;
height: 100%;
`;
29 changes: 12 additions & 17 deletions src/app/cart/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import CartItem from './cartItem';
import NavBar from '../../components/NavBarFolder/NavBar';
import {
OutterFavoriteDiv,
PageDiv,
CheckoutButton,
LeftColumnDiv,
Expand Down Expand Up @@ -54,22 +53,18 @@ export default function OrderPage() {
<NavBar />
<PageDiv>
<LeftColumnDiv>
<BackButtonDiv>
<BackButton destination="./profileScreen" />
</BackButtonDiv>
<Heading>Cart</Heading>
<OutterFavoriteDiv>
{cart.map(cartItem => (
<CartItem
key={cartItem.id}
cartItemProduct={cartItem}
setCart={setCart}
cart={cart}
setNumberOfItems={setNumberOfItems}
numberOfItems={numberOfItems}
/>
))}
</OutterFavoriteDiv>
<BackButton destination="./storefront" />
<h1>Cart</h1>
{cart.map(cartItem => (
<CartItem
key={cartItem.id}
cartItemProduct={cartItem}
setCart={setCart}
cart={cart}
setNumberOfItems={setNumberOfItems}
numberOfItems={numberOfItems}
/>
))}
</LeftColumnDiv>
<RightColumnDiv>
<OrderSummary cart={cart} numberOfItems={numberOfItems} />
Expand Down
11 changes: 0 additions & 11 deletions src/app/cart/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ export const FavoriteDiv = styled.div`
margin-top: 30px;
`;

export const OutterFavoriteDiv = styled.div`
display: flex;
flex-direction: column;
align-items: center;
border-radius: 10px;
width: 1000px;
height: 700px;
overflow: scroll;
margin-top: 10px;
`;

export const BackDiv = styled.button`
display: flex;
flex-direction: row;
Expand Down
Loading

0 comments on commit 8c30afc

Please sign in to comment.