add name to reports list. fix delete

This commit is contained in:
Dobromir Popov
2024-03-10 01:47:21 +02:00
parent 2cc8731519
commit 1880c34887

View File

@ -22,7 +22,7 @@ export default function Reports() {
const deleteReport = (id) => {
axiosInstance
.delete(`api/data/reports/${id}`)
.delete(`/api/data/reports/${id}`)
.then((res) => {
toast.success("Успешно изтрит отчет");
// router.push("/cart/reports/list");
@ -43,12 +43,12 @@ export default function Reports() {
const { data } = await axiosInstance.get("/api/data/locations");
setLocations(data);
console.log(data);
axiosInstance.get(`/api/data/reports`)
axiosInstance.get(`/api/data/reports?include=publisher,location`)
.then((res) => {
let reports = res.data;
reports.forEach((report) => {
report.location = data.find((loc) => loc.id === report.locationId);
});
// let reports = res.data;
// reports.forEach((report) => {
// report.location = data.find((loc) => loc.id === report.locationId);
// });
setReports(res.data);
})
.catch((err) => {
@ -78,6 +78,7 @@ export default function Reports() {
<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>
@ -87,9 +88,10 @@ export default function Reports() {
<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">
<td className="border px-2 py-2">{report.publisher.firstName + " " + report.publisher.lastName}</td>
<td className="border px-2 py-2">{common.getDateFormated(new Date(report.date))}</td>
<td className="border px-2 py-2">{report.location?.name}</td>
<td className="border px-2 py-2">
{(report.experienceInfo === null || report.experienceInfo === "")
? (
<>
@ -99,12 +101,19 @@ export default function Reports() {
Клипове: {report.videoCount} <br />
Адреси / Телефони: {report.returnVisitInfoCount} <br />
</>
) : (report.placementCount > 0) ? (
<>
<div><strong>Отзив</strong></div>
<div dangerouslySetInnerHTML={{ __html: report.experienceInfo }} />
</>
) : (
<>
<div><strong>Случка</strong></div>
<div dangerouslySetInnerHTML={{ __html: report.experienceInfo }} />
</>
)}
)
}
</td>
<td className="border px-4 py-2">
@ -122,8 +131,8 @@ export default function Reports() {
</div>
</div >
</div >
</ProtectedRoute>
</Layout>
</ProtectedRoute >
</Layout >
);
}