-
Notifications
You must be signed in to change notification settings - Fork 1
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
[ FEAT ] 카카오톡 공유하기 버튼 Component
- Loading branch information
Showing
9 changed files
with
125 additions
and
12 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// components/KakaoShareButton.tsx | ||
import { useEffect, useState } from "react"; | ||
import Button from "./Button"; | ||
|
||
interface KakaoShareButtonProps { | ||
senderName: string; | ||
letterId: string; | ||
} | ||
|
||
const KakaoShareButton: React.FC<KakaoShareButtonProps> = ({ | ||
senderName, | ||
letterId, | ||
}) => { | ||
const [isKakaoLoaded, setIsKakaoLoaded] = useState(false); | ||
const JS_KEY = process.env.NEXT_PUBLIC_JAVASCRIPT_KEY; | ||
|
||
useEffect(() => { | ||
if (!JS_KEY) { | ||
console.error("Kakao JavaScript key is missing"); | ||
return; | ||
} | ||
|
||
const script = document.createElement("script"); | ||
script.src = "https://developers.kakao.com/sdk/js/kakao.js"; | ||
script.async = true; | ||
|
||
script.onload = () => { | ||
if (window.Kakao && !window.Kakao.isInitialized()) { | ||
window.Kakao.init(JS_KEY); | ||
setIsKakaoLoaded(true); | ||
} | ||
}; | ||
|
||
document.body.appendChild(script); | ||
|
||
return () => { | ||
document.body.removeChild(script); | ||
}; | ||
}, [JS_KEY]); | ||
|
||
const shareToKakao = () => { | ||
const { Kakao, location } = window; | ||
|
||
if (!Kakao || !Kakao.isInitialized()) { | ||
console.error("Kakao is not initialized"); | ||
return; | ||
} | ||
|
||
// Kakao.Share.sendDefault({ | ||
// objectType: "feed", | ||
// content: { | ||
// title: "나만의 디지털 편지 아카이브, 레터링", | ||
// description: `${senderName} 님으로부터 한 통의 편지가 도착했습니다! 소중한 편지를 손쉽게 보관하고 나의 스페이스에 수놓아보세요!`, | ||
// imageUrl: imageAsset, | ||
// link: { | ||
// mobileWebUrl: location.href, | ||
// webUrl: location.href, | ||
// }, | ||
// }, | ||
// }); | ||
|
||
Kakao.Share.sendScrap({ | ||
// requestUrl: , | ||
requestUrl: location.origin + location.pathname, | ||
templateId: 112798, | ||
templateArgs: { | ||
senderName: senderName, | ||
id: letterId, | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Button | ||
buttonType="primary" | ||
text="카카오톡 공유하기" | ||
onClick={shareToKakao} | ||
/> | ||
); | ||
}; | ||
|
||
export default KakaoShareButton; |
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