Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/components/mover/detail/MoverDetailShare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useRef, useState } from "react";

import { Text } from "@/components/common/Text";
import { shareKakaoMoverCustom, toKakaoShareImageUrl } from "@/lib/kakao/share";
import { shareKakaoMoverCustom, toKakaoShareImageUrl, toKakaoSharePath } from "@/lib/kakao/share";
import { usePageShare } from "@/hooks/usePageShare";
import { ClipIcon } from "@/icons";
import { hasFacebookAppId } from "@/lib/facebook/share";
Expand Down Expand Up @@ -69,10 +69,18 @@ export default function MoverDetailShare({
kakaoSharingRef.current = true;
setIsKakaoSharing(true);
try {
const PATH = toKakaoSharePath();
await shareKakaoMoverCustom({
templateArgs: kakaoShare,
templateArgs: {
...kakaoShare,
PATH,
},
onMissingConfig: () => onToastMessage?.("카카오톡 공유 설정이 필요합니다."),
onError: (message) => onToastMessage?.(message),
});
} catch (error) {
const message = error instanceof Error ? error.message : "카카오톡 공유에 실패했습니다.";
onToastMessage?.(message);
} finally {
kakaoSharingRef.current = false;
setIsKakaoSharing(false);
Expand Down
15 changes: 15 additions & 0 deletions src/lib/kakao/share.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
buildKakaoShareImageUrl,
buildKakaoSharePath,
getKakaoJavascriptKey,
getMoverShareTemplateId,
hasKakaoJavascriptKey,
Expand Down Expand Up @@ -168,3 +169,17 @@ export function toKakaoShareImageUrl(src: string | null | undefined): string {
const origin = typeof window !== "undefined" ? window.location.origin : undefined;
return buildKakaoShareImageUrl(src, origin);
}

/** 클라이언트 현재 경로를 카카오 템플릿 ${PATH} 인자로 변환 */
export function toKakaoSharePath(): string {
if (typeof window === "undefined") {
throw new Error("카카오톡 공유 경로는 브라우저에서만 사용할 수 있습니다.");
}

const path = buildKakaoSharePath(window.location.pathname, window.location.search);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (!path) {
throw new Error("카카오톡 공유 경로를 확인할 수 없습니다.");
}

return path;
}
12 changes: 11 additions & 1 deletion src/lib/kakao/shareTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { DEFAULT_MOVER_PROFILE_IMAGE } from "@/lib/utils/moverProfileImage";

/** 기사님 상세 카카오톡 메시지 공유 템플릿 인자 */
/**
* 기사님 상세 카카오톡 메시지 공유 템플릿 인자
* PATH: 템플릿 링크 `https://도메인/${PATH}` 용 (앞 슬래시 없이, 예: movers/{id})
*/
export interface KakaoMoverShareTemplateArgs {
PATH: string;
driver_name: string;
like_count: string;
driver_profile: string;
}

/** 카카오 템플릿 ${PATH}용 — `/movers/1` → `movers/1` */
export function buildKakaoSharePath(pathname: string, search = ""): string {
const path = pathname.replace(/^\/+/, "");
return search ? `${path}${search}` : path;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

export function parseKakaoTemplateId(raw: string | undefined): number | null {
const trimmed = raw?.trim();
if (!trimmed) {
Expand Down