Skip to content

Commit

Permalink
Merge pull request #331 from ASAP-as-soon-as-possible/feat/#325/webSh…
Browse files Browse the repository at this point in the history
…areAPI

[Feat/#325] web Share api 배포본 테스트
  • Loading branch information
ljh0608 authored Sep 2, 2024
2 parents e76e291 + 198fcaa commit f940860
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
34 changes: 34 additions & 0 deletions src/hooks/useShareLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useParams } from 'react-router-dom';
import { notify } from 'utils/toast/copyLinkToast';

const useShareLink = () => {
const { meetingId } = useParams();

const inviteURL = `${window.location.origin}/meet/${meetingId}`;
const shareData = {
title: 'ASAP',
text: '회의 시간을 입력해주세요',
url: inviteURL,
};

const handleCopyToClipboard = async () => {
try {
await navigator.clipboard.writeText(inviteURL);
notify();
} catch {
alert('링크복사에 실패했습니다. \n 다시 시도해주세요.');
}
};

const handleWebShare = async () => {
if (navigator.share) {
navigator.share(shareData);
} else {
handleCopyToClipboard();
}
};

return { inviteURL, handleCopyToClipboard, handleWebShare };
};

export default useShareLink;
18 changes: 12 additions & 6 deletions src/components/common/moleculesComponents/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { BackIc, ExitIc, HambergerIc, LinkIc, MainLogoIc } from 'components/Icon
import { useScheduleStepContext } from 'pages/selectSchedule/contexts/useScheduleStepContext';
import { ScheduleStepType } from 'pages/selectSchedule/types';
import CopyToClipboard from 'react-copy-to-clipboard';
import { useParams } from 'react-router';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import useShareLink from 'src/\bhooks/useShareLink';
import styled from 'styled-components';
import { theme } from 'styles/theme';
import { notify } from 'utils/toast/copyLinkToast';

import Navigation from './Navigation';

Expand All @@ -21,8 +20,13 @@ interface HeaderProps {
setSelectScheduleStep?: Dispatch<SetStateAction<ScheduleStepType>>;
}


function Header({ position, setFunnelStep }: HeaderProps) {
const { scheduleStep, setScheduleStep } = useScheduleStepContext();
const { meetingId } = useParams();

const {inviteURL, handleWebShare} = useShareLink();

const navigationOptions = [
{
title: '회의 일정 정하기',
Expand Down Expand Up @@ -57,8 +61,8 @@ function Header({ position, setFunnelStep }: HeaderProps) {
}
}
};
console.log(window.location.origin);

const { meetingId } = useParams();
return (
<>
<HeaderWrapper>
Expand Down Expand Up @@ -106,8 +110,10 @@ function Header({ position, setFunnelStep }: HeaderProps) {
<IconWrapper>
{(position==="completeCreateMeeting" || position==="cueCard" || position==="confirmMeet") &&
<LinkIcWrapper>
<IconSection onClick={notify}>
<CopyToClipboard text={ position==="cueCard" ? `${import.meta.env.VITE_WEB_IP}/q-card/${meetingId}`:`${import.meta.env.VITE_WEB_IP}/meet/${meetingId}` }>
{/* <IconSection onClick={notify}> */}
<IconSection onClick={handleWebShare}>

<CopyToClipboard text={ position==="cueCard" ? `${import.meta.env.VITE_WEB_IP}/q-card/${meetingId}`:inviteURL }>
<LinkIc/>
</CopyToClipboard>
</IconSection>
Expand Down
3 changes: 2 additions & 1 deletion src/utils/toast/ToastContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default ToastContainerBox;
const StyledToastContainer = styled(ToastContainer)`
display: flex;
position: absolute;
bottom: 6rem;
bottom: 5rem;
height: 10rem;
align-items: center;
justify-content: center;
overflow: hidden;
Expand Down

0 comments on commit f940860

Please sign in to comment.