ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

Issue

ํ”„๋กœ์ ํŠธ ๋„์ค‘ ํšŒ์› ๊ฐ€์ž… ์ฐฝ์ด ๋œจ๊ธฐ ์ „์— ์ด์šฉ ์•ฝ๊ด€ ๋™์˜ ์ฐฝ์— ๋Œ€ํ•œ ๋””์ž์ธ ์‹œ์•ˆ์ด ์ถ”๊ฐ€๋˜์—ˆ๋‹ค.

 

์ฒ˜์Œ์—๋Š” ์ด์šฉ ์•ฝ๊ด€ ๋™์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ–ˆ์ง€๋งŒ, ์ฒดํฌ ๋ฐ•์Šค ๊ด€๋ จ ๊ธฐ๋Šฅ์€ ์•ž์œผ๋กœ๋„ ๋งŽ์ด ์“ฐ์ผ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฒˆ ๊ธฐํšŒ์— ์Šค์Šค๋กœ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด๋ณด๊ธฐ๋กœ ํ•˜์˜€๋‹ค.

 

Code

์šฐ์„ , ๊ฐ ์ฒดํฌ ๋ฐ•์Šค์˜ ์ฒดํฌ ํ™œ์„ฑ์— ๋Œ€ํ•œ ์—ฌ๋ถ€๋ฅผ ์ €์žฅํ•ด์ฃผ์–ด์•ผ ์ด์šฉ ์•ฝ๊ด€ ๋™์˜ ์ฐฝ์—์„œ ์—ฌ๋Ÿฌ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐ ์ฒดํฌ ๋ฐ•์Šค์˜ Key๊ฐ’์— ๋Œ€ํ•œ ์ฒดํฌ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” Boolean Value๋ฅผ ์ง€๋‹Œ ๊ฐ์ฒด๋ฅผ state๊ฐ’์œผ๋กœ ์ดˆ๊ธฐํ™” ํ•˜์˜€๋‹ค.

const [checkInfo, setCheckInfo] = useState({
    webAccessCheck: false,
    privateInfoCheck: false,
    advertiseCheck: false,
  });

๊ฐ ์ฒดํฌ ๋ฐ•์Šค๋ฅผ ํด๋ฆญํ•˜์˜€์„ ๊ฒฝ์šฐ ๊ฐ™์€ ์ด๋ฒคํŠธ ๋™์ž‘์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ ์ฒดํฌ ๋ฐ•์Šค์— onClick ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๋ฐ”์ธ๋”ฉํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์•„๋‹Œ ์ด๋“ค์„ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ์ƒ์œ„ ํƒœ๊ทธ ํ•˜๋‚˜์—๋งŒ onClick ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๋ฐ”์ธ๋”ฉ์‹œ์ผœ ์ฃผ์–ด, event targeting์ด ๋ฐœ์ƒ๋˜๋„๋ก ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์˜€๋‹ค.

const checkClickSort = event => {
    const currentTargetElementInfo = nodeName: event.target.nodeName

    if (currentTargetElementInfo.nodeName !== "BUTTON") return;

    const currentTargetButtonSort = event.target.dataset.buttonsort;
    const currentButtonName = event.target.name;

    switch (currentTargetButtonSort) {
      case "checkButton":
        setCheckValue("checkInfo", currentButtonName);
        break;
      case "nextButton":
        goToRegisterForm();
        break;
      default:
        break;
    }
  };

ํ˜„์žฌ ์ด์šฉ ์•ฝ๊ด€ ๋™์˜ ํผ์—๋Š” ํฌ๊ฒŒ ์ฒดํฌ ๋ฒ„ํŠผ๊ณผ next ๋ฒ„ํŠผ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— curret.event.target ๊ฐ’์„ ์ •ํ™•ํ•˜๊ฒŒ ํƒ€๊ฒŸํŒ…ํ•ด์ฃผ๊ธฐ ์œ„ํ•ด ์ƒ์œ„ ํƒœ๊ทธ ์š”์†Œ์— onClick ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์— ์ด๋ฅผ ์‹๋ณ„ํ•ด ์ค„ ์ˆ˜ ์žˆ๋Š” checkClickSort ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ๋ฐ”์ธ๋”ฉํ•ด์ฃผ์—ˆ๋‹ค.

 

๋งŒ์•ฝ์— ํ˜„์žฌ ํด๋ฆญ๋œ ๋ฒ„ํŠผ์ด ์ฒดํฌ ๋ฐ•์Šค ๋ฒ„ํŠผ์ผ ๊ฒฝ์šฐ์—๋Š” setCheckValue ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ฃผ์—ˆ๋‹ค.

const setCheckValue = (currentTargetedState, currentButtonName) => {
    if (currentTargetedState === "checkInfo")
      if (currentButtonName === "allCheck") {
        if (isAllChecked()) { 
          setCheckInfo({ //๋ชจ๋‘ ์ฒดํฌ๊ฐ€ ๋œ ๊ฒฝ์šฐ => ๋‹ค๋ฅธ ์ฒดํฌ ๊ฐ’๋“ค์„ unactive ์ฒ˜๋ฆฌ
            ...checkInfo,
            webAccessCheck: false,
            privateInfoCheck: false,
            advertiseCheck: false,
          });
        } else { // ๋ชจ๋‘ ์ฒดํฌ๊ฐ€ ๋œ ๊ฒฝ์šฐ => ๋‹ค๋ฅธ ์ฒดํฌ ๊ฐ’๋“ค์„ active ์ฒ˜๋ฆฌ
          setCheckInfo({
            ...checkInfo,
            webAccessCheck: true,
            privateInfoCheck: true,
            advertiseCheck: true,
          });
        }
      } else {
        setCheckInfo({
          ...checkInfo,
          [currentButtonName]: !checkInfo[currentButtonName],
        });
      }
  };

ํ•ด๋‹น ํ•จ์ˆ˜๋Š” ํฌ๊ฒŒ ๋‘ ๋ถ„๊ธฐ๋กœ ๋‚˜๋‰œ๋‹ค.

์ฒซ ๋ฒˆ์งธ๋Š” ํ•ด๋‹น ์ฒดํฌ ๋ฐ•์Šค ๋ฒ„ํŠผ์ด AllCheck ๋ฒ„ํŠผ์ผ ๊ฒฝ์šฐ์™€ ๋‘ ๋ฒˆ์งธ๋Š” ๊ทธ ์™ธ์— Check ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ๊ฒฝ์šฐ๋กœ ๋ถ„๊ธฐ ๋ฐ ์‹๋ณ„ ์ฒ˜๋ฆฌํ•œ๋‹ค.

 

์ „์ž์ผ ๊ฒฝ์šฐ์—๋Š” isAllChecked ๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ Object.entries() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ ์ฒดํฌ๋ฐ•์Šค ํ‚ค ๊ฐ’์— ๋Œ€ํ•œ Boolean Value๋ฅผ ํ™•์ธํ•ด์ฃผ๋ฉฐ ์ตœ์ข…์ ์œผ๋กœ ์ˆœํšŒ๋ ๋•Œ๊นŒ์ง€ ํ•˜๋‚˜๋ผ๋„ false์ผ ๊ฒฝ์šฐ์—๋Š” ์‚ฌ์ „์— ์ •์˜ํ•œ allChecked ๋ณ€์ˆ˜๋ฅผ false๋กœ ๋ฆฌํ„ด์‹œํ‚ค๋ฉฐ ๊ทธ ๋ฐ˜๋Œ€๋Š” true๋ฅผ ๋ฆฌํ„ด์‹œํ‚ค๋„๋ก ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์˜€๋‹ค.

const isAllChecked = () => {
    let allChecked = true;
    for (const value of Object.values(checkInfo)) {
      if (!value) allChecked = false; // ํ•˜๋‚˜๋ผ๋„ ์ฒดํฌ๊ฐ€ ๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด allChecked => false
    }
    return allChecked;
  };

๊ทธ๋Ÿฐ ๋‹ค์Œ ๊ฐ ์ฒดํฌ ๋ฐ•์Šค์— ๋Œ€ํ•ด checkActvie() ํ•จ์ˆ˜๋ฅผ ๋ฐ”์ธ๋”ฉํ•ด์ฃผ๊ณ  ๋งŒ์•ฝ์— ํ•ด๋‹น ๊ฐ’์ด true์ธ์ง€ false์ธ์ง€์— ๋”ฐ๋ผ style img๊ฐ€ ๋™์ ์œผ๋กœ ๋ฐ”๋€Œ๋„๋ก ๋‹ค์Œ๊ณผ ๊ฐ™์ด styled-components๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ background-image ๊ฐ’์„ ๋ฐ”๊ฟ”์ฃผ์—ˆ๋‹ค.

const CheckIcon = styled.button`
  width: 40px;
  height: 40px;
  background: ${({ active }) =>
      active
        ? "url(./images/icon_active_check.png)"
        : "url(./images/icon_unactive_check.png)"}
    no-repeat;
  background-position: center;
  background-size: contain;
  border: none;
  cursor: pointer;
`;

๋˜ํ•œ ํ•„์ˆ˜ ์ฒดํฌ ํ•ญ๋ชฉ์ด ๋ชจ๋‘ ์ฒดํฌ๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด next button์„ disabled ์ฒ˜๋ฆฌํ•ด์ฃผ์—ˆ๋‹ค.

const checkPrimaryAccessTerms = () => {
    const { webAccessCheck, privateInfoCheck } = checkInfo;
    if (webAccessCheck && privateInfoCheck) return false;
    else return true;
  };

๋งˆ์ง€๋ง‰์œผ๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ๊ด‘๊ณ  ๋™์˜๋ฅผ ์ฒดํฌํ–ˆ์„ ๊ฒฝ์šฐ์—๋Š” ์„œ๋ฒ„๋กœ ๊ด‘๊ณ  ๋™์˜ ์—ฌ๋ถ€ ๊ฐ’์„ ๋„˜๊ฒจ์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— checkCurrentAdvertiseAccess ๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ Container Components์—์„œ props๋กœ ๋„˜๊ฒจ ๋ฐ›์•„ ๊ด‘๊ณ  ๋™์˜๊ฐ€ ์ฒดํฌ๊ฐ€ ๋˜์—ˆ์„ ๊ฒฝ์šฐ์— useEffect ๋‚ด์—์„œ ํ•ด๋‹น ๊ฐ’์ด ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Œ์„ ํ™•์ธํ•˜๊ณ  checkCurrentAdvertiseAccess ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด์ฃผ๋„๋ก ํ•˜์˜€๋‹ค.

 

ํ•ด๋‹น ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜๋ฉด ๊ด‘๊ณ  ์ฒดํฌ์— ๋Œ€ํ•œ true๊ฐ’์„ Auth store์— is_receive_email key์— ํ• ๋‹นํ•ด์ฃผ๋„๋ก ๋ฆฌ๋“€์„œ๋ฅผ ์ž‘์„ฑํ•˜์˜€๋‹ค.

// RegisterContainer
const checkCurrentAdvertiseAccess = useCallback(
    isCurrentAdvertiseAccess => {
      dispatch(setCurrentAdvertiseAccess(isCurrentAdvertiseAccess));
    },
    [dispatch]
  );

// AccessTermForm
useEffect(() => {
    checkCurrentAdvertiseAccess(advertiseCheck);
  }, [checkCurrentAdvertiseAccess, advertiseCheck]);

 

๋™์ž‘ ์˜์ƒ

๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
TAG
more
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ