[TIL/React] 2023/09/22

์›๋ฏผ๊ด€ยท2023๋…„ 9์›” 22์ผ

[TIL]

๋ชฉ๋ก ๋ณด๊ธฐ
114/204

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. ํ˜„์žฌ ๋ชจ์Šต ๐ŸŸข

profile
Write a little every day, without hope, without despair โœ๏ธ

0๊ฐœ์˜ ๋Œ“๊ธ€