Skip to content

Commit

Permalink
Co-authored-by: surajr10 <[email protected]>
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjcai committed Nov 3, 2023
2 parents af3c971 + 3a66963 commit e1bcd8c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module.exports = {
extends: ["@calblueprint/eslint-config-react"],
extends: ["@calblueprint/eslint-config-react"],
rules: {
// Add any custom rules here
// Disable the rule that requires React to be in scope -- we don't need this with React 18
'react/react-in-jsx-scope': 'off',
'react/jsx-uses-react': 'off',
},
settings: {
'import/resolver': {
typescript: {}
}
}
};
1 change: 0 additions & 1 deletion src/api/supabase/auth/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const handleSignUp = async (email: string, password: string) => {
};

export const signInWithEmail = async (email: string, password: string) => {
console.log('hi');
const { data, error } = await supabase.auth.signInWithPassword({
email,
password,
Expand Down
15 changes: 8 additions & 7 deletions src/api/supabase/queries/user_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export async function fetchUserData(): Promise<
PostgrestSingleResponse<User[]> | { data: never[]; error: PostgrestError }
> {
try {
const { data: users, error } = await supabase.from('users').select('*');
const { data: users, error } = await supabase
.from('profiles')
.select('*')
.single();

if (error) {
console.error('Error fetching data:', error);
Expand All @@ -34,12 +37,10 @@ export async function fetchUserData(): Promise<
}
}

export async function fetchUserByUUID(
uuid: string,
): Promise<PostgrestSingleResponse<unknown>> {
export async function fetchUserByUUID(uuid: string) {
try {
const { data: user, error } = await supabase
.from('Users')
.from('profiles')
.select('*')
.eq('user_id', uuid)
.single();
Expand All @@ -63,7 +64,7 @@ export async function addUserAddress(
): Promise<PostgrestSingleResponse<unknown>> {
try {
const { data: existingUser, error: selectError } = await supabase
.from('Users')
.from('profiles')
.select('street, city, zipcode')
.eq('user_id', uuid)
.single();
Expand All @@ -79,7 +80,7 @@ export async function addUserAddress(
const updatedZipcode = [...(existingUser?.zipcode || []), newZipcode];

const { data, error } = await supabase
.from('Users')
.from('profiles')
.update({
street: updatedStreet,
city: updatedCity,
Expand Down
35 changes: 34 additions & 1 deletion src/app/checkout/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
'use client';

import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import supabase from '@/api/supabase/createClient';
import { fetchUserByUUID } from '@/api/supabase/queries/user_queries';
import { Button } from '../login/styles';

import NavBar from '../../components/NavBar';

export default function Checkout() {
const [deliveryEnabled, setDeliveryEnabled] = useState<boolean>(false);
useEffect(() => {
(async () => {
const { data: sessionData, error } = await supabase.auth.getSession();

if (error) throw error;
if (
!sessionData ||
!sessionData.session ||
!sessionData.session.user ||
!sessionData.session.user.id
)
return;

const data = await fetchUserByUUID(sessionData.session.user.id as string);
setDeliveryEnabled(data.delivery_allowed);
})();
}, []);

const router = useRouter();
const checkDelivery = () => {
if (deliveryEnabled) {
router.push('/delivery');
} else {
router.push('/pickup');
}
};
return (
<main>
<NavBar />
<div>Checkout</div>
<Button onClick={checkDelivery}>Checkout</Button>
</main>
);
}
20 changes: 9 additions & 11 deletions src/schema/schema.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
export type User = {
user_id: string; // UUID
email: string;
password: string;
first_name: string;
last_name: string;
pet_information: string;
user_id: string; // UUID
order_option: boolean;
address: number; // index of the address the street, city, and zipcode to build the address
street: string[];
city: string[];
zipcode: string[];
delivery_allowed: boolean;
created_at: Date; // timestamp of when record was created
cart_id: string; // UUID
address_id: string; // UUID
};

export type Order = {
id: number; // bigint generated by default as identity
user_id: string; // UUID not null
order_cart: number; // bigint[] null
status: string; // bigint null
pickup_time: number; // bigint null
created_at: string; // timestamp with time zone not null default now();
};

export type Schedule = {
id: number; // bigint generated by default as identity
date: string; // text not null
start_time: string; // text null
end_time: string; // text null
date: Date; // text not null
start_time: Date; // text null
end_time: Date; // text null
};

export type Product = {
Expand All @@ -35,7 +33,7 @@ export type Product = {
category: string; // numeric not null;
quantity: number; // numeric not null;
photo: string; // text null;
updated_at: string; // timestamp with time zone not null default now();
updated_at: Date; // timestamp with time zone not null default now();
};

export type Cart = {
Expand Down

0 comments on commit e1bcd8c

Please sign in to comment.