Open SeonHyungJo opened 3 years ago
type ShareData = {
title?: string;
text?: string;
url?: string;
files?: File[];
};
interface WebShareAPIProps {
shareData: ShareData;
copyData: string;
children?: string | ReactElement | Array<string | ReactElement>;
errorDispatch: (httpMethod: string, errOccurUrl: string, errOccurData: any, responseErr: any) => Promise<any>
}
export const WebShareAPI = ({ children, errorDispatch, shareData, copyData }: WebShareAPIProps): ReactElement => {
const [token] = useCookie(ZARITALK_TOKEN, '');
const [copied, setCopied, copy] = useCopyToClipboard(copyData);
const onShared = useCallback(() => {
if (navigator.share) {
navigator.share(shareData).then(() => {
sendActivityLog(ActionType.WEB_SHARE_API_FREE_TICKET, token, JSON.stringify(shareData)).then();
}).catch((err) => {
errorDispatch('GET', '/web/share', err, err).then();
});
} else {
sendActivityLog(ActionType.WEB_SHARE_API_FREE_TICKET, token, JSON.stringify(shareData)).then();
// @ts-ignore
copy();
}
}, [shareData]);
return (
<>
<section className={'z-web-share'} onClick={onShared}>
{children}
</section>
</>
);
};
Web Share API