-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
64 lines (51 loc) · 1.71 KB
/
page.tsx
File metadata and controls
64 lines (51 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use client'
import { useState, useEffect } from "react"
import SignUpForm from "./sign-up-form"
import ConfirmAccountForm from "./confirm-account-form"
import SignInForm from "./sign-in-form"
import Dashboard from "./dashboard"
import Layout from "./layout"
import { subscribe, publish, unsubscribe } from "./events"
export default function Page() {
const [page, setPage] = useState("")
const logInClickHandler = (event: { preventDefault: () => void }) => {
event.preventDefault()
publish("page-change", "sign-in")
}
const signUpClickHandler = (event: { preventDefault: () => void }) => {
event.preventDefault()
publish("page-change", "sign-up")
}
useEffect(() => {
subscribe("page-change", (event: CustomEventInit) => {
const view = event.detail
console.log(view)
setPage(view)
});
return () => {
unsubscribe("page-change", () => { })
}
}, [])
if (page === "dashboard") {
return <Dashboard />
}
if (page === "sign-up") {
return <SignUpForm />
}
if (page === "confirm-account") {
return <ConfirmAccountForm />
}
if (page === "sign-in") {
return <SignInForm />
}
return (
<Layout>
Welcome, please
< a href="" onClick={logInClickHandler} style={{ border: "1px solid black", padding: 20, display: "block", marginTop: 20 }
}> Log In</a >
<div style={{ marginTop: 20 }}>
or
</div>
<a href="" onClick={signUpClickHandler} style={{ border: "1px solid black", padding: 20, display: "block", marginTop: 20 }}>Sign Up</a>
</Layout>)
}