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
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
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>
);
}
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;
}
35 changes: 35 additions & 0 deletions src/app/(with-header-sidebar)/mypage/_components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useEffect } from 'react';
import { createPortal } from 'react-dom';
import useModalStore from '../_store/modalStore';
import styles from './modal.module.css';

export default function Modal() {
const { modals, closeModal } = useModalStore();

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
closeModal();
}
};

window.addEventListener('keydown', handleKeyDown);

return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [closeModal]);

if (modals.length === 0) return null;

return createPortal(
<div className={styles.overlay}>
{modals.map((content, index) => (
<div key={index} className={styles.modal}>
{content}
</div>
))}
</div>,
document.body
);
}
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
Loading