-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
137 additions
and
168 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
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<string>(''); | ||
|
||
const handleInsert = async () => { | ||
if (reason !== '') { | ||
const newInterest: Interest = { | ||
// hardcoded values for now | ||
id: crypto.randomUUID(), | ||
listing_id: '36b8f84d-df4e-4d49-b662-bcde71a8764f', | ||
listing_type: 'IJP6 Test', | ||
user_id: '36b8f84d-df4e-4d49-b662-bcde71a8764f', | ||
form_response: { | ||
interestType: ['IJP-6-test'], | ||
whyInterested: reason, | ||
}, | ||
}; | ||
await insertInterest(newInterest); | ||
setReason(''); | ||
} else { | ||
// console.log('cannot create an empty interest'); | ||
} | ||
}; | ||
|
||
return ( | ||
<main className={styles.main}> | ||
<div className={styles.description}>Interest Form</div> | ||
<form> | ||
<textarea | ||
required | ||
value={reason} | ||
onChange={event => setReason(event.target.value)} | ||
/> | ||
<button type="button" onClick={handleInsert}> | ||
Submit | ||
</button> | ||
</form> | ||
</main> | ||
); | ||
} |
Oops, something went wrong.