Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.modal {
display: flex;
flex-direction: column;
align-items: center;
gap: 32px;
font-size: 16px;
font-weight: 500;
line-height: 26px;
color: var(--black-100);
padding: 32px 40px;
}

.button {
font-size: 14px;
font-weight: 600;
line-height: 24px;
padding: 9px 83.5px;
}

@media screen and (min-width: 768px) {
.modal {
font-size: 20px;
line-height: 32px;
padding: 40px 64px;
}
.button {
font-size: 16px;
line-height: 26px;
padding: 11px 106px;
}
}
17 changes: 17 additions & 0 deletions src/app/(with-header-sidebar)/mypage/_components/AlertModal.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

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

์š” ํŒŒ์ผ์ด ๋ชจ๋‹ฌ์ธ๊ฑฐ์ฃ ..!?
๊ณต์šฉ์„ ์—ผ๋‘์— ๋‘๊ณ  ๋งŒ๋“œ์…จ๋‹ค๊ณ  ํ•œ๊ฑฐ์—ฌ์„œ ์ถ”๊ฐ€ ์˜๊ฒฌ ๋“œ๋ฆฝ๋‹ˆ๋‹ค..!
๋ชจ๋‹ฌ ๋ณด๋ฉด์€ ์œ„์— ํƒ€์ดํ‹€์ด๋ž‘ x๋ฒ„ํŠผ ์žˆ๊ฑฐ๋‚˜ ์—†๊ฑฐ๋‚˜ ์ด๊ฒƒ๋„ ๊ณ ๋ คํ•ด์ฃผ์‹œ๋ฉด ์ข‹์„๊ฒƒ๊ฐ™์•„์š”
ํ™•์ธ ๋ฒ„ํŠผ๋ถ€๋ถ„๋„ ์žˆ์„์ˆ˜๋„ ์žˆ๊ณ , ์—†์„์ˆ˜๋„ ์žˆ๋Š”๊ฑฐ์—ฌ์„œ ๋‚ด์šฉ+ํ•˜๋‹จ๋ฒ„ํŠผ ๊นŒ์ง€๋ฅผ children์œผ๋กœ ๋ฐ›๊ณ ,
๋ชจ๋‹ฌ์œ„์— ํƒ€์ดํ‹€์ด๋ž‘ x ๋ฒ„ํŠผ ์ด๊ฑฐ๋ฅผ ๋ชจ๋‹ฌ์—์„œ ์ปจํŠธ๋กคํ•˜๋ฉด ์ข‹์„๊ฒƒ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋’ค์— ๊ฒ€์€ ๋ฐฐ๊ฒฝ์— ์Šคํฌ๋กค ๋ง‰๋Š”๊ฑด ๋˜์–ด์žˆ์„๊นŒ์š”?
๊ทธ๋ฆฌ๊ณ  ๊ฒ€์€๋ฐฐ๊ฒฝ ํด๋ฆญํ•˜๋ฉด์€ ๋ชจ๋‹ฌ์ด ๋‹ซํžˆ๋Š”๊ฒƒ๋‘์š”! (์ด๊ฑด ๋‹ซํž๊ฑด์ง€ ์•ˆ๋‹ซํž๊ฑด์ง€๋Š” ๋ชจ๋‹ฌ props๋กœ ์ปจํŠธ๋กคํ•˜๋ฉด ๋” ์‚ฌ์šฉ์„ฑ ๋†’์„๊ฒƒ๊ฐ™์•„์š”)
๋ชจ๋‹ฌ ๋„์šธ๋•Œ ์•ฝ๊ฐ„ ์Šค๋ฅด๋ฅต ์• ๋‹ˆ๋งค์ด์…˜ ์ถ”๊ฐ€ํ•˜๋ฉด ๋” ์žˆ์–ด๋ณด์ผ๊ฒƒ๊ฐ™์Šต๋‹ˆ๋‹ค~

๋” ๋งŒ์•ฝ์— ์—ฌ์œ ๊ฐ€ ๋œ๋‹ค๋ฉด
๋ชจ๋‹ฌ ๋‚ด์—์„œ๋Š” ํƒญ ๋ˆ„๋ฅด๋ฉด ๋ชจ๋‹ฌ ๋‚ด์šฉ์—์„œ๋งŒ ํฌ์ปค์Šค ๋Œ๊ฒŒ๋” ํ•˜๋Š”๊ฒƒ๋„ ์žˆ๋”๋ผ๊ณ ์š” focusTrap ์ด๋ผ๊ณ  ํ•˜๋˜๋ฐ ์ด๊ฒƒ๋„ ๊ณ ๋ คํ•ด๋ณด๋ฉด ์ข‹์„๊ฒƒ๊ฐ™์•„์š”
๊ทธ๋ฆฌ๊ณ  ๋ชจ๋‹ฌ ๋„์šฐ๋ฉด focus๊ฐ€๋Šฅํ•œ ์นœ๊ตฌ์ค‘์— ์ฒซ๋ฒˆ์งธ ์š”์†Œ์— ํฌ์ปค์Šค ๊ฐ€๊ฒŒํ•˜๋ฉด ๋ชจ๋ฐ”์ผ ํ™”๋ฉด์—์„œ ๋ชฌ๊ฐ€ ๊ทธ๋‚˜๋งˆ ์งค๋ฆฌ๋Š”ํ˜„์ƒ? ์ด๋Ÿฐ๊ฒŒ ๋œํ•œ๊ฒƒ ๊ฐ™๋”๋ผ๊ตฌ์š”

์ œ๊ฐ€ ์ €๋ฒˆ ํ”„๋กœ์ ํŠธ ๋•Œ ๋ชจ๋‹ฌ์— ์ง‘์ฐฉ(?)ํ•ด์„œ ์ œ๊ฐ€ ๊ตฌํ˜„ํ–ˆ๋˜ ๋‚ด์šฉ์œ„์ฃผ๋กœ ๋ง์”€๋“œ๋ ค๋ด…๋‹ˆ๋‹ค...ใ…Žใ…Žใ…Ž
ํ˜น์‹œ ๋ง์”€๋“œ๋ฆฐ๊ฑฐ์ค‘์— ์ด๋ฏธ ๊ตฌํ˜„๋˜์–ด์žˆ๋Š”๋ฐ ์ œ๊ฐ€ ๋ชป ์•Œ์•„?๋ณธ๊ฒƒ๋„ ์žˆ์„๊ฒƒ๊ฐ™์•„์š”

์ž˜๋งŒ๋“ค์–ด์ฃผ์‹œ๋ฉด... ์ €๋Š” najitwo-modal ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์“ฐ๊ณ ์‹ถ๋„ค์š”...๐Ÿค—๐Ÿค—

Copy link
Owner Author

@najitwo najitwo Nov 18, 2024

Choose a reason for hiding this comment

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

ํ—ค๋”, ๋ฉ”์ธ, ํ‘ธํ„ฐ ์˜์—ญ ์ด๋Ÿฐ๊ฑด ์ง„์งœ ๋ชจ๋‹ฌ ๋งˆ๋‹ค ๋‹ค๋‹ฌ๋ผ์„œ
๊ป๋ฐ๊ธฐ๋งŒ ๋งŒ๋“ค๊ณ  ํ—ค๋”, ๋ฉ”์ธ, ํ‘ธํ„ฐ๋ฅผ ์•„์˜ˆ ์ปค์Šคํ…€(children)์œผ๋กœ ๋‹ค ๋ฐ›๋Š”๊ฑด ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”?

์Šคํฌ๋กค ๋ง‰๋Š”๊ฒƒ,์• ๋‹ˆ๋ฉ”์ด์…˜,ํฌ์ปค์Šค ์ธ์ง€ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.!
๊ฒ€์€๋ฐฐ๊ฒฝ ํด๋ฆญํ•˜๋ฉด์€ ๋ชจ๋‹ฌ์ด ๋‹ซํžŒ๋‹ค << ์ด๊ฒƒ๋„ ๊ณ ๋ คํ•ด๋ดค๋Š”๋ฐ ๋Œ€์‹œ๋ณด๋“œ ์ถ”๊ฐ€ํ•˜๋‹ค๊ฐ€ ์ž˜๋ชปํด๋ฆญํ•˜๋ฉด ํ—ˆ๋งํ• ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค..๐Ÿ™„

Copy link
Collaborator

@devmanta devmanta Nov 18, 2024

Choose a reason for hiding this comment

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

๊ทธ๋Ÿผ ๋‹ซ์„์ง€๋ง์ง€๋„ ํ”„๋กญ์Šค๋กœ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ•˜๋Š”๊ฑด์š”!?

ํ—ค๋”,๋ฉ”์ธ,ํ‘ธํ„ฐ ๋‹ค ์ž์‹์œผ๋กœ ๋ฐ›์•„๋„๋ ๊ฒƒ..๊ฐ™์€๋ฐ
ํ—ค๋”์ •๋„๋Š” ๋ชจ๋‹ฌ์—์„œ ํ•˜๋Š”๊ฑด์–ด๋•Œ์š” !?
(ํ—ค๋”๋Š” ์žˆ๊ฑฐ๋‚˜ ์—†๊ฑฐ๋‚˜ ๋ง๊ณ  ์Šคํƒ€์ผ์ƒ ๋‹ค๋ฅธ์ƒํ™ฉ์€ ํฌ๊ฒŒ? ์—†์„๊ฒƒ๊ฐ™์•„์š”)

๊ทผ๋ฐ ๊ทธ๊ฑฐ ๋’ค์— ๋”ค์ฒ˜๋ฆฌ๋œ๊ฑฐ ํด๋ฆญํ•˜๊ณ  ๋‹ซ์•„๋„
๋ชจ๋‹ฌ ๋‹ซํž๋•Œ ๋”ฐ๋กœ input์นœ๊ตฌ๋“ค ์ดˆ๊ธฐํ™” ์•ˆํ•ด์ฃผ๋ฉด ๊ฐ’์€ ๋‚จ์•„์ž‡๋”๋ผ๊ณ ์š” ใ…‹ใ…‹ใ…‹ใ…‹ ์ด๊ฑด ์—ฌ๋‹ด.. ์ €๋ฒˆํ”„๋กœ์ ํŠธ๋•Œ ๊ทธ๋ž˜์„œ ๋ฆฌ์…‹ ๋กœ์ง ์ถ”๊ฐ€ํ–‡์–ด์š”..

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ReactNode } from 'react';
import Button from '@/components/Button';
import styles from './AlertModal.module.css';
import useModalStore from '../_store/modalStore';

export default function AlertModal({ children }: { children: ReactNode }) {
const { closeModal } = useModalStore();

return (
<div className={styles.modal}>
{children}
<Button className={styles.button} onClick={closeModal}>
ํ™•์ธ
</Button>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@
display: none;
}

.image {
border-radius: 8px;
}

.hoverContent {
opacity: 0;
transition: opacity 0.3s ease-in-out;
}

.label:hover .image {
filter: brightness(50%);
transition: filter 0.3s ease-in-out;
}

.label:hover .hoverContent {
opacity: 1;
transition: opacity 0.3s ease-in-out;
z-index: 1;
}

@media screen and (min-width: 768px) {
.label {
width: 182px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useEffect } from 'react';
import { ChangeEvent, useState } from 'react';
import Image from 'next/image';
Expand Down Expand Up @@ -31,7 +33,16 @@ export default function FileInput({ name, setValue, url, id }: FileInputProps) {
<>
<label className={styles.label} htmlFor={id}>
{preview ? (
<Image src={preview} alt="๋ฏธ๋ฆฌ๋ณด๊ธฐ" fill />
<>
<Image src={preview} alt="๋ฏธ๋ฆฌ๋ณด๊ธฐ" fill className={styles.image} />
<Image
src="/icons/edit.svg"
alt="์ด๋ฏธ์ง€์ˆ˜์ •"
width={30}
height={30}
className={styles.hoverContent}
/>
</>
) : (
<div className={styles.iconContainer}>
<Image src="/icons/add.svg" alt="์ด๋ฏธ์ง€ ์ถ”๊ฐ€" fill />
Expand Down
64 changes: 64 additions & 0 deletions src/app/(with-header-sidebar)/mypage/_components/Form.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.form {
background-color: var(--white);
border-radius: 8px;
padding: 16px;
}

.profile {
display: flex;
flex-direction: column;
gap: 40px;
}

.userInfo {
flex: 1;
}

.form h2 {
font-size: 18px;
font-weight: 700;
line-height: 26px;
color: var(--black-100);
margin-bottom: 40px;
}

.input {
margin-bottom: 16px;
}

.button {
line-height: 24px;
margin-top: 24px;
padding: 15px 0;
}

@media screen and (min-width: 768px) {
.form {
padding: 24px;
}

.form h2 {
font-size: 24px;
line-height: 32px;
margin-bottom: 24px;
}

.profile {
flex-direction: row;
gap: 42px;
}

.button {
padding: 14px 0;
}
}

@media screen and (min-width: 1200px) {
.form {
max-width: 672px;
}

.userInfo {
max-width: 400px;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { ReactNode } from 'react';
import { FieldError, UseFormRegisterReturn } from 'react-hook-form';
import Label from './Label';
Expand Down Expand Up @@ -38,8 +40,8 @@ export default function Input({
{...register}
/>
{children}
{error && <span className={styles.error}>{error.message}</span>}
</div>
{error && <span className={styles.error}>{error.message}</span>}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
'use client';

import { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import Input from './Input';
import Button from '@/components/Button';
import { ERROR_MESSAGES } from '../constants/message';
import { ERROR_MESSAGES } from '../_constants/message';
import styles from './Form.module.css';
import { updatePassword } from '../lib/authHelper';
import useModalStore from '../_store/modalStore';
import axios from '../_lib/axios';
import AlertModal from './AlertModal';

export interface PasswordFormValues {
currentPassword: string;
Expand All @@ -16,18 +20,43 @@ export default function PasswordForm() {
const {
register,
handleSubmit,
formState: { errors },
formState: { errors, isValid },
watch,
trigger,
setError,
reset,
} = useForm<PasswordFormValues>({ mode: 'onChange' });
const { openModal } = useModalStore();

const customIsValid = Object.keys(errors).length === 0;
const watchedPassword = watch('newPassword');

const onSubmit = async (data: PasswordFormValues) =>
updatePassword(data, reset, setError);
const onSubmit = async (data: PasswordFormValues) => {
try {
await axios.put('/auth/password', {
password: data.currentPassword,
newPassword: data.newPassword,
});
Comment on lines +36 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

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

๋ชฌ๊ฐ€.. ์ €๋Š” apiํ˜ธ์ถœํ•˜๋Š” ๋ถ€๋ถ„์€ ๋ณ„๋„๋กœ ๋นผ์„œ ์ปดํฌ๋„ŒํŠธ์—์„œ๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ๋งŒํ•ด์„œ ์“ฐ๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ํ•˜๊ณ ์žˆ๋Š”๋ฐ
์–ด๋– ์‹ ๊ฐ€์š”~?

Copy link
Owner Author

Choose a reason for hiding this comment

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

@devmanta ์œ ์ € ์ˆ˜์ • ํฌ์ŠคํŠธ ์š”์ฒญ์‹œ ํ•œ๊ธ€ ๋‹‰๋„ค์ž„ ์ž˜๋˜๋˜๋ฐ์š”???
๋ณ„๋„๋กœ ๋นผ๋ฉด ์ข‹์ฃ !!! ๊ท€์ฐฎ์•„์„œ ์•ˆํ–ˆ์Šต๋‹ˆ๋‹ค.. ๐Ÿค

Copy link
Collaborator

Choose a reason for hiding this comment

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

@najitwo ๊ทธ๋Ÿฐ์ด์œ ๋ผ๋ฉด ๋นผ.์ฃผ.์„ธ.์š”. ๐Ÿ˜‡

Copy link
Collaborator

Choose a reason for hiding this comment

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

๋“ฑ๋ก๋งŒ ๊ทธ๋Ÿผ ํ•œ๊ธ€์ด์•ˆ๋˜๋Š”๊ฑด๊ฐ€. . . . . .

reset();
} catch (error) {
if (error instanceof Error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error ์ธ์Šคํ„ด์Šค๊ฐ€ ์•„๋‹๊ฒฝ์šฐ๋„ ์žˆ๋‚˜์š”..!?

Copy link
Owner Author

Choose a reason for hiding this comment

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

catch์˜ error ํƒ€์ž…์ด unkown์ด๋ผ ํƒ€์ž… ์ขํžˆ๊ธฐ๋กœ ์‚ฌ์šฉํ•œ ๊ฒƒ ์ž…๋‹ˆ๋‹ค.!!

if (error.message === ERROR_MESSAGES.CURRENT_PASSWORD_INCORRECT) {
openModal(<AlertModal>{error.message}</AlertModal>);
setError('currentPassword', {
type: 'manual',
message: error.message,
});
}
if (error.message === ERROR_MESSAGES.SAME_AS_OLD_PASSWORD) {
openModal(<AlertModal>{error.message}</AlertModal>);
setError('newPassword', {
type: 'manual',
message: error.message,
});
}
Comment on lines +43 to +56
Copy link
Collaborator

Choose a reason for hiding this comment

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

๋ชฌ๊ฐ€..if๋ฌธ์•ˆ์— if๋ฌธ์€ ์ง€์–‘ํ•˜๋Š” ๋А๋‚Œ์ด์—ฌ์„œ
switch ๋ฌธ์„ ์“ฐ๋ฉด ๋” ๋ณด๊ธฐ ํŽธํ• ๊ฒƒ๊ฐ™์•„์š”!
์•„๋‹ˆ๋ฉด ์š”๋Ÿฐ๋А๋‚Œ๋„ ์ข‹์„๊ฒƒ๊ฐ™์•„์š”~!

Suggested change
if (error.message === ERROR_MESSAGES.CURRENT_PASSWORD_INCORRECT) {
openModal(<AlertModal>{error.message}</AlertModal>);
setError('currentPassword', {
type: 'manual',
message: error.message,
});
}
if (error.message === ERROR_MESSAGES.SAME_AS_OLD_PASSWORD) {
openModal(<AlertModal>{error.message}</AlertModal>);
setError('newPassword', {
type: 'manual',
message: error.message,
});
}
const errorHandlingMap = {
[ERROR_MESSAGES.CURRENT_PASSWORD_INCORRECT]: 'currentPassword',
[ERROR_MESSAGES.SAME_AS_OLD_PASSWORD]: 'newPassword',
};
const field = errorHandlingMap[error.message];
if (field) {
openModal(<AlertModal>{error.message}</AlertModal>);
setError(field, {
type: 'manual',
message: error.message,
});
}

}
}
};

useEffect(() => {
if (watchedPassword) {
Expand All @@ -44,7 +73,9 @@ export default function PasswordForm() {
name="currentPassword"
label="ํ˜„์žฌ ๋น„๋ฐ€๋ฒˆํ˜ธ"
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ"
register={register('currentPassword')}
register={register('currentPassword', {
required: ERROR_MESSAGES.PASSWORD_REQUIRE,
})}
error={errors.currentPassword}
/>
<Input
Expand All @@ -54,6 +85,7 @@ export default function PasswordForm() {
label="์ƒˆ ๋น„๋ฐ€๋ฒˆํ˜ธ"
placeholder="์ƒˆ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ"
register={register('newPassword', {
required: ERROR_MESSAGES.PASSWORD_REQUIRE,
minLength: {
value: 8,
message: ERROR_MESSAGES.PASSWORD_TOO_SHORT,
Expand All @@ -70,11 +102,17 @@ export default function PasswordForm() {
validate: {
matchesPassword: (value) =>
value === watchedPassword || ERROR_MESSAGES.PASSWORDS_MATCH,
required: (value) =>
value !== '' || ERROR_MESSAGES.PASSWORD_REQUIRE,
},
})}
error={errors.newPasswordConfirmation}
/>
<Button className={styles.button} type="submit" disabled={!customIsValid}>
<Button
className={styles.button}
type="submit"
disabled={!(isValid && customIsValid)}
>
๋ณ€๊ฒฝ
</Button>
</form>
Expand Down
75 changes: 75 additions & 0 deletions src/app/(with-header-sidebar)/mypage/_components/ProfileForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use client';

import { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import useAuth from '../_hooks/useAuth';
import FileInput from './FileInput';
import Input from './Input';
import Button from '@/components/Button';
import { updateProfile } from '../_lib/userService';
import styles from './Form.module.css';
import { ERROR_MESSAGES } from '../_constants/message';

export interface ProfileFormValues {
image: File | null;
email: string;
nickname: string;
}

export default function ProfileForm() {
const { user } = useAuth();
const {
register,
handleSubmit,
formState: { errors, isValid },
setValue,
reset,
} = useForm<ProfileFormValues>({ mode: 'onChange' });

const onSubmit = async (data: ProfileFormValues) => updateProfile(data);

useEffect(() => {
if (user) {
const { email, nickname } = user;
reset({ email, nickname });
}
}, [reset, user]);

return (
<form className={styles.form} onSubmit={handleSubmit(onSubmit)}>
<h2>ํ”„๋กœํ•„</h2>
<div className={styles.profile}>
<FileInput
id="image"
name="image"
setValue={setValue}
url={user?.profileImageUrl}
/>
<div className={styles.userInfo}>
<Input
className={styles.input}
type="text"
name="email"
label="์ด๋ฉ”์ผ"
register={register('email')}
readOnly
/>
<Input
className={styles.input}
type="text"
name="nickname"
label="๋‹‰๋„ค์ž„"
placeholder="๋‹‰๋„ค์ž„ ์ž…๋ ฅ"
register={register('nickname', {
required: ERROR_MESSAGES.NICKNAME_REQUIRE,
})}
error={errors.nickname}
/>
<Button className={styles.button} type="submit" disabled={!isValid}>
์ €์žฅ
</Button>
</div>
</div>
</form>
);
}
17 changes: 17 additions & 0 deletions src/app/(with-header-sidebar)/mypage/_components/modal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
}

.modal {
background: var(--white);
border-radius: 16px;
}
Loading