[TIL/React] 2023/09/22

원민관·2023λ…„ 9μ›” 22일

[TIL]

λͺ©λ‘ 보기
114/201

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개의 λŒ“κΈ€