Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 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 @@ -70,7 +70,11 @@ export default function MoverDetailShare({
setIsKakaoSharing(true);
try {
await shareKakaoMoverCustom({
templateArgs: kakaoShare,
templateArgs: {
...kakaoShare,
PATH: toKakaoSharePath(),
},
onMissingConfig: () => onToastMessage?.("카카오톡 공유 설정이 필요합니다."),
onError: (message) => onToastMessage?.(message),
});
} finally {
Expand Down
9 changes: 9 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,11 @@ 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") {
return "";
Comment thread
yooseohyeon marked this conversation as resolved.
Resolved
}
return buildKakaoSharePath(window.location.pathname, window.location.search);
}
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.
Resolved
}

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