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 all 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
27 changes: 27 additions & 0 deletions admin/src/components/NewPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useRecoilValue } from "recoil";
import { tokenState } from "../store/atoms/auth";
import { Link } from "react-router-dom";
import { ColorRing } from 'react-loader-spinner';
import { TbReportAnalytics } from "react-icons/tb";

const NewPosts = () => {
const [posts, setposts] = useState<IPost[]>([]);
Expand All @@ -27,6 +28,27 @@ const NewPosts = () => {
}
};

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);
}
};

useEffect(() => {
fetchPost();
}, []);
Expand Down Expand Up @@ -89,6 +111,11 @@ const NewPosts = () => {
</tbody>
</table>
</div>
<div className="lg:mx-24 mx-10 lg:mr-11 mt-5 overflow-x-auto rounded-xl mb-5">
<button onClick={downloadReport} className="flex items-center py-2.5 px-4 rounded-lg transition duration-200 bg-yellow-500 hover:bg-yellow-600 text-gray-100"><TbReportAnalytics size={23} className='mr-3'/>
Download Report
</button>
</div>
</>
}
</div>
Expand Down
Loading
Loading