Skip to content

Commit

Permalink
๐Ÿ—‘๏ธ Chore : ์ƒ์„ธ์ •๋ณด ๋ชจ๋‹ฌ ๊ตฌํ˜„ ๋ฐ mbti์„ ํƒ ์ปดํฌ๋„ŒํŠธ ์ˆ˜์ • (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
g89g6 committed Sep 30, 2024
1 parent 398bd90 commit 090b6e3
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/components/MbtiSelector/MbtiSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import './MbtiSelector.css';

type MbtiType = 'EI' | 'SN' | 'TF' | 'JP';
Expand All @@ -15,7 +15,11 @@ interface MbtiRowProps {
onChange: () => void;
}

const MbtiSelector = () => {
interface MbtiSelectorProps {
onMbtiChange: (mbti: string) => void;
}

const MbtiSelector: React.FC<MbtiSelectorProps> = ({ onMbtiChange }) => {
const [mbti, setMbti] = useState<MbtiState>({
EI: false,
SN: false,
Expand All @@ -27,49 +31,52 @@ const MbtiSelector = () => {
setMbti((prev) => ({ ...prev, [key]: !prev[key] }));
};

const getMbtiResult = (): string => {
const getMbtiResult = useCallback((): string => {
return (
(mbti.EI ? 'I' : 'E') +
(mbti.SN ? 'N' : 'S') +
(mbti.TF ? 'F' : 'T') +
(mbti.JP ? 'P' : 'J')
);
};
}, [mbti]);

useEffect(() => {
const result = getMbtiResult();
onMbtiChange(result);
}, [getMbtiResult, onMbtiChange]);

return (
<div className="mbti-container">

<div className="mbti-flex-container">
<MbtiRow
<MbtiRow
label="์—๋„ˆ์ง€์˜ ๋ฐฉํ–ฅ"
leftOption="E (์™ธํ–ฅํ˜•)"
rightOption="I (๋‚ดํ–ฅํ˜•)"
isRight={mbti.EI}
onChange={() => updateMbti('EI')}
/>
<MbtiRow
<MbtiRow
label="์ธ์‹ ๋ฐฉ์‹"
leftOption="S (๊ฐ๊ฐํ˜•)"
rightOption="N (์ง๊ด€ํ˜•)"
isRight={mbti.SN}
onChange={() => updateMbti('SN')}
/>
<MbtiRow
<MbtiRow
label="๊ฒฐ์ • ๋ฐฉ์‹"
leftOption="T (์‚ฌ๊ณ ํ˜•)"
rightOption="F (๊ฐ์ •ํ˜•)"
isRight={mbti.TF}
onChange={() => updateMbti('TF')}
/>
<MbtiRow
<MbtiRow
label="์‚ถ์˜ ํŒจํ„ด"
leftOption="J (ํŒ๋‹จํ˜•)"
rightOption="P (์ธ์‹ํ˜•)"
isRight={mbti.JP}
onChange={() => updateMbti('JP')}
/>
</div>

<div className="mbti-result">
<p>์„ ํƒ๋œ MBTI <span className="mbti-result-text">{getMbtiResult()}</span></p>
</div>
Expand Down
61 changes: 61 additions & 0 deletions src/pages/JoinPage/JoinDetail/JoinDetail.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.join-detail {
padding: 20px;
}

.join-detail h2 {
font-size: 18px;
margin-bottom: 20px;
}

.join-detail h3 {
font-size: 1.0rem;
margin-bottom: 10px;
font-weight: 600;
}

.gender-selector, .birth-date-selector, .mbti-selector {
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #EEEEEE;
}

.gender-options {
display: flex;
justify-content: left;
gap: 20px;
}

.gender-options label {
display: flex;
align-items: center;
cursor: pointer;
}

.gender-options input[type="radio"] {
margin-left: 15px;
}

.birth-date-selector {
display: flex;
flex-direction: column;
align-items: flex-start;
}

.birth-date-selector h3 {
align-self: flex-start;
}

.birth-date-selector input {
width: 400px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
text-align: center;
align-self: center;
}

.mbti-selector {
width: 100%;
border-bottom: none;
}
67 changes: 67 additions & 0 deletions src/pages/JoinPage/JoinDetail/JoinDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { useState } from 'react';
import BottomModal from '@components/BottomModal/BottomModal';
import MbtiSelector from '@components/MbtiSelector/MbtiSelector';
import './JoinDetail.css';

const JoinDetail: React.FC = () => {
const [gender, setGender] = useState<'male' | 'female'>('male');
const [birthDate, setBirthDate] = useState('');
const [mbti, setMbti] = useState('');

const handleMbtiChange = (selectedMbti: string) => {
setMbti(selectedMbti);
};

const handleSubmit = () => {
console.log({ gender, birthDate, mbti });
};

return (
<BottomModal onClick={handleSubmit} buttonText="ํ™•์ธ">
<div className="join-detail">
<div className="gender-selector">
<h3>์„ฑ๋ณ„</h3>
<div className="gender-options">
<label>
๋‚จ
<input
type="radio"
name="gender"
value="male"
checked={gender === 'male'}
onChange={() => setGender('male')}
/>

</label>
<label>
์—ฌ
<input
type="radio"
name="gender"
value="female"
checked={gender === 'female'}
onChange={() => setGender('female')}
/>

</label>
</div>
</div>
<div className="birth-date-selector">
<h3>์ƒ๋…„์›”์ผ</h3>
<input
type="date"
value={birthDate}
onChange={(e) => setBirthDate(e.target.value)}
placeholder="YYYY.MM.DD"
/>
</div>
<div className="mbti-selector">
<h3>MBTI</h3>
<MbtiSelector onMbtiChange={handleMbtiChange} />
</div>
</div>
</BottomModal>
);
};

export default JoinDetail;
File renamed without changes.
File renamed without changes.

0 comments on commit 090b6e3

Please sign in to comment.