Skip to content
Open
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
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"pretendard": "^1.3.9",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"react-router": "^7.10.1",
Expand Down
72 changes: 34 additions & 38 deletions src/components/Modal/ModalTest.jsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
// src/pages/ModalTest.jsx
import { useState } from 'react';
import QuestionModal from './QuestionModal';
import Button from '../../components/Button/Button';
import Button from '@/components/Button/Button';
import QuestionModal from '@/components/Modal/QuestionModal';

/**
* Modal ํ…Œ์ŠคํŠธ ํŽ˜์ด์ง€
*
* UI๊ฐ€ ์ž˜ ์ž‘๋™ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธ
* - ์ฝ˜์†”์—์„œ ์งˆ๋ฌธ ๋‚ด์šฉ ํ™•์ธ
*/
export default function ModalTest() {
const [isOpen, setIsOpen] = useState(false);
const handleOpenModal = () => setIsOpen(true);
const handleCloseModal = () => setIsOpen(false);

// ํ…Œ์ŠคํŠธ์šฉ ๋ฐ›๋Š” ์‚ฌ๋žŒ ์ •๋ณด
const recipient = {
name: 'ํ…Œ์ŠคํŠธ์šฉ',
imageSource:
'https://fastly.picsum.photos/id/505/200/200.jpg?hmac=c295sjTIAZ_9Gj-PENrzAbATNIiWPL1dmhIhWndYnyo', // ์ž„์‹œ ์ด๋ฏธ์ง€
};
const testSubjectId = 12629; // ์‹ค์ œ ์กด์žฌํ•˜๋Š” ID Test

const QuestionSuccess = newQuestion => {
console.log('์งˆ๋ฌธ ๋“ฑ๋ก ์„ฑ๊ณต!', newQuestion);
};

return (
<div>
{/* // style={{ padding: '40px' }} */}
<h1>๋ชจ๋‹ฌ ํ…Œ์ŠคํŠธ ํŽ˜์ด์ง€</h1>
<div style={{ padding: '40px' }}>
<h1>Modal ํ…Œ์ŠคํŠธ</h1>

<button onClick={handleOpenModal}>๋ชจ๋‹ฌ ์—ด๊ธฐ</button>
<br />
<br />

<QuestionModal isOpen={isOpen} setIsOpen={handleCloseModal} />
{/* QuestionModal ํ…Œ์ŠคํŠธ ๋ฒ„ํŠผ */}
<Button onClick={() => setIsOpen(true)}>์งˆ๋ฌธ ๋ชจ๋‹ฌ ์—ด๊ธฐ</Button>

{/* Box ๋ฒ„ํŠผ - ๊ธฐ๋ณธ */}
<Button type="box" variant="brown" size="md">
์งˆ๋ฌธ๋ฐ›๊ธฐ
</Button>
{/* Box ๋ฒ„ํŠผ - ์ „์ฒด ๋„ˆ๋น„ (์™ธ๋ถ€ ์ œ์–ด) */}
<Button
type="box"
variant="brown"
size="md"
// style={{ width: '100%' }}
>
๋กœ๊ทธ์ธ
</Button>
{/* Floating ๋ฒ„ํŠผ */}
<Button type="floating" size="md">
์งˆ๋ฌธ ์ž‘์„ฑ
</Button>
<Button type="floating" size="sm">
์‚ญ์ œ ํ•˜๊ธฐ
</Button>
{/* ๋น„ํ™œ์„ฑํ™” */}
<Button type="box" variant="brown" disabled>
์ œ์ถœ
</Button>
{/* ํ™”์‚ดํ‘œ ์•„์ด์ฝ˜ */}
<Button type="box" variant="beige" isArrow>
์งˆ๋ฌธํ•˜๋Ÿฌ ๊ฐ€๊ธฐ
</Button>
{/* QuestionModal */}
<QuestionModal
isOpen={isOpen}
onClose={() => setIsOpen(false)}
recipient={recipient}
subjectId={testSubjectId}
onSuccess={QuestionSuccess}
/>
</div>
);
}
47 changes: 17 additions & 30 deletions src/components/Modal/QuestionModal.jsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
import { useState } from 'react';
import Modal from '../Modal/Modal';
import Button from '../Button/Button';
import TextArea from '../TextArea/TextArea';
import QuestionTarget from './QuestionTarget';
import ModalHeader from './ModalHeader';
import { createQuestion } from '@/services/questionsApi';
import Modal from '@/components/Modal/Modal';
import Button from '@/components/Button/Button';
import TextArea from '@/components/TextArea/TextArea';
import QuestionTarget from '@/components/Modal/QuestionTarget';
import ModalHeader from '@/components/Modal/ModalHeader';
import { useToast } from '@/contexts/Toast/ToastCopy';
import styles from './QuestionModal.module.css';

/**
* ์งˆ๋ฌธ ์ž‘์„ฑ ๋ชจ๋‹ฌ ์ปดํฌ๋„ŒํŠธ (API ์—ฐ๋™ ์™„๋ฃŒ)
*
* ์งˆ๋ฌธ์„ ์ž‘์„ฑํ•˜๊ณ  ์„œ๋ฒ„์— ์ „์†ก
* ์งˆ๋ฌธ ์ž‘์„ฑ ๋ชจ๋‹ฌ ์ปดํฌ๋„ŒํŠธ
*
* @param {boolean} isOpen - ๋ชจ๋‹ฌ ์—ด๋ฆผ/๋‹ซํž˜ (true/false)
* @param {function} onClose - ๋ชจ๋‹ฌ ๋‹ซ๊ธฐ ํ•จ์ˆ˜
* @param {object} recipient - ๋ฐ›๋Š” ์‚ฌ๋žŒ ์ •๋ณด { name, imageSource }
* @param {number} subjectId - ์งˆ๋ฌธ ๋ฐ›์„ ์‚ฌ๋žŒ์˜ ID (์„œ๋ฒ„ ์ „์†ก ์‹œ ํ•„์š”)
* @param {function} onSuccess - ์งˆ๋ฌธ ๋“ฑ๋ก ์„ฑ๊ณต ์‹œ ์‹คํ–‰ํ•  ํ•จ์ˆ˜
* @param {function} onSuccess - ์งˆ๋ฌธ ์ œ์ถœ ์‹œ ์‹คํ–‰ํ•  ์ฝœ๋ฐฑ ํ•จ์ˆ˜ (content๋ฅผ ์ธ์ž๋กœ ๋ฐ›์Œ)
*/
function QuestionModal({ isOpen, onClose, recipient, subjectId, onSuccess }) {
// ์งˆ๋ฌธ ๋‚ด์šฉ ์ƒํƒœ
// ์‚ฌ์šฉ์ž๊ฐ€ textarea์— ์ž…๋ ฅํ•˜๋Š” ๋‚ด์šฉ์„ ์ €์žฅ
function QuestionModal({ isOpen, onClose, recipient, onSuccess }) {
// ์ž…๋ ฅ ๋‚ด์šฉ ์ƒํƒœ
const [content, setContent] = useState('');

// ์ „์†ก ์ค‘ ์ƒํƒœ
// true: API ํ˜ธ์ถœ ์ค‘ (๋ฒ„ํŠผ ๋น„ํ™œ์„ฑํ™”, ์ค‘๋ณต ํด๋ฆญ ๋ฐฉ์ง€)
// false: ๋Œ€๊ธฐ ์ค‘
const [isSubmitting, setIsSubmitting] = useState(false);

const { showToast } = useToast();
// ๋ชจ๋‹ฌ ๋‹ซ์•˜์„ ์‹œ ๋‚ด์šฉ ์‚ญ์ œ
const handleClose = () => {
setContent('');
Expand All @@ -38,23 +30,18 @@ function QuestionModal({ isOpen, onClose, recipient, subjectId, onSuccess }) {
setIsSubmitting(true);

try {
// API ํ˜ธ์ถœ
const newQuestion = await createQuestion(subjectId, { content });
// ๋ถ€๋ชจ๊ฐ€ ์ „๋‹ฌํ•œ callback ์‹คํ–‰ (content๋งŒ ์ „๋‹ฌ)
await onSuccess(content);

// ์„ฑ๊ณต ์‹œ ์ฒ˜๋ฆฌ
setContent(''); // ์ž…๋ ฅ์ฐฝ ๋น„์šฐ๊ธฐ
onClose(); // ๋ชจ๋‹ฌ ๋‹ซ๊ธฐ

onSuccess(newQuestion); // ๋ถ€๋ชจ์—๊ฒŒ ์ƒˆ ์งˆ๋ฌธ ๋ฐ์ดํ„ฐ ์ „๋‹ฌ
console.log('onSuccess ์„ฑ๊ณต๋‚ด์—ญ ', newQuestion);
setContent('');
onClose();
showToast('์งˆ๋ฌธ์ด ๋“ฑ๋ก๋˜์—ˆ์Šต๋‹ˆ๋‹ค');
} catch (error) {
// ์‹คํŒจ ์‹œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ

console.error('์งˆ๋ฌธ ๋“ฑ๋ก ์‹คํŒจ:', error);
alert('์งˆ๋ฌธ ๋“ฑ๋ก์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.');
showToast('์งˆ๋ฌธ ๋“ฑ๋ก์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค');
} finally {
// ์ „์†ก ์ข…๋ฃŒ
alert('์งˆ๋ฌธ ๋“ฑ๋ก ์„ฑ๊ณตํ–ˆ์Šต๋‹ˆ๋‹ค.!');
setIsSubmitting(false); // ๋ฒ„ํŠผ ๋ณด์ด๊ฒŒ
}
};
Expand Down
16 changes: 9 additions & 7 deletions src/components/Modal/QuestionTarget.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styles from './QuestionModal.module.css';

import { Avatar } from '@/components/Avatar/Avatar';
/**
* ์งˆ๋ฌธ ๋Œ€์ƒ์ž ์ •๋ณด ์ปดํฌ๋„ŒํŠธ
*
Expand All @@ -13,12 +13,14 @@ function QuestionTarget({ target }) {
<div className={styles.target}>
<span className={styles.toLabel}>To.</span>

{/* ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ */}
<img
className={styles.profileImg}
src={target.imageSource}
alt={`${target.name} ํ”„๋กœํ•„`}
/>
{/* Avatar ์ปดํฌ๋„ŒํŠธ๋กœ ๊ต์ฒด */}
<Avatar className={styles.profileImg}>
{/* ์ด๋ฏธ์ง€ ๋กœ๋”ฉ ์‹œ๋„ */}
<Avatar.Image src={target.imageSource} alt={`${target.name} ํ”„๋กœํ•„`} />

{/* ์ด๋ฏธ์ง€ ๋กœ๋”ฉ ์‹คํŒจ ์‹œ ๋Œ€์ฒด UI (์ด๋ฆ„ ์ฒซ ๊ธ€์ž) */}
<Avatar.Fallback>{target.name[0]}</Avatar.Fallback>
</Avatar>

{/* ๋ฐ›๋Š” ์‚ฌ๋žŒ ์ด๋ฆ„ */}
<span className={styles.targetName}>{target.name}</span>
Expand Down
6 changes: 5 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import List from './pages/List/ListPage.jsx';
import PostDetail from './pages/Post/PostDetail.jsx';
import PostAnswer from './pages/Post/PostAnswer.jsx';
import Layout from './components/layout/Layout.jsx';

import ModalTest from './components/Modal/ModalTest.jsx';
import './index.css';
import { ToastProvider } from './contexts/Toast/ToastCopy.jsx';

Expand All @@ -28,6 +28,10 @@ const router = createBrowserRouter([
path: 'list',
Component: List,
},
{
path: '/ModalTest',
element: <ModalTest />,
},
{
path: 'post',
children: [
Expand Down