diff --git a/src/api/supabase/queries/interest.ts b/src/api/supabase/queries/interest.ts new file mode 100644 index 00000000..ea2f1d9d --- /dev/null +++ b/src/api/supabase/queries/interest.ts @@ -0,0 +1,21 @@ +import supabase from '../createClient'; +import { Interest } from '../../../types/schemaTypes'; + +/** Get all interest from supabase interest table. */ +export async function getAllInterests() { + const { data, error } = await supabase.from('interests').select(); + + if (error) { + throw new Error(`An error occurred trying to read interests: ${error}`); + } + return data; +} + +/** Insert a new interest object into supabase interest table. */ +export async function insertInterest(interest: Interest) { + const { error } = await supabase.from('interests').insert(interest).select(); + + if (error) { + throw new Error(`An error occurred trying to insert an interest: ${error}`); + } +} diff --git a/src/api/supabase/queries/profiles.ts b/src/api/supabase/queries/profiles.ts new file mode 100644 index 00000000..0653769e --- /dev/null +++ b/src/api/supabase/queries/profiles.ts @@ -0,0 +1,32 @@ +import { UUID } from 'crypto'; +import supabase from '../createClient'; +import { Profile } from '../../../types/schemaTypes'; + +export async function fetchProfiles() { + const { data, error } = await supabase.from('profiles').select('*'); + + if (error) { + throw new Error(`An error occured when trying to read profiles: ${error}`); + } else { + // console.log('Profiles Data:', data); + return data; + } +} + +export async function insertProfile(profileData: Profile) { + const { error } = await supabase.from('profiles').insert(profileData); + if (error) { + throw new Error(`Error inserting profile data: ${error.message}`); + } +} + +export async function updateProfile(id: UUID, updatedInfo: Partial) { + const { error } = await supabase + .from('profiles') + .update(updatedInfo) + .eq('user_id', id); + + if (error) { + throw new Error(`Error updating profile data: ${error.message}`); + } +} diff --git a/src/app/interest/page.tsx b/src/app/interest/page.tsx new file mode 100644 index 00000000..49e4b693 --- /dev/null +++ b/src/app/interest/page.tsx @@ -0,0 +1,47 @@ +'use client'; + +import { useState } from 'react'; +import { UUID } from 'crypto'; +import { insertInterest } from '../../api/supabase/queries/interest'; +import { Interest } from '../../types/schemaTypes'; +import styles from '../page.module.css'; + +export default function Interest() { + const [reason, setReason] = useState(''); + + const handleInsert = async () => { + if (reason !== '') { + const newInterest: Interest = { + // hardcoded values for now + id: crypto.randomUUID() as UUID, + listing_id: '36b8f84d-df4e-4d49-b662-bcde71a8764f', + listing_type: 'IJP6 Test', + user_id: '36b8f84d-df4e-4d49-b662-bcde71a8764f', + form_response: { + interestType: ['IJP-6-test'], + interestReason: reason, + }, + }; + await insertInterest(newInterest); + setReason(''); + } else { + // console.log('cannot create an empty interest'); + } + }; + + return ( +
+
Interest Form
+
+