Skip to content

Commit dabde5b

Browse files
authored
안드로이드 등에서 복사가 되지 않는 문제 수정 (#421)
* chore: react-copy-to-clipboard 라이브러리 추가 * feat: copy link 컴포넌트 만들고 적용 * feat: 제거 - SurveyIdLoaded * feat: 클립보드 로직 변경 * refactor: 사용하지 않는 부분 제거
1 parent 97282a7 commit dabde5b

13 files changed

+167
-50
lines changed

.pnp.cjs

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"@types/mixpanel-browser": "^2.38.1",
8888
"@types/node": "18.15.11",
8989
"@types/react": "18.0.35",
90+
"@types/react-copy-to-clipboard": "^5",
9091
"@types/react-dom": "18.0.11",
9192
"@types/testing-library__jest-dom": "^5",
9293
"@typescript-eslint/eslint-plugin": "^5.58.0",
@@ -114,6 +115,7 @@
114115
"postcss": "^8.4.21",
115116
"postcss-syntax": "^0.36.2",
116117
"prettier": "^2.8.7",
118+
"react-copy-to-clipboard": "^5.1.0",
117119
"storybook": "^7.0.6",
118120
"styled-jsx": "^5.1.2",
119121
"stylelint": "^15.10.1",

src/components/copyLink/CopyLink.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { type PropsWithChildren } from 'react';
2+
import { CopyToClipboard } from 'react-copy-to-clipboard';
3+
4+
import { BASE_URL } from '~/constants/url';
5+
6+
interface Props {
7+
copyText: string;
8+
onCopy: () => void;
9+
}
10+
11+
const CopyLink = ({ copyText, children, onCopy }: PropsWithChildren<Props>) => {
12+
return (
13+
<CopyToClipboard text={copyToClipBoardWithHostUrl(copyText)} onCopy={onCopy}>
14+
{children}
15+
</CopyToClipboard>
16+
);
17+
};
18+
19+
export default CopyLink;
20+
21+
const copyToClipBoardWithHostUrl = (path: string) => {
22+
if (typeof window === 'undefined') {
23+
return `${BASE_URL}${path}`;
24+
} else {
25+
const { host } = window.location;
26+
27+
return `${host}${path}`;
28+
}
29+
};

src/features/dna/DnaCta.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { useRouter } from 'next/router';
33
import { css, type Theme } from '@emotion/react';
44

55
import CTAButton from '~/components/button/CTAButton';
6+
import CopyLink from '~/components/copyLink/CopyLink';
67
import useToast from '~/components/toast/useToast';
78
import type useGetUserInfoBySurveyId from '~/hooks/api/user/useGetUserInfoBySurveyId';
89
import { type DnaOwnerStatus } from '~/pages/dna/type';
9-
import { copyToClipBoardWithHost } from '~/utils/clipboard';
1010
import recordEvent from '~/utils/event';
1111

1212
interface Props {
@@ -19,10 +19,8 @@ const DnaCta: FC<Props> = ({ surveyId, dnaOwnerStatus, userInfo }) => {
1919
const router = useRouter();
2020
const { fireToast } = useToast();
2121

22-
const onClickCopyCTA = () => {
22+
const onClickLink = () => {
2323
recordEvent({ action: 'DNA 페이지 - 커리어 명함 링크 복사 클릭' });
24-
25-
copyToClipBoardWithHost(`/dna/${surveyId}`);
2624
fireToast({ content: `${userInfo?.nickname}님의 커리어 명함 링크가 복사되었어요`, higherThanCTA: true });
2725
};
2826

@@ -35,7 +33,9 @@ const DnaCta: FC<Props> = ({ surveyId, dnaOwnerStatus, userInfo }) => {
3533
if (dnaOwnerStatus === 'current_user')
3634
return (
3735
<div css={wrapperCss}>
38-
<CTAButton onClick={onClickCopyCTA}>공유하기</CTAButton>
36+
<CopyLink copyText={`/dna/${surveyId}`} onCopy={onClickLink}>
37+
<CTAButton>공유하기</CTAButton>
38+
</CopyLink>
3939
</div>
4040
);
4141

src/features/feedback/NewFeedbackCopyButton.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { css, type Theme } from '@emotion/react';
22

3+
import CopyLink from '~/components/copyLink/CopyLink';
34
import LinkIcon from '~/components/icons/LinkIcon';
45
import Toast from '~/components/toast/Toast';
56
import useToast from '~/components/toast/useToast';
67
import { HEAD_2_BOLD } from '~/styles/typo';
7-
import { copyToClipBoardWithHost } from '~/utils/clipboard';
88

99
interface Props {
1010
surveyId: string;
@@ -13,27 +13,29 @@ interface Props {
1313
const NewFeedbackCopyButton = ({ surveyId }: Props) => {
1414
const { fireToast } = useToast();
1515

16-
const onClick = () => {
17-
copyToClipBoardWithHost(`/review/${surveyId}`);
18-
16+
const onCopyLink = () => {
1917
fireToast({
2018
content: (
2119
<>
2220
<LinkIcon />
2321
<Toast.Text>나의 질문 폼 링크가 복사되었어요</Toast.Text>
2422
</>
2523
),
24+
higherThanCTA: true,
2625
});
2726
};
2827

2928
return (
30-
<button type="button" css={buttonCss} onClick={onClick}>
31-
<span css={titleCss}>나의 질문 폼 링크 공유하기</span>
32-
<span css={spanCss}>
33-
<LinkIcon fill="#677089" width={14} height={14} viewBox="0 0 24 24" />
34-
질문 폼 복사
35-
</span>
36-
</button>
29+
<CopyLink copyText={`/review/${surveyId}`} onCopy={onCopyLink}>
30+
<button type="button" css={buttonCss}>
31+
<span css={titleCss}>나의 질문 폼 링크 공유하기</span>
32+
33+
<span css={spanCss}>
34+
<LinkIcon fill="#677089" width={14} height={14} viewBox="0 0 24 24" />
35+
질문 폼 복사
36+
</span>
37+
</button>
38+
</CopyLink>
3739
);
3840
};
3941

src/pages/result/SurveyIdLoaded.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { m, type Variants } from 'framer-motion';
55

66
import BottomSheet from '~/components/bottomSheet/BottomSheet';
77
import CTAButton from '~/components/button/CTAButton';
8+
import CopyLink from '~/components/copyLink/CopyLink';
89
import Softskill from '~/components/graphic/softskills/Softskill';
910
import { type Softskills } from '~/components/graphic/softskills/type';
1011
import Header from '~/components/header/Header';
@@ -34,7 +35,6 @@ import useBoolean from '~/hooks/common/useBoolean';
3435
import useScrollLock from '~/hooks/common/useScrollLock';
3536
import { useScrollSpy } from '~/hooks/common/useScrollSpy';
3637
import { BODY_2_REGULAR, HEAD_1, HEAD_2_BOLD } from '~/styles/typo';
37-
import { copyToClipBoardWithHost } from '~/utils/clipboard';
3838

3939
interface Props {
4040
surveyId: string;
@@ -43,12 +43,13 @@ interface Props {
4343
const PILL_COLORS: Color[] = ['bluegreen', 'pink', 'skyblue', 'yellowgreen', 'purple'];
4444

4545
const SurveyIdLoaded = ({ surveyId }: Props) => {
46+
const { fireToast } = useToast();
47+
4648
const { isLoading: isFeedbackSummaryLoading, data: feedbackSummaryData } = useGetFeedbackSummaryBySurveyId(surveyId);
4749
const { isLoading: isReviewersSummaryLoading, data: reviewersSummaryData } =
4850
useGetReviewersSummaryBySurveyId(surveyId);
4951
const { isLoading: isAllDataLoading, data: allData } = useGetAllFeedbacksBySurveyId(surveyId);
5052
const tendencyCountData = getTendencyCount(allData);
51-
const { fireToast } = useToast();
5253

5354
const [isShowing, toggle, _, setFalse] = useBoolean(false);
5455
useScrollLock({ lock: isShowing });
@@ -63,9 +64,11 @@ const SurveyIdLoaded = ({ surveyId }: Props) => {
6364
setInnerWidth(limittedInnerWidth);
6465
}, []);
6566

66-
const onClickCTA = () => {
67-
copyToClipBoardWithHost(`/review/${surveyId}`);
67+
const moveToTop = () => {
68+
window.scrollTo({ top: 0, behavior: 'smooth' });
69+
};
6870

71+
const onCopyLink = () => {
6972
fireToast({
7073
content: (
7174
<>
@@ -77,10 +80,6 @@ const SurveyIdLoaded = ({ surveyId }: Props) => {
7780
});
7881
};
7982

80-
const moveToTop = () => {
81-
window.scrollTo({ top: 0, behavior: 'smooth' });
82-
};
83-
8483
if (feedbackSummaryData && feedbackSummaryData.all_feedback_count < 1) {
8584
return (
8685
<>
@@ -95,9 +94,9 @@ const SurveyIdLoaded = ({ surveyId }: Props) => {
9594
<m.span css={bubbleSpanCss} variants={bubbleVariants}>
9695
더 많은 동료들에게 질문 폼 링크를 공유해 보세요!
9796
</m.span>
98-
<CTAButton onClick={onClickCTA} color="blue">
99-
공유하기
100-
</CTAButton>
97+
<CopyLink copyText={`/review/${surveyId}`} onCopy={onCopyLink}>
98+
<CTAButton color="blue">공유하기</CTAButton>
99+
</CopyLink>
101100
</m.div>
102101
</>
103102
);

src/pages/survey/link.page.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { useEffect } from 'react';
12
import Image from 'next/image';
23
import { css, type Theme } from '@emotion/react';
34
import { m } from 'framer-motion';
45

56
import CTAButton from '~/components/button/CTAButton';
7+
import CopyLink from '~/components/copyLink/CopyLink';
68
import LinkIcon from '~/components/icons/LinkIcon';
79
import SEO from '~/components/SEO/SEO';
810
import StaggerWrapper from '~/components/stagger/StaggerWrapper';
@@ -11,24 +13,23 @@ import useToast from '~/components/toast/useToast';
1113
import { fixedBottomCss } from '~/features/review/style';
1214
import { CTAVariants, fixedContainerCss } from '~/features/survey/styles';
1315
import useInternalRouter from '~/hooks/router/useInternalRouter';
14-
import { copyToClipBoardWithHost } from '~/utils/clipboard';
1516

1617
const SurveyLinkPage = () => {
1718
const { fireToast } = useToast();
1819
const router = useInternalRouter();
20+
const id = router.query.id;
1921

20-
const onNext = () => {
22+
useEffect(() => {
2123
if (!router.isReady) {
22-
throw new Error('잠시만 기다려주세요. ');
24+
return;
2325
}
24-
const id = router.query.id;
2526

2627
if (!id) {
2728
throw new Error('잘못된 경로입니다.\nsurveyId가 없습니다.');
2829
}
30+
}, [id, router]);
2931

30-
copyToClipBoardWithHost(`/review/${id}`);
31-
32+
const onCopyLink = () => {
3233
fireToast({
3334
content: (
3435
<>
@@ -58,9 +59,11 @@ const SurveyLinkPage = () => {
5859
</StaggerWrapper>
5960

6061
<m.div css={fixedBottomCss} variants={CTAVariants} initial="initial" animate="animate" exit="exit">
61-
<CTAButton color="blue" onClick={onNext}>
62-
질문 폼 공유하기
63-
</CTAButton>
62+
<CopyLink copyText={`/review/${id}`} onCopy={onCopyLink}>
63+
<CTAButton color="blue" disabled={!id}>
64+
질문 폼 공유하기
65+
</CTAButton>
66+
</CopyLink>
6467
</m.div>
6568
</main>
6669
</>

src/utils/clipboard.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)