Skip to content

Commit

Permalink
feat: 회의 생성페이지 webShare api
Browse files Browse the repository at this point in the history
  • Loading branch information
ljh0608 committed Sep 2, 2024
1 parent 662d48d commit 198fcaa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 28 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;
37 changes: 10 additions & 27 deletions src/components/common/moleculesComponents/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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';

Expand All @@ -23,6 +23,10 @@ interface HeaderProps {

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

const {inviteURL, handleWebShare} = useShareLink();

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

const { meetingId } = useParams();

const shareData = {
title: "ASAP",
text: "회의 시간을 입력해주세요",
url: `${import.meta.env.VITE_WEB_IP}/meet/${meetingId}`,
};

const handleWebShare=async()=>{
// if (navigator.share && navigator.canShare(shareData)) {
// console.log("test");
try{
await navigator.share(shareData);
}
catch(err){
alert(err + "지원하지 않는 브라우저");
}
// } else {
// alert("out");
// }
//test

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

<CopyToClipboard text={ position==="cueCard" ? `${import.meta.env.VITE_WEB_IP}/q-card/${meetingId}`:inviteURL }>
<LinkIc/>
</CopyToClipboard>
</IconSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ function PriorityDropdown() {
return updatedInput;
});
};
//test
return (
<PriorityDropdownWrapper>
{isOpenDropDown.map((item, idx) => (
Expand Down

0 comments on commit 198fcaa

Please sign in to comment.