Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/app/mypage/components/Button.module.css
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;
}
18 changes: 18 additions & 0 deletions src/app/mypage/components/Button.tsx
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>
);
}
32 changes: 32 additions & 0 deletions src/app/mypage/components/FileInput.module.css
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;
}
}
44 changes: 44 additions & 0 deletions src/app/mypage/components/FileInput.tsx
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}
Copy link
Collaborator

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๊ฐ€ ์ค‘๋ณต๋ ์ˆ˜ ์žˆ๋Š” ์ƒํ™ฉ์ด์žˆ์„๊ฒƒ๊ฐ™์Šต๋‹ˆ๋‹ค!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์žฌ์‚ฌ์šฉ์„ฑ์„ ๊ณ ๋ คํ•ด์„œ ์ˆ˜์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

onChange={handleChange}
/>
</>
);
}
44 changes: 44 additions & 0 deletions src/app/mypage/components/Input.module.css
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);
}
45 changes: 45 additions & 0 deletions src/app/mypage/components/Input.tsx
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>
);
}
13 changes: 13 additions & 0 deletions src/app/mypage/components/Label.module.css
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;
}
}
15 changes: 15 additions & 0 deletions src/app/mypage/components/Label.tsx
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>
);
}
28 changes: 28 additions & 0 deletions src/app/mypage/components/PasswordForm.module.css
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;
}
}
76 changes: 76 additions & 0 deletions src/app/mypage/components/PasswordForm.tsx
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>
);
}
28 changes: 28 additions & 0 deletions src/app/mypage/components/ProfileForm.module.css
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;
}
}
Loading
Loading