-
Notifications
You must be signed in to change notification settings - Fork 77
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
장원정
committed
Dec 17, 2024
1 parent
d49115f
commit 2a6505b
Showing
4 changed files
with
58 additions
and
48 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createRouter } from "@/router/createRouter"; | ||
import UserStore from "@/store/userStore"; | ||
|
||
const { navigator } = createRouter(); | ||
|
||
export function clickEventHandler(e) { | ||
const { id, tagName } = e.target; | ||
|
||
if (tagName === "A") { | ||
e.preventDefault(); | ||
const { href } = e.target; | ||
let path = new URL(href).pathname; | ||
if (id === "logout") { | ||
new UserStore().deleteUser(); | ||
path = "/login"; | ||
} | ||
navigator(path); | ||
} | ||
} |
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 @@ | ||
export * from "./clickEventHandler"; | ||
export * from "./submitEventHandler"; |
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,35 @@ | ||
import { createRouter } from "@/router/createRouter"; | ||
import UserStore from "@/store/userStore"; | ||
|
||
const { navigator } = createRouter(); | ||
|
||
export function submitEventHandler(e) { | ||
e.preventDefault(); | ||
const form = e.target; | ||
const formData = new FormData(form); | ||
const { id } = form; | ||
|
||
if (id === "login-form") { | ||
login(formData); | ||
} | ||
|
||
if (id === "profile-form") { | ||
updateProfile(formData); | ||
} | ||
} | ||
|
||
function login(formData) { | ||
const username = formData.get("username"); | ||
if (username) { | ||
new UserStore().setUser({ username, email: "", bio: "" }); | ||
navigator("/profile"); | ||
} | ||
} | ||
|
||
function updateProfile(formData) { | ||
const username = formData.get("username"); | ||
const email = formData.get("email"); | ||
const bio = formData.get("bio"); | ||
new UserStore().setUser({ username, email, bio }); | ||
navigator("/profile"); | ||
} |