Skip to content

Commit

Permalink
Fix: ModalEvent2023FallRandomBox
Browse files Browse the repository at this point in the history
  • Loading branch information
14KGun committed Sep 26, 2023
1 parent 0506f17 commit 5e475c8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
13 changes: 12 additions & 1 deletion src/components/ModalPopup/ModalEvent2023FallItemInstagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ type ModalEvent2023FallItemInstagramProps = { item?: EventItem } & Parameters<
typeof Modal
>[0];

const Background = () => (
<div css={{ position: "absolute", top: "20%", left: 0, bottom: 0, right: 0 }}>
<div className="c2023fallevent-before"></div>
<div className="c2023fallevent-after"></div>
</div>
);

const ModalEvent2023FallItemInstagram = ({
item,
...modalProps
Expand All @@ -43,7 +50,11 @@ const ModalEvent2023FallItemInstagram = ({
};

return (
<Modal padding="16px 12px 12px" {...modalProps}>
<Modal
padding="16px 12px 12px"
backgroundChildren={<Background />}
{...modalProps}
>
<div css={styleTitle}>
<ShareRoundedIcon style={styleIcon} />
인스타그램 스토리에 공유하기
Expand Down
36 changes: 25 additions & 11 deletions src/components/ModalPopup/ModalEvent2023FallRandomBox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { memo, useCallback, useEffect, useState } from "react";
import {
Dispatch,
SetStateAction,
memo,
useCallback,
useEffect,
useState,
} from "react";

import type { EventItem } from "types/event2023fall";

Expand All @@ -23,19 +30,29 @@ const Background = () => (
</div>
);

type ModalEvent2023FallRandomBoxProps = { item?: EventItem } & Parameters<
typeof Modal
>[0];
type ModalEvent2023FallRandomBoxProps = {
item?: EventItem;
setShareItem?: Dispatch<SetStateAction<Nullable<EventItem>>>;
} & Parameters<typeof Modal>[0];

const ModalEvent2023FallRandomBox = ({
item,
setShareItem,
...modalProps
}: ModalEvent2023FallRandomBoxProps) => {
const [isBoxOpend, setIsBoxOpend] = useState<boolean>(false);
const isDisplayRandomBox = !useDelayBoolean(!modalProps.isOpen, 500);
const isDisplayItemName = useDelay<boolean>(isBoxOpend, !isBoxOpend, 6000);
const onClickOk = useCallback(() => setIsBoxOpend(true), []);

const onChangeIsOpen = useCallback(
(isOpen: boolean) => {
if (!isOpen && item) setShareItem?.(item);
modalProps?.onChangeIsOpen?.(isOpen);
},
[item, setShareItem, modalProps]
);

useEffect(() => {
if (!modalProps.isOpen) setIsBoxOpend(false);
}, [modalProps.isOpen]);
Expand All @@ -58,10 +75,11 @@ const ModalEvent2023FallRandomBox = ({

return (
<Modal
{...modalProps}
css={{ padding: "16px 12px 12px", overflow: "hidden" }}
onEnter={onClickOk}
backgroundChildren={isBoxOpend ? <Background /> : undefined}
{...modalProps}
onEnter={onClickOk}
onChangeIsOpen={onChangeIsOpen}
>
<div css={styleTitle}>
<HelpCenterRoundedIcon style={styleIcon} />
Expand Down Expand Up @@ -102,11 +120,7 @@ const ModalEvent2023FallRandomBox = ({
...theme.font14_bold,
}}
disabled={isDisplayItemName ? false : isBoxOpend}
onClick={
isDisplayItemName
? () => modalProps?.onChangeIsOpen?.(false)
: onClickOk
}
onClick={isDisplayItemName ? () => onChangeIsOpen(false) : onClickOk}
>
{isDisplayItemName ? "확인" : "박스 열기"}
</Button>
Expand Down
1 change: 1 addition & 0 deletions src/pages/Event/Event2023FallStore/ItemListSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const EventItemContainer = ({ value, fetchItems }: EventItemComponentProps) => {
isOpen={!!rewardItem}
onChangeIsOpen={() => setRewardItem(null)}
item={rewardItem || undefined}
setShareItem={setShareItem}
/>
)}
<ModalEvent2023FallItemInstagram
Expand Down

0 comments on commit 5e475c8

Please sign in to comment.