// @ts-ignore import React, { useMemo, useState } from 'react'; import { FileDownloadOutlined, Share } from '@mui/icons-material'; import { toast } from 'react-hot-toast'; import { CircularProgress, Divider } from '@mui/material'; import { useColorPalates } from '@samagra-x/stencil-hooks'; import { useUiConfig } from '@samagra-x/stencil-hooks'; const ShareButtons = () => { const config = useUiConfig('component', 'shareButton'); const theme = useColorPalates(); // @ts-ignore const secondaryColor = useMemo(() => { return theme?.primary?.light; }, [theme?.primary?.light]); const primaryColor = useMemo(() => { return theme?.primary?.main; }, [theme?.primary?.main]); const [shareLoader, setShareLoader] = useState(false); const [downloadLoader, setDownloadLoader] = useState(false); // @ts-ignore const downloadChat = async (type: string) => { // perform your download chat logic here }; const downloadShareHandler = async (type: string) => { try { if (type === 'download') { setDownloadLoader(true); } else { setShareLoader(true); } if (type === 'download') { setDownloadLoader(false); setTimeout(() => { toast.success('Downloading...'); }, 2000); } else if (type === 'share') { setShareLoader(false); setTimeout(() => { toast.success('Share successful'); }, 2000); } else { toast.error("Your system doesn't support sharing this file."); setDownloadLoader(false); setShareLoader(false); } } catch (error: any) { setDownloadLoader(false); setShareLoader(false); toast.error('Error while performing'); } }; return ( <> {(config?.allowDownloadChat || config?.allowShareChat) && (
{config?.allowShareChat && (
downloadShareHandler('share')} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', cursor: 'pointer', }} > {shareLoader ? (
) : (
)}

Share

)} {/* Only render divider when both share and download allowed */} {config?.allowDownloadChat && config?.allowShareChat && } {config?.allowDownloadChat && (
downloadShareHandler('download')} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', cursor: 'pointer', }} > {/* Download */} {downloadLoader ? (
) : (
)}

Download

)}
)} ); }; export default ShareButtons; type ShareButtonProps = { allowDownloadChat?: boolean; handleShareButton?: () => void; allowShareChat?: boolean; shareLoader?: boolean; downloadLoader?: boolean; handleDownloadButton?: () => void; style?: { container?: object; button?: object; icon?: object; text?: object; divider?: object; }; }; const NewShareButtons: React.FC = ({ allowDownloadChat = false, handleShareButton, allowShareChat = false, handleDownloadButton, shareLoader, downloadLoader, style = {}, }) => { const theme = useColorPalates(); const primaryColor = useMemo(() => { return theme?.primary?.main; }, [theme?.primary?.main]); return ( <> {(allowDownloadChat || allowShareChat) && (
{allowShareChat && (
{shareLoader ? (
) : (
)}

Share

)} {/* Only render divider when both share and download allowed */} {allowDownloadChat && allowShareChat && ( )} {allowDownloadChat && (
{/* Download */} {downloadLoader ? (
) : (
)}

Download

)}
)} ); }; export { NewShareButtons };