-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] integrate user api for mypage #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bf1424e
84291cf
8a1331e
82b0048
4b69065
46be792
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,35 @@ | ||
| import { useEffect } from 'react'; | ||
| import { ChangeEvent, useState } from 'react'; | ||
| import Image from 'next/image'; | ||
| import { UseFormSetValue } from 'react-hook-form'; | ||
| import { FormValues } from './ProfileForm'; | ||
| import styles from './FileInput.module.css'; | ||
|
|
||
| interface FileInputProps { | ||
| name: 'imgFile'; | ||
| setValue: UseFormSetValue<FormValues>; | ||
| id: string; | ||
| name: 'image'; | ||
| setValue: (name: 'image', value: File | null) => void; | ||
| url?: string | null; | ||
| } | ||
|
|
||
| export default function FileInput({ name, setValue }: FileInputProps) { | ||
| const [preview, setPreview] = useState(''); | ||
| export default function FileInput({ name, setValue, url, id }: FileInputProps) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μκΈ°μ nameμ νμ 'image' λ¬Έμμ΄ κ³ μ κ° λ§μκΉμ?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ€ image file input μ©λλ‘λ§ μ¬μ©ν κ±° κ°μμ 'image' κ³ μ μ
λλ€. |
||
| const [preview, setPreview] = useState<string | null>(null); | ||
|
|
||
| const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
| const file = event.target.files?.[0]; | ||
| if (file) { | ||
| setPreview(URL.createObjectURL(file)); | ||
| setValue('image', file); | ||
| setValue(name, file); | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use client μ΅μμμ μ μΈ μν΄μ€λ λμνλ보ꡰμ?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λΆλͺ¨μ»΄ν¬λνΈκ° 'use client' λ‘ λμ΄μμΌλ©΄ νμ μκΈ΄ νλ°... |
||
| if (url) { | ||
| setPreview(url); | ||
| } | ||
| }, [url]); | ||
|
|
||
| return ( | ||
| <> | ||
| <label className={styles.label} htmlFor={name}> | ||
| <label className={styles.label} htmlFor={id}> | ||
| {preview ? ( | ||
| <Image src={preview} alt="미리보기" fill /> | ||
| ) : ( | ||
|
|
@@ -34,9 +41,9 @@ export default function FileInput({ name, setValue }: FileInputProps) { | |
| <input | ||
| className={styles.input} | ||
| type="file" | ||
| accept="image/png, image/jpeg" | ||
| id={id} | ||
| name={name} | ||
| id={name} | ||
| accept="image/png, image/jpeg" | ||
| onChange={handleChange} | ||
| /> | ||
| </> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| } | ||
|
|
||
| .button { | ||
| line-height: 24px; | ||
| margin-top: 24px; | ||
| padding: 15px 113.5px; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| } | ||
|
|
||
| .input:read-only { | ||
| color: var(--gray-400); | ||
| outline: none; | ||
| } | ||
|
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export const ERROR_MESSAGES = { | ||
| CURRENT_PASSWORD_INCORRECT: 'νμ¬ λΉλ°λ²νΈκ° νλ Έμ΅λλ€.', | ||
| PASSWORDS_MATCH: 'λΉλ°λ²νΈκ° μΌμΉνμ§ μμ΅λλ€.', | ||
| SAME_AS_OLD_PASSWORD: 'κΈ°μ‘΄ λΉλ°λ²νΈμ λμΌν©λλ€.', | ||
| PASSWORD_TOO_SHORT: 'λΉλ°λ²νΈλ₯Ό 8μ μ΄μ μ λ ₯ν΄μ£ΌμΈμ.', | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import useAuthStore from '../store/authStore'; | ||
| import axios from '../lib/axios'; | ||
|
|
||
| const useAuth = () => { | ||
| const { user, accessToken, setUser, setAccessToken } = useAuthStore(); | ||
| const isAuthenticated = !!accessToken; | ||
|
|
||
| const getMe = async () => { | ||
| try { | ||
| const response = await axios.get('/users/me'); | ||
| setUser(response.data); | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
|
|
||
| const login = async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ΄κ±΄ κ°λ° μμμ©μΈκ±ΈκΉμ?! |
||
| try { | ||
| const response = await axios.post('/auth/login', { | ||
| email: '[email protected]', | ||
| password: '12341234', | ||
| }); | ||
| setAccessToken(response.data.accessToken); | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
|
|
||
| const logout = async () => { | ||
| setAccessToken(null); | ||
| }; | ||
|
|
||
| return { | ||
| user, | ||
| accessToken, | ||
| isAuthenticated, | ||
| getMe, | ||
| login, | ||
| logout, | ||
| }; | ||
| }; | ||
|
|
||
| export default useAuth; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄κ±° λμ΄ κ°μ΄ μμΌλ©΄ μΆ©λλμ κ²½κ³ λ°μ€μ΄ μ΄μνκ² λ¨λλΌκ³ μ
μ ν¬ μ΄μ°¨νΌ typescriptλ§ μ¬μ©νλκΉ μμ건 μ§μ μ΅λλ€.