-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#633 인스타그램 스토리 이동 이벤트 앱으로 전달
- Loading branch information
Showing
13 changed files
with
415 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/components/Link/LinkEvent2023FallInstagramStoryShare.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { HTMLAttributes, ReactNode, useCallback, useState } from "react"; | ||
|
||
import { useEvent2023FallQuestComplete } from "hooks/event/useEvent2023FallQuestComplete"; | ||
import { sendPopupInstagramStoryShareToFlutter } from "hooks/skeleton/useFlutterEventCommunicationEffect"; | ||
import { useValueRecoilState } from "hooks/useFetchRecoilState"; | ||
import { useAxios } from "hooks/useTaxiAPI"; | ||
|
||
import ModalEvent2023FallJoin from "components/ModalPopup/ModalEvent2023FallJoin"; | ||
|
||
import alertAtom from "atoms/alert"; | ||
import { useSetRecoilState } from "recoil"; | ||
|
||
import { deviceType } from "tools/loadenv"; | ||
|
||
const backgroundLayerDefaultUrl = | ||
"https://sparcs-taxi-prod.s3.ap-northeast-2.amazonaws.com/assets/event-2023fall/instagram_background.png"; | ||
const stickerLayerDefaultUrl = | ||
"https://sparcs-taxi-prod.s3.ap-northeast-2.amazonaws.com/assets/event-2023fall/instagram_sticker.png"; | ||
|
||
type LinkEvent2023FallInstagramStoryShareProps = { | ||
type: "eventSharingOnInstagram" | "purchaseSharingOnInstagram"; | ||
backgroundLayerUrl?: string; | ||
stickerLayerUrl?: string; | ||
children?: ReactNode; | ||
} & HTMLAttributes<HTMLAnchorElement>; | ||
|
||
const LinkEvent2023FallInstagramStoryShare = ({ | ||
type, | ||
backgroundLayerUrl = backgroundLayerDefaultUrl, | ||
stickerLayerUrl = stickerLayerDefaultUrl, | ||
children, | ||
...aProps | ||
}: LinkEvent2023FallInstagramStoryShareProps) => { | ||
const axios = useAxios(); | ||
const setAlert = useSetRecoilState(alertAtom); | ||
const isLogin = !!useValueRecoilState("loginInfo")?.id; | ||
const { isAgreeOnTermsOfEvent } = | ||
useValueRecoilState("event2023FallInfo") || {}; | ||
const [isOpenJoin, setIsOpenJoin] = useState<boolean>(false); | ||
|
||
//#region event2023Fall | ||
const event2023FallQuestComplete = useEvent2023FallQuestComplete(); | ||
//#endregion | ||
|
||
const onClick = useCallback(async () => { | ||
if (!deviceType.startsWith("app/")) { | ||
setAlert("앱에서만 이용 가능합니다."); | ||
} else if (!isLogin) { | ||
setAlert("로그인 이후 이용해주세요."); | ||
} else if (!isAgreeOnTermsOfEvent) { | ||
setIsOpenJoin(true); | ||
} else { | ||
const result = await sendPopupInstagramStoryShareToFlutter({ | ||
backgroundLayerUrl, | ||
stickerLayerUrl, | ||
}); | ||
if (!result) { | ||
setAlert("인스타그램 실행에 실패하였습니다."); | ||
return; | ||
} | ||
axios({ | ||
url: `/events/2023fall/quests/complete/${type}`, | ||
method: "post", | ||
onSuccess: () => { | ||
//#region event2023Fall | ||
event2023FallQuestComplete(type); | ||
//#endregion | ||
}, | ||
}); | ||
} | ||
}, [ | ||
isLogin, | ||
isAgreeOnTermsOfEvent, | ||
backgroundLayerUrl, | ||
stickerLayerUrl, | ||
event2023FallQuestComplete, | ||
]); | ||
|
||
return ( | ||
<> | ||
<a onClick={onClick} css={{ textDecoration: "none" }} {...aProps}> | ||
{children} | ||
</a> | ||
<ModalEvent2023FallJoin | ||
isOpen={isOpenJoin} | ||
onChangeIsOpen={setIsOpenJoin} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default LinkEvent2023FallInstagramStoryShare; |
Oops, something went wrong.