publishers try ex cel export (wip)

This commit is contained in:
Dobromir Popov
2024-09-14 19:03:48 +03:00
parent 51544873dd
commit ed3222a428
3 changed files with 67 additions and 5 deletions

View File

@ -16,7 +16,7 @@ import ProtectedRoute from '../../../components/protectedRoute';
import ConfirmationModal from '../../../components/ConfirmationModal';
import { relative } from "path";
import { set } from "lodash";
import { excel } from "../../../src/helpers/excel";
interface IProps {
@ -172,6 +172,14 @@ function PublishersPage({ publishers = [] }: IProps) {
}
};
const exportPublishers = async () => {
try {
await excel.ExportPublishersToExcel();
} catch (error) {
console.error(JSON.stringify(error));
}
}
return (
<Layout>
<ProtectedRoute allowedRoles={[UserRole.ADMIN, UserRole.POWERUSER]}>
@ -204,8 +212,13 @@ function PublishersPage({ publishers = [] }: IProps) {
<div className="flex justify-center m-4">
<a href="/cart/publishers/import" className="btn">Import publishers</a>
</div>
{/* export by calling excel helper .ExportPublishersToExcel() */}
<div className="flex justify-center m-4">
<button className="btn" onClick={exportPublishers}>Export to Excel</button>
</div>
</div>
<div className="z-60 sticky top-0" style={{ zIndex: 60, position: relative }}>
<div name="filters" className="flex items-center justify-center space-x-4 m-4 bg-gray-100 p-2" >
<label htmlFor="filter">Filter:</label>
@ -245,12 +258,12 @@ function PublishersPage({ publishers = [] }: IProps) {
export default PublishersPage;
//import { set } from "date-fns";
//import {set} from "date-fns";
export const getServerSideProps = async (context) => {
// const axios = await axiosServer(context);
// //ToDo: refactor all axios calls to use axiosInstance and this URL
// const { data: publishers } = await axios.get('/api/data/publishers?select=id,firstName,lastName,email,isActive,isTrained,isImported,assignments.shift.startTime,availabilities.startTime&dev=fromuseefect');
// const {data: publishers } = await axios.get('/api/data/publishers?select=id,firstName,lastName,email,isActive,isTrained,isImported,assignments.shift.startTime,availabilities.startTime&dev=fromuseefect');
//use prisma instead of axios
const prisma = common.getPrismaClient();
let publishers = await prisma.publisher.findMany({