Skip to content

Commit

Permalink
basic interest form complete
Browse files Browse the repository at this point in the history
  • Loading branch information
varortz committed Oct 3, 2023
1 parent d2b4b4b commit cd10023
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 168 deletions.
179 changes: 12 additions & 167 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@calblueprint/prettier-config": "^0.0.1",
"@supabase/supabase-js": "^2.36.0",
"@supabase/supabase-js": "^2.37.0",
"@types/node": "20.6.3",
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
Expand Down
21 changes: 21 additions & 0 deletions src/api/supabase/queries/interest.ts
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}`);
}
}
46 changes: 46 additions & 0 deletions src/app/interest/page.tsx
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>
);
}
Loading

0 comments on commit cd10023

Please sign in to comment.