-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] add forms to mypage #6
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
Merged
najitwo
merged 1 commit into
develop
from
3-feat-add-profile-and-password-forms-to-mypage
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
| .button { | ||
| width: 100%; | ||
| background-color: var(--violet); | ||
| border-radius: 8px; | ||
| font-size: 14px; | ||
| font-weight: 600; | ||
| line-height: 24px; | ||
| color: var(--white); | ||
| } | ||
|
|
||
| .button:disabled { | ||
| background-color: var(--gray-400); | ||
| cursor: auto; | ||
| } |
This file contains hidden or 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,18 @@ | ||
| import { ButtonHTMLAttributes, PropsWithChildren } from 'react'; | ||
| import styles from './Button.module.css'; | ||
|
|
||
| interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
| className?: string; | ||
| } | ||
|
|
||
| export default function Button({ | ||
| className = '', | ||
| children, | ||
| ...props | ||
| }: PropsWithChildren<ButtonProps>) { | ||
| return ( | ||
| <button className={`${styles.button} ${className}`} {...props}> | ||
| {children} | ||
| </button> | ||
| ); | ||
| } |
This file contains hidden or 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 @@ | ||
| .label { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| width: 100px; | ||
| height: 100px; | ||
| border-radius: 8px; | ||
| background-color: var(--gray-200); | ||
| cursor: pointer; | ||
| position: relative; | ||
| } | ||
|
|
||
| .iconContainer { | ||
| position: relative; | ||
| width: 20px; | ||
| height: 20px; | ||
| } | ||
|
|
||
| .input { | ||
| display: none; | ||
| } | ||
|
|
||
| @media screen and (min-width: 768px) { | ||
| .label { | ||
| width: 182px; | ||
| height: 182px; | ||
| } | ||
| .imageContainer { | ||
| width: 30px; | ||
| height: 30px; | ||
| } | ||
| } |
This file contains hidden or 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,44 @@ | ||
| 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>; | ||
| } | ||
|
|
||
| export default function FileInput({ name, setValue }: FileInputProps) { | ||
| const [preview, setPreview] = useState(''); | ||
|
|
||
| const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
| const file = event.target.files?.[0]; | ||
| if (file) { | ||
| setPreview(URL.createObjectURL(file)); | ||
| setValue('image', file); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <label className={styles.label} htmlFor={name}> | ||
| {preview ? ( | ||
| <Image src={preview} alt="๋ฏธ๋ฆฌ๋ณด๊ธฐ" fill /> | ||
| ) : ( | ||
| <div className={styles.iconContainer}> | ||
| <Image src="/icons/add.svg" alt="์ด๋ฏธ์ง ์ถ๊ฐ" fill /> | ||
| </div> | ||
| )} | ||
| </label> | ||
| <input | ||
| className={styles.input} | ||
| type="file" | ||
| accept="image/png, image/jpeg" | ||
| name={name} | ||
| id={name} | ||
| onChange={handleChange} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
This file contains hidden or 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,44 @@ | ||
| .container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 8px; | ||
| } | ||
|
|
||
| .inputWrapper { | ||
| position: relative; | ||
| } | ||
|
|
||
| .input { | ||
| width: 100%; | ||
| border: 1px solid var(--gray-300); | ||
| border-radius: 8px; | ||
| font-size: 16px; | ||
| font-weight: 400; | ||
| line-height: 26px; | ||
| color: var(--black-100); | ||
| padding: 12px 16px; | ||
| } | ||
|
|
||
| .input:read-only { | ||
| outline: none; | ||
| } | ||
|
|
||
| .input:focus:not(:read-only) { | ||
| outline-color: var(--violet); | ||
| } | ||
|
|
||
| .input::placeholder { | ||
| color: var(--gray-400); | ||
| } | ||
|
|
||
| .errorFocus { | ||
| outline: 1px solid var(--red); | ||
| } | ||
|
|
||
| .error { | ||
| display: block; | ||
| font-size: 14px; | ||
| font-weight: 400; | ||
| line-height: 24px; | ||
| color: var(--red); | ||
| } |
This file contains hidden or 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,45 @@ | ||
| import { ReactNode } from 'react'; | ||
| import { FieldError, UseFormRegisterReturn } from 'react-hook-form'; | ||
| import Label from './Label'; | ||
| import styles from './Input.module.css'; | ||
|
|
||
| interface InputProps { | ||
| type: string; | ||
| name: string; | ||
| className?: string; | ||
| label?: string; | ||
| placeholder?: string; | ||
| children?: ReactNode; | ||
| register?: UseFormRegisterReturn; | ||
| error?: FieldError; | ||
| readOnly?: boolean; | ||
| } | ||
|
|
||
| export default function Input({ | ||
| type, | ||
| name, | ||
| className = '', | ||
| label = '', | ||
| placeholder = '', | ||
| children, | ||
| register, | ||
| error, | ||
| readOnly = false, | ||
| }: InputProps) { | ||
| return ( | ||
| <div className={`${styles.container} ${className}`}> | ||
| <Label htmlFor={name}>{label}</Label> | ||
| <div className={styles.inputWrapper}> | ||
| <input | ||
| className={`${styles.input} ${error ? styles.errorFocus : ''}`} | ||
| type={type} | ||
| placeholder={placeholder} | ||
| readOnly={readOnly} | ||
| {...register} | ||
| /> | ||
| {children} | ||
| {error && <span className={styles.error}>{error.message}</span>} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,13 @@ | ||
| .label { | ||
| font-size: 14px; | ||
| font-weight: 400; | ||
| line-height: 24px; | ||
| color: var(--black-100); | ||
| } | ||
|
|
||
| @media screen and (min-width: 768px) { | ||
| .label { | ||
| font-size: 16px; | ||
| line-height: 26px; | ||
| } | ||
| } |
This file contains hidden or 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,15 @@ | ||
| import { ReactNode } from 'react'; | ||
| import styles from './Label.module.css'; | ||
|
|
||
| interface LabelProps { | ||
| htmlFor: string; | ||
| children?: ReactNode; | ||
| } | ||
|
|
||
| export default function Label({ htmlFor, children }: LabelProps) { | ||
| return ( | ||
| <label className={styles.label} htmlFor={htmlFor}> | ||
| {children} | ||
| </label> | ||
| ); | ||
| } |
This file contains hidden or 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,28 @@ | ||
| .form h2 { | ||
| font-size: 18px; | ||
| font-weight: 700; | ||
| line-height: 26px; | ||
| color: var(--black-100); | ||
| margin-bottom: 40px; | ||
| } | ||
|
|
||
| .input { | ||
| margin-bottom: 16px; | ||
| } | ||
|
|
||
| .button { | ||
| margin-top: 24px; | ||
| padding: 15px 113.5px; | ||
| } | ||
|
|
||
| @media screen and (min-width: 768px) { | ||
| .form h2 { | ||
| font-size: 24px; | ||
| line-height: 32px; | ||
| margin-bottom: 24px; | ||
| } | ||
|
|
||
| .button { | ||
| padding: 14px 236px; | ||
| } | ||
| } |
This file contains hidden or 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,76 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect } from 'react'; | ||
| import { useForm } from 'react-hook-form'; | ||
| import Input from './Input'; | ||
| import Button from './Button'; | ||
| import styles from './PasswordForm.module.css'; | ||
|
|
||
| interface FormValues { | ||
| currentPassword: string; | ||
| newPassword: string; | ||
| newPasswordConfirmation: string; | ||
| } | ||
|
|
||
| export default function PasswordForm() { | ||
| const { | ||
| register, | ||
| handleSubmit, | ||
| formState: { errors, isValid }, | ||
| watch, | ||
| trigger, | ||
| } = useForm<FormValues>({ mode: 'onChange' }); | ||
|
|
||
| const watchedPassword = watch('newPassword'); | ||
|
|
||
| const onSubmit = () => {}; | ||
|
|
||
| useEffect(() => { | ||
| if (watchedPassword) { | ||
| trigger('newPasswordConfirmation'); | ||
| } | ||
| }, [watchedPassword, trigger]); | ||
|
|
||
| return ( | ||
| <form className={styles.form} onSubmit={handleSubmit(onSubmit)}> | ||
| <h2>๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ</h2> | ||
| <Input | ||
| className={styles.input} | ||
| type="password" | ||
| name="currentPassword" | ||
| label="ํ์ฌ ๋น๋ฐ๋ฒํธ" | ||
| placeholder="๋น๋ฐ๋ฒํธ ์ ๋ ฅ" | ||
| /> | ||
| <Input | ||
| className={styles.input} | ||
| type="password" | ||
| name="newPassword" | ||
| label="์ ๋น๋ฐ๋ฒํธ" | ||
| placeholder="์ ๋น๋ฐ๋ฒํธ ์ ๋ ฅ" | ||
| register={register('newPassword', { | ||
| minLength: { | ||
| value: 8, | ||
| message: '๋น๋ฐ๋ฒํธ๋ฅผ 8์ ์ด์ ์ ๋ ฅํด์ฃผ์ธ์.', | ||
| }, | ||
| })} | ||
| error={errors.newPassword} | ||
| /> | ||
| <Input | ||
| type="password" | ||
| name="newPasswordConfirmation" | ||
| label="์ ๋น๋ฐ๋ฒํธ ํ์ธ" | ||
| placeholder="์ ๋น๋ฐ๋ฒํธ ํ์ธ" | ||
| register={register('newPasswordConfirmation', { | ||
| validate: { | ||
| matchesPassword: (value) => | ||
| value === watchedPassword || '๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.', | ||
| }, | ||
| })} | ||
| error={errors.newPasswordConfirmation} | ||
| /> | ||
| <Button className={styles.button} type="submit" disabled={!isValid}> | ||
| ๋ณ๊ฒฝ | ||
| </Button> | ||
| </form> | ||
| ); | ||
| } |
This file contains hidden or 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,28 @@ | ||
| .form h2 { | ||
| font-size: 18px; | ||
| font-weight: 700; | ||
| line-height: 26px; | ||
| color: var(--black-100); | ||
| margin-bottom: 40px; | ||
| } | ||
|
|
||
| .input { | ||
| margin-bottom: 16px; | ||
| } | ||
|
|
||
| .button { | ||
| margin-top: 24px; | ||
| padding: 15px 113.5px; | ||
| } | ||
|
|
||
| @media screen and (min-width: 768px) { | ||
| .form h2 { | ||
| font-size: 24px; | ||
| line-height: 32px; | ||
| margin-bottom: 24px; | ||
| } | ||
|
|
||
| .button { | ||
| padding: 14px 236px; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
name๊ฐ์ ํญ์ imgFile ๊ฐ์ธ๊ฐ์..? FileInputProps ์ธํฐํ์ด์ค์
name: 'imgFile';์ด๋ ๊ฒ ๋์ด์๊ธธ๋..ํ๊ณณ์์ ํ๋ฒ๋ง ์ฐ๋ ์ฉ๋๋ผ๋ฉด ๊ด์ฐฎ์๊ฒ๊ฐ์๋ฐ ๊ณตํต์ปดํฌ๋ํธ๋ก ์๊ฐํ๋ฉด id๊ฐ ์ค๋ณต๋ ์ ์๋ ์ํฉ์ด์์๊ฒ๊ฐ์ต๋๋ค!
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.
์ฌ์ฌ์ฉ์ฑ์ ๊ณ ๋ คํด์ ์์ ํด๋ณด๊ฒ ์ต๋๋ค.