Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Download all the stats in pdf for admin successfully Issue 501 #530

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions admin/src/components/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,36 @@ import { FaRegComments } from "react-icons/fa";
import GoogleTranslate from './GoogleTranslate';
import { RiHeartsLine } from "react-icons/ri";
import { VscReactions } from "react-icons/vsc";
import { TbReportAnalytics } from "react-icons/tb";
import { tokenState } from '../store/atoms/auth';
import { useRecoilValue } from 'recoil';
import axios from 'axios';

const SideBar = ({ sidebarOpen, toggleSidebar }: { sidebarOpen: boolean, toggleSidebar: () => void }) => {
const location = useLocation();
const token = useRecoilValue(tokenState);

const downloadReport = async () => {
try {
const response = await axios.get('/api/v1/admin/downloadReport', {
headers: {
Authorization: `Bearer ${token}`,
},
responseType: 'blob',
});

const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'StyleShare_Report.pdf');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
console.error('Error downloading the report:', error);
}
};


const linkClasses = (path: string) =>
`mb-2 flex items-center py-2.5 px-4 rounded-lg transition duration-200 ${location.pathname === path ? 'bg-sky-500' : 'hover:bg-sky-500'}`;
Expand All @@ -40,6 +67,9 @@ const SideBar = ({ sidebarOpen, toggleSidebar }: { sidebarOpen: boolean, toggleS
<Link to="/admin/favorites" className={linkClasses('/admin/favorites')}><RiHeartsLine size={23} className='mr-3'/>Favorites</Link>
<Link to="/admin/reactions" className={linkClasses('/admin/reactions')}><VscReactions size={23} className='mr-3'/>Reactions</Link>
<Link to="/admin/statistics" className={linkClasses('/admin/statistics')}><VscGraphScatter size={23} className='mr-3'/>Statistics</Link>
<button onClick={downloadReport} className="w-full mb-2 flex items-center py-2.5 px-4 rounded-lg transition duration-200 bg-yellow-500 hover:bg-yellow-600"><TbReportAnalytics size={23} className='mr-3'/>
Download Report
</button>
</nav>
</div>
);
Expand Down
Loading
Loading