1. QnA Page κ²½λ‘ μ§μ π’

2. QnA Page μ ν π’
import React, { useState } from "react";
import styled from "@emotion/styled";
import ComponentWrapper from "../components/common/ComponentWrapper";
import { QnALists } from "../data/QnAList";
import { QnAListDetailData } from "../data/QnAListDetail";
const QnABoxWrapper = styled.div`
width: 100%;
`;
const QuestionBox = styled.div`
width: 100%;
height: 100px;
cursor: pointer;
border: 1px solid black;
`;
const AnswerBox = styled.div`
width: 100%;
height: 100px;
background-color: #f2f2f2;
border: 1px solid black;
border-top: none;
overflow: hidden;
transition: height 0.4s ease-in-out;
${({ isVisible }) => (isVisible ? "height: 100px;" : "height: 0;")}
`;
const CategoryButton = styled.div`
cursor: pointer;
`;
const QnAPage = () => {
const [visibleCards, setVisibleCards] = useState({});
const handleCardClick = (cardId) => {
setVisibleCards((prevVisibleCards) => ({
...prevVisibleCards,
[cardId]: !prevVisibleCards[cardId],
}));
};
const [category, setCategory] = useState("μνκ΄λ ¨");
const handleSetCategory = (category) => {
setCategory(category);
};
const MapData = QnAListDetailData[category];
return (
<>
{/* μ λͺ©κ³Ό μΉ΄ν
κ³ λ¦¬ λ²νΌ */}
<ComponentWrapper>
<p>μμ£Ό 묻λ μ§λ¬Έ</p>
<>
{QnALists?.map((elem) => (
<CategoryButton
key={elem.id}
onClick={() => handleSetCategory(elem.category)}
style={{ border: "1px solid black" }}
>
{elem.title}
</CategoryButton>
))}
</>
</ComponentWrapper>
{/* μΉ΄λ μμ */}
<ComponentWrapper
style={{
backgroundColor: "yellow",
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
marginTop: "70px",
}}
>
{MapData?.map((elem) => (
<QnABoxWrapper key={elem?.id}>
<QuestionBox onClick={() => handleCardClick(elem?.id)}>
<p>{elem?.title}</p>
<p>{elem?.content}</p>
</QuestionBox>
<AnswerBox isVisible={visibleCards[elem?.id]}>
<p>{elem?.reply}</p>
</AnswerBox>
</QnABoxWrapper>
))}
</ComponentWrapper>
</>
);
};
export default QnAPage;
3. QnA List μ ν π’
export const QnALists = [
{
id: "1",
title: "μνκ΄λ ¨",
category: "μνκ΄λ ¨",
},
{
id: "2",
title: "μ£Όλ¬Έ/κ²°μ ",
category: "μ£Όλ¬Έ/κ²°μ ",
},
{
id: "3",
title: "λ°°μ‘",
category: "λ°°μ‘",
},
{
id: "4",
title: "λ³κ²½/μ·¨μ/λ°ν",
category: "λ³κ²½/μ·¨μ/λ°ν",
},
{
id: "5",
title: "νμμ 보",
category: "νμμ 보",
},
{
id: "6",
title: "μλΉμ€μ΄μ©",
category: "μλΉμ€μ΄μ©",
},
];
4. QnA List Detail μ ν π’
const productQnA = [
{
id: "1",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ1",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ1",
},
{
id: "2",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ2",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ2",
},
{
id: "3",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ3",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ3",
},
{
id: "4",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ4",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ4",
},
{
id: "5",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ5",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ5",
},
{
id: "6",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ6",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ6",
},
{
id: "7",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ7",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ7",
},
{
id: "8",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ8",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ8",
},
{
id: "9",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ9",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ9",
},
{
id: "10",
title: "μνκ΄λ ¨",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ10",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ10",
},
];
const orderAndPayQnA = [
{
id: "1",
title: "μ£Όλ¬Έ/κ²°μ ",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ",
},
];
const deliveryQnA = [
{
id: "1",
title: "λ°°μ‘",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ",
},
];
const modificationEtcQnA = [
{
id: "1",
title: "λ³κ²½/μ·¨μ/λ°ν",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ",
},
];
const userInfoQnA = [
{
id: "1",
title: "νμμ 보",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ",
},
];
const serviceUsageQnA = [
{
id: "1",
title: "μλΉμ€μ΄μ©",
content: "μ΄κ±° λͺ¨λ₯΄κ² μ΄μ",
reply: "μ΄κ²λ λͺ¨λ₯΄λ λ°λ³΄μ",
},
];
export const QnAListDetailData = {
μνκ΄λ ¨: productQnA,
"μ£Όλ¬Έ/κ²°μ ": orderAndPayQnA,
λ°°μ‘: deliveryQnA,
"λ³κ²½/μ·¨μ/λ°ν": modificationEtcQnA,
νμμ 보: userInfoQnA,
μλΉμ€μ΄μ©: serviceUsageQnA,
};
5. νμ¬ λͺ¨μ΅ π’