in progress: db support for tandem add to user table on supabase registration

This commit is contained in:
2022-10-10 18:28:49 -05:00
parent f29ee33ca1
commit 4965480aaf
9 changed files with 96 additions and 4 deletions

View File

@@ -0,0 +1,34 @@
import { useState } from "react";
import Button from "../../_ui/Button/Button";
import Card from "../../_ui/Card/Card"
const UpdateUserInfo = () => {
const [input, setInput] = useState({first: "", last: ""});
const handleUpdate = () => {
if (!input.first || !input.last) return;
}
return (
<Card>
<h1>Update User Information</h1>
<form>
<div>
<label htmlFor="first-name">First Name: </label>
<input onChange={(e) => setInput({...input, first: e.target.value})} type="text" autoComplete="First Name"></input>
</div>
<div>
<label htmlFor="last-name">Last Name: </label>
<input onChange={(e) => setInput({...input, last: e.target.value})} type="text" autoComplete="Last Name"></input>
</div>
</form>
<Button onClick={handleUpdate}>Update</Button>
</Card>
)
}
export default UpdateUserInfo;

View File

@@ -16,7 +16,7 @@ export default function UserProfile() {
<div className="user-profile-options">
<Button onClick={() => navigate('/cart')}>View my Cart</Button>
<Button onClick={() => navigate('/orders')}>View my Order History</Button>
<Button onClick={() => {}}>Manage Account Settings</Button>
<Button onClick={() => navigate('/user-settings')}>Manage Account Settings</Button>
</div>
</Page>
)

View File

@@ -1,3 +1,18 @@
import { useEffect, useState } from "react";
import { useSupabase } from "../../supabase/SupabaseContext"
import Page from "../_ui/Page/Page";
import UpdateUserInfo from "./SettingsWidgets/UpdateUserInfo";
export default function UserSettings() {
return <h1>User Settings!</h1>
const supabase = useSupabase();
const [activeSections, setActiveSections] = useState({
userInfo: false
});
return (
<Page>
<h1>User Settings!</h1>
{ activeSections.userInfo && <UpdateUserInfo /> }
</Page>
)
}

View File

@@ -9,6 +9,17 @@ export const getByProductId = async (id: string) => {
return response;
}
export const updateUser = async (id: string, body: object) => {
const response = await fetch(`https://mikayla-spice-market-api.herokuapp.com/users/${id}`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
return response;
}
// order functions
export const getOrder = async () => {
return;

View File

@@ -1,4 +1,5 @@
import { SupabaseClient } from "@supabase/supabase-js";
import { updateUser } from "./apiUtils";
export interface FormInput {
email: string
@@ -22,7 +23,6 @@ export const handleRegister = async (supabase: SupabaseClient | undefined, input
if (email && password) {
const { user, session, error} = await supabase.auth.signUp({ email, password });
if (error) throw error;
console.log(user, session);
}
}

View File

@@ -14,7 +14,7 @@ async function main() {
CREATE TABLE IF NOT EXISTS users (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL,
email VARCHAR NOT NULL,
password VARCHAR NOT NULL,
supabaseUser JSON NOT NULL,
firstname VARCHAR,
lastname VARCHAR,
isadmin BOOLEAN DEFAULT FALSE

View File

@@ -62,4 +62,19 @@ module.exports = class UserModel {
throw new Error(e);
}
}
async createFromSupabase(data) {
try {
const statement = '';
const result = await db.query(statement);
if (result.rows.length) {
return result.rows[0];
}
return null;
} catch(e) {
throw new Error(e);
}
}
}

View File

@@ -26,4 +26,13 @@ module.exports = (app) => {
next(e);
}
})
router.post('/', async (req, res, next) => {
try {
const data = req.body;
} catch(e) {
next(e);
}
})
}

View File

@@ -23,4 +23,12 @@ module.exports = class UserService {
throw new Error(e);
}
}
async insert(data) {
try {
const user = await UserInstance.create(data);
} catch(e) {
next(e);
}
}
}