-
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.
Merge pull request #13 from calblueprint/buyankhuu/logOutButton
Buyankhuu/log out button
- Loading branch information
Showing
11 changed files
with
292 additions
and
57 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,39 +1,41 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import LoginForm from '../../components/LoginForm'; | ||
|
||
import { | ||
handleSignUp, | ||
signInWithEmail, | ||
signOut, | ||
} from '../../api/supabase/auth/auth'; | ||
GlobalStyle, | ||
Fullscreen, | ||
Img, | ||
LoginBox, | ||
LoginContent, | ||
WelcomeSign, | ||
Button, | ||
} from './styles'; | ||
|
||
export default function Login() { | ||
import { handleSignUp, signInWithEmail } from '../../api/supabase/auth/auth'; | ||
|
||
export default function App() { | ||
const [email, setEmail] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
|
||
return ( | ||
<> | ||
<input | ||
name="email" | ||
onChange={e => setEmail(e.target.value)} | ||
value={email} | ||
/> | ||
<input | ||
type="password" | ||
name="password" | ||
onChange={e => setPassword(e.target.value)} | ||
value={password} | ||
/> | ||
<button type="button" onClick={() => handleSignUp(email, password)}> | ||
Sign up | ||
</button> | ||
<button type="button" onClick={() => signInWithEmail(email, password)}> | ||
Sign in | ||
</button> | ||
<button type="button" onClick={signOut}> | ||
Sign out | ||
</button> | ||
</> | ||
<main> | ||
<GlobalStyle /> | ||
<Fullscreen> | ||
<Img /> | ||
<LoginBox> | ||
<LoginContent> | ||
<WelcomeSign>Welcome</WelcomeSign> | ||
<LoginForm changeUserName={setEmail} changePassword={setPassword} /> | ||
<Button onClick={() => signInWithEmail(email, password)}> | ||
Log In | ||
</Button> | ||
<button type="button" onClick={() => handleSignUp(email, password)}> | ||
Sign up | ||
</button> | ||
</LoginContent> | ||
</LoginBox> | ||
</Fullscreen> | ||
</main> | ||
); | ||
} |
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,2 @@ | ||
SUPABASE_URL = https://raqpvvgsmwarxhaialcz.supabase.co | ||
REACT_APP_ANON_KEY = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InJhcXB2dmdzbXdhcnhoYWlhbGN6Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTYxODg2MTgsImV4cCI6MjAxMTc2NDYxOH0.triHI7DNSzNeAibtktBZ1b2wQuwnd0WL7R_yZYOJbPc |
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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
'use client'; | ||
|
||
import { LogOutButton, GlobalStyle } from './style'; | ||
|
||
import { signOut } from '../../api/supabase/auth/auth'; | ||
|
||
export default function Profile() { | ||
return ( | ||
<main> | ||
<div>Profile</div> | ||
<GlobalStyle /> | ||
<LogOutButton onClick={() => signOut()}>Sign Out</LogOutButton> | ||
</main> | ||
); | ||
} |
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,22 @@ | ||
import styled, { createGlobalStyle } from 'styled-components'; | ||
|
||
export const GlobalStyle = createGlobalStyle` | ||
body { | ||
background:white; | ||
} | ||
`; | ||
|
||
export const LogOutButton = styled.button` | ||
background: #00507f; | ||
color: #fff; | ||
text-align: center; | ||
font-family: Inter; | ||
font-size: 20px; | ||
font-style: normal; | ||
font-weight: 500; | ||
line-height: normal; | ||
border: transparent; | ||
border-radius: 5px; | ||
width: 300px; | ||
height: 50px; | ||
`; |
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,32 @@ | ||
import dotenv from 'dotenv'; | ||
import { createClient } from '@supabase/supabase-js'; | ||
dotenv.config(); | ||
if ( | ||
!process.env.NEXT_PUBLIC_SUPABASE_URL || | ||
!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY | ||
) { | ||
throw new Error( | ||
'No Supabase environment variables detected, please make sure they are in place!', | ||
); | ||
} | ||
const supabase = createClient( | ||
process.env.NEXT_PUBLIC_SUPABASE_URL, | ||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY, | ||
); | ||
|
||
export async function getProduct() { | ||
let { data, error } = await supabase.from('product').select('*'); | ||
console.log(data); | ||
return data; | ||
} | ||
|
||
export async function filterProduct(productType) { | ||
const { data, error } = await supabase | ||
.from('product') | ||
.select('*') | ||
.eq('category', productType); | ||
|
||
console.log(data); | ||
|
||
return data; | ||
} |
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 |
---|---|---|
@@ -1,19 +1,58 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import Link from 'next/link'; | ||
import { GlobalStyle, Button } from './styles'; | ||
import React, { useState } from 'react'; | ||
|
||
import { GlobalStyle, ButtonsContainer } from './styles'; | ||
import ProductButtons from './productButtons'; | ||
|
||
interface Product { | ||
description: string; | ||
category: string; | ||
quantity: number; | ||
photo: string; | ||
product_id: number; | ||
name: string; | ||
updated_at: Date; | ||
} | ||
// https://codesandbox.io/s/filter-with-react-button-r5x4i?file=/src/App.js | ||
export default function App() { | ||
const buttons = [ | ||
{ | ||
name: 'All', | ||
value: 'All', | ||
count: 0, | ||
}, | ||
{ | ||
name: 'Dog', | ||
value: 'Dog', | ||
count: 1, | ||
}, | ||
{ | ||
name: 'Cat', | ||
value: 'Cat', | ||
count: 2, | ||
}, | ||
{ | ||
name: 'Misc.', | ||
value: 'Misc.', | ||
count: 3, | ||
}, | ||
]; | ||
const [, setFilteredProducts] = useState<null | Product[]>(null); | ||
|
||
return ( | ||
<main> | ||
<GlobalStyle /> | ||
<Button> | ||
<Link href="/checkout">Cart</Link> | ||
</Button> | ||
<Button> | ||
<Link href="/profileScreen">Profile</Link> | ||
</Button> | ||
<ButtonsContainer> | ||
{buttons.map(type => ( | ||
<ProductButtons | ||
key={type.count} | ||
value={type.value} | ||
setFiltredProducts={setFilteredProducts} | ||
content={type.name} | ||
/> | ||
))} | ||
</ButtonsContainer> | ||
</main> | ||
); | ||
} |
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,58 @@ | ||
// 'use client'; | ||
|
||
import React, { useState } from 'react'; | ||
|
||
import { Button, Label, IndividualContainer } from './styles'; | ||
|
||
import { getProduct, filterProduct } from './helperFunction'; | ||
|
||
interface Product { | ||
description: string; | ||
category: string; | ||
quantity: number; | ||
photo: string; | ||
product_id: number; | ||
name: string; | ||
updated_at: Date; | ||
} | ||
export default function ProductButtons(props: { | ||
key: number; | ||
value: string; | ||
setFiltredProducts: (category: Product[]) => void; | ||
content: string; | ||
}) { | ||
const { key, value, content, setFiltredProducts } = props; | ||
const [IsClicked, setIsClicked] = useState(false); | ||
|
||
async function applyFilter( | ||
e: React.MouseEvent<HTMLButtonElement, MouseEvent>, | ||
) { | ||
setIsClicked(!IsClicked); | ||
const category = e.currentTarget.value; | ||
console.log(category); | ||
|
||
if (category !== 'All') { | ||
const products = await filterProduct(category); | ||
if (products !== null) { | ||
setFiltredProducts(products); | ||
} | ||
} else { | ||
const products = await getProduct(); | ||
if (products !== null) { | ||
setFiltredProducts(products); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<IndividualContainer> | ||
<Button | ||
isClicked={IsClicked} | ||
key={key} | ||
value={value} | ||
onClick={e => applyFilter(e)} | ||
/> | ||
<Label isClicked={IsClicked}>{content}</Label> | ||
</IndividualContainer> | ||
); | ||
} |
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
Oops, something went wrong.