initial commit - code moved to separate repo
This commit is contained in:
46
pages/cart/reports/experience.tsx
Normal file
46
pages/cart/reports/experience.tsx
Normal file
@ -0,0 +1,46 @@
|
||||
//next.js page to show all locatons in the database with a link to the location page
|
||||
// import axios from "axios";
|
||||
import { Location, UserRole } from "@prisma/client";
|
||||
import Layout from "../../../components/layout";
|
||||
import ExperienceForm from "../../../components/reports/ExperienceForm";
|
||||
import axiosInstance from '../../../src/axiosSecure';
|
||||
import ProtectedRoute from '../../../components/protectedRoute';
|
||||
|
||||
function NewPage(loc: Location) {
|
||||
return (
|
||||
<Layout>
|
||||
<ProtectedRoute allowedRoles={[UserRole.POWERUSER, UserRole.ADMIN, UserRole.USER, UserRole.EXTERNAL]}>
|
||||
<div className="h-5/6 grid place-items-center">
|
||||
<ExperienceForm />
|
||||
</div></ProtectedRoute>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
export default NewPage;
|
||||
|
||||
//------------------pages\cart\locations\edit\[id].tsx------------------
|
||||
|
||||
export const getServerSideProps = async (context) => {
|
||||
return {
|
||||
props: {}
|
||||
};
|
||||
//if query is undefined, then it is a new location
|
||||
// if (context.query.id === undefined) {
|
||||
// return {
|
||||
// props: {}
|
||||
// };
|
||||
// }
|
||||
// const { data: loc } = await axiosInstance.get(
|
||||
// `${process.env.NEXTAUTH_URL}api/data/locations/` + context.params.id
|
||||
// );
|
||||
|
||||
// console.log(location) //this is the location object
|
||||
// context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
|
||||
// return {
|
||||
// props: {
|
||||
// location: loc,
|
||||
|
||||
// },
|
||||
// };
|
||||
};
|
130
pages/cart/reports/list.tsx
Normal file
130
pages/cart/reports/list.tsx
Normal file
@ -0,0 +1,130 @@
|
||||
//page to show all repots in the database with a link to the report page
|
||||
import axiosInstance from '../../../src/axiosSecure';
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useRouter } from "next/router";
|
||||
import Link from "next/link";
|
||||
import { useSession } from "next-auth/react"
|
||||
//const common = require('src/helpers/common');
|
||||
import common from '../../../src/helpers/common';
|
||||
import Layout from "../../../components/layout";
|
||||
import ProtectedRoute from '../../../components/protectedRoute';
|
||||
import { Location, UserRole } from "@prisma/client";
|
||||
|
||||
|
||||
export default function Reports() {
|
||||
const [reports, setReports] = useState([]);
|
||||
const router = useRouter();
|
||||
const { data: session } = useSession();
|
||||
|
||||
|
||||
|
||||
|
||||
const deleteReport = (id) => {
|
||||
axiosInstance
|
||||
.delete(`api/data/reports/${id}`)
|
||||
.then((res) => {
|
||||
toast.success("Успешно изтрит отчет");
|
||||
// router.push("/cart/reports/list");
|
||||
setReports(reports.filter(report => report.id !== id));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
const [locations, setLocations] = useState([]);
|
||||
useEffect(() => {
|
||||
const fetchLocations = async () => {
|
||||
try {
|
||||
console.log("fetching locations");
|
||||
const { data } = await axiosInstance.get("/api/data/locations");
|
||||
setLocations(data);
|
||||
console.log(data);
|
||||
axiosInstance.get(`api/data/reports`)
|
||||
.then((res) => {
|
||||
let reports = res.data;
|
||||
reports.forEach((report) => {
|
||||
report.location = data.find((loc) => loc.id === report.locationId);
|
||||
});
|
||||
setReports(res.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
if (!locations.length) {
|
||||
fetchLocations();
|
||||
}
|
||||
}, []);
|
||||
return (
|
||||
<Layout>
|
||||
<ProtectedRoute allowedRoles={[UserRole.POWERUSER, UserRole.ADMIN, UserRole.USER, UserRole.EXTERNAL]}>
|
||||
|
||||
<div className="h-5/6 grid place-items-center">
|
||||
<div className="flex flex-col w-full px-4">
|
||||
<h1 className="text-2xl font-bold text-center">Отчети</h1>
|
||||
<Link href="/cart/reports/report">
|
||||
<button className="mt-4 bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
|
||||
Добави нов отчет
|
||||
</button>
|
||||
</Link>
|
||||
<div className="mt-4 w-full overflow-x-auto">
|
||||
<table className="w-full table-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="px-4 py-2 text-left">Дата</th>
|
||||
<th className="px-4 py-2 text-left" >Място</th>
|
||||
<th className="px-4 py-2 text-left">Отчет</th>
|
||||
<th className="px-4 py-2 text-left">Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{reports.map((report) => (
|
||||
<tr key={report.id}>
|
||||
<td className="border px-4 py-2">{common.getDateFormated(new Date(report.date))}</td>
|
||||
<td className="border px-4 py-2">{report.location?.name}</td>
|
||||
<td className="border px-4 py-2">
|
||||
{(report.experienceInfo === null || report.experienceInfo === "")
|
||||
? (
|
||||
<>
|
||||
<div><strong>Отчет</strong></div>
|
||||
Издания: {report.placementCount} <br />
|
||||
Разговори: {report.conversationCount} <br />
|
||||
Клипове: {report.videoCount} <br />
|
||||
Адреси / Телефони: {report.returnVisitInfoCount} <br />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div><strong>Случка</strong></div>
|
||||
<div dangerouslySetInnerHTML={{ __html: report.experienceInfo }} />
|
||||
</>
|
||||
)}
|
||||
</td>
|
||||
<td className="border px-4 py-2">
|
||||
|
||||
<button
|
||||
className="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded"
|
||||
onClick={() => deleteReport(report.id)}
|
||||
>
|
||||
Изтрий
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div >
|
||||
</div >
|
||||
</ProtectedRoute>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
|
45
pages/cart/reports/report.tsx
Normal file
45
pages/cart/reports/report.tsx
Normal file
@ -0,0 +1,45 @@
|
||||
//next.js page to show all locatons in the database with a link to the location page
|
||||
// import axios from "axios";
|
||||
import { Location, UserRole } from "@prisma/client";
|
||||
import Layout from "../../../components/layout";
|
||||
import ReportForm from "../../../components/reports/ReportForm";
|
||||
import axiosInstance from '../../../src/axiosSecure';
|
||||
import ProtectedRoute from '../../../components/protectedRoute';
|
||||
|
||||
function NewPage(loc: Location) {
|
||||
return (
|
||||
<Layout>
|
||||
<ProtectedRoute allowedRoles={[UserRole.POWERUSER, UserRole.ADMIN, UserRole.USER, UserRole.EXTERNAL]}>
|
||||
<div className="h-5/6 grid place-items-center">
|
||||
<ReportForm />
|
||||
</div></ProtectedRoute>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
export default NewPage;
|
||||
|
||||
//------------------pages\cart\locations\edit\[id].tsx------------------
|
||||
|
||||
export const getServerSideProps = async (context) => {
|
||||
return {
|
||||
props: {}
|
||||
};
|
||||
//if query is undefined, then it is a new location
|
||||
// if (context.query.id === undefined) {
|
||||
// return {
|
||||
// props: {}
|
||||
// };
|
||||
// }
|
||||
|
||||
// const { data: loc } = await axiosInstance.get(
|
||||
// `${process.env.NEXTAUTH_URL}api/data/locations/` + context.params.id
|
||||
// );
|
||||
// console.log(location) //this is the location object
|
||||
// context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
|
||||
// return {
|
||||
// props: {
|
||||
// location: loc,
|
||||
// },
|
||||
// };
|
||||
};
|
Reference in New Issue
Block a user