diff --git a/.env b/.env index 854bba3..61f85aa 100644 --- a/.env +++ b/.env @@ -8,6 +8,7 @@ NEXTAUTH_SECRET=ed8a9681efc414df89dfd03cd188ed58 NODE_ENV=development # mysql +DATABASE=mysql://cart:cartpw@localhost:3306/cart # // owner: dobromir.popov@gmail.com | Специално Свидетелстване София # // https://console.cloud.google.com/apis/credentials/oauthclient/926212607479-d3m8hm8f8esp3rf1639prskn445sa01v.apps.googleusercontent.com?project=grand-forge-108716 diff --git a/components/reports/ExperienceForm.js b/components/reports/ExperienceForm.js index eff676f..a96decc 100644 --- a/components/reports/ExperienceForm.js +++ b/components/reports/ExperienceForm.js @@ -4,7 +4,7 @@ import { toast } from 'react-toastify'; import { useRouter } from "next/router"; import Link from "next/link"; import DayOfWeek from "../DayOfWeek"; -import { Location, UserRole } from "@prisma/client"; +import { ReportType } from "@prisma/client"; const common = require('src/helpers/common'); import { useSession } from "next-auth/react" @@ -97,6 +97,7 @@ export default function ExperienceForm({ publisherId, assgnmentId, existingItem, e.preventDefault(); item.publisher = { connect: { id: pubId } }; item.location = { connect: { id: parseInt(item.locationId) } }; + item.type = ReportType.Experience; delete item.locationId; try { diff --git a/components/reports/FeedbackForm.js b/components/reports/FeedbackForm.js index 3cd0664..cec9532 100644 --- a/components/reports/FeedbackForm.js +++ b/components/reports/FeedbackForm.js @@ -4,7 +4,7 @@ import { toast } from 'react-toastify'; import { useRouter } from "next/router"; import Link from "next/link"; import DayOfWeek from "../DayOfWeek"; -import { Location, UserRole } from "@prisma/client"; +import { ReportType } from "@prisma/client"; const common = require('src/helpers/common'); import { useSession } from "next-auth/react" @@ -55,7 +55,7 @@ export default function FeedbackForm({ publisherId, onDone }) { assignmentId: 0, publisherId: publisherId, date: new Date(), - placementCount: 0, + placementCount: 1, videoCount: 0, returnVisitInfoCount: 0, conversationCount: 0 @@ -73,6 +73,8 @@ export default function FeedbackForm({ publisherId, onDone }) { const handleSubmit = async (e) => { e.preventDefault(); item.publisher = { connect: { id: pubId } }; + //ToDo: create dedicated feedback type instead of using placementCount for subtype + item.type = item.placementCount === 1 ? ReportType.Feedback_Problem : (item.placementCount === 2 ? ReportType.Feedback_Suggestion : ReportType.Feedback); delete item.assignmentId; try { diff --git a/components/reports/ReportForm.js b/components/reports/ReportForm.js index b6f22b5..50bc119 100644 --- a/components/reports/ReportForm.js +++ b/components/reports/ReportForm.js @@ -4,6 +4,7 @@ import { toast } from "react-hot-toast"; import { useRouter } from "next/router"; import Link from "next/link"; import { useSession } from "next-auth/react" +import { ReportType } from "@prisma/client"; const common = require('src/helpers/common'); @@ -89,6 +90,7 @@ export default function ReportForm({ shiftId, existingItem, onDone }) { item.publisher = { connect: { id: publisherId } }; item.shift = { connect: { id: parseInt(item.shiftId) } }; item.date = new Date(item.date); + item.type = ReportType.Report; delete item.publisherId; delete item.shiftId; item.placementCount = parseInt(item.placementCount); diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 82e5a1f..0760d19 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -42,10 +42,10 @@ export const authOptions: NextAuthOptions = { } } }), - AppleProvider({ - clientId: process.env.APPLE_APP_ID, - clientSecret: process.env.APPLE_SECRET - }), + // AppleProvider({ + // clientId: process.env.APPLE_APP_ID, + // clientSecret: process.env.APPLE_SECRET + // }), // AzureADProvider({ // clientId: process.env.AZURE_AD_CLIENT_ID, // clientSecret: process.env.AZURE_AD_CLIENT_SECRET, diff --git a/pages/cart/reports/list.tsx b/pages/cart/reports/list.tsx index 3675b55..fc6d47c 100644 --- a/pages/cart/reports/list.tsx +++ b/pages/cart/reports/list.tsx @@ -9,16 +9,35 @@ import { useSession } from "next-auth/react" import common from '../../../src/helpers/common'; import Layout from "../../../components/layout"; import ProtectedRoute from '../../../components/protectedRoute'; -import { Location, UserRole } from "@prisma/client"; +import { Location, UserRole, ReportType } from "@prisma/client"; export default function Reports() { const [reports, setReports] = useState([]); + const [filteredReports, setFilteredReports] = useState([]); + const router = useRouter(); const { data: session } = useSession(); + const [filterType, setFilterType] = useState('ServiceReport'); + + const handleFilterChange = (event) => { + setFilterType(event.target.value); + console.log("event filter set to:" + event.target.value); + }; + useEffect(() => { + const isFeedbackType = type => [ + 'Feedback_Problem', + 'Feedback_Suggestion', + 'Feedback' + ].includes(type); + + setFilteredReports(reports.filter(report => + filterType === 'Feedback' ? isFeedbackType(report.type) : report.type === filterType + )); + }, [reports, filterType]); const deleteReport = (id) => { axiosInstance @@ -66,7 +85,7 @@ export default function Reports() { -
+

Отчети

@@ -74,18 +93,21 @@ export default function Reports() { Добави нов отчет - - - +
+ + + + +
@@ -98,13 +120,13 @@ export default function Reports() { - {reports.map((report) => ( + {filteredReports.map((report) => (
{report.publisher.firstName + " " + report.publisher.lastName} {common.getDateFormated(new Date(report.date))} {report.location?.name} - {(report.experienceInfo === null || report.experienceInfo === "") + {(report.type === ReportType.ServiceReport) ? ( <>
Отчет
@@ -113,9 +135,16 @@ export default function Reports() { Клипове: {report.videoCount}
Адреси / Телефони: {report.returnVisitInfoCount}
- ) : (report.placementCount > 0) ? ( + ) : (report.type === ReportType.Feedback || report.type === ReportType.Feedback_Problem || report.type === ReportType.Feedback_Suggestion) ? ( <> -
Отзив
+
+ Отзив + {report.type === "Feedback_Problem" ? + - Проблем : + report.type === "Feedback_Suggestion" ? + - Предложение : + ""} +
) : ( diff --git a/prisma/migrations/20240418092928_add_event_log_table/migration.sql b/prisma/migrations/20240418092928_add_event_log_table/migration.sql new file mode 100644 index 0000000..52dd62f --- /dev/null +++ b/prisma/migrations/20240418092928_add_event_log_table/migration.sql @@ -0,0 +1,20 @@ +-- CreateTable +CREATE TABLE `EventLog` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `date` DATETIME(3) NOT NULL, + `publisherId` VARCHAR(191) NULL, + `shiftId` INTEGER NULL, + `content` VARCHAR(191) NOT NULL, + `type` ENUM('AssignnementReplacementRequested', 'AssignnementReplacement', 'SentEmail') NOT NULL, + + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `EventLog` +ADD CONSTRAINT `EventLog_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher` (`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `EventLog` +ADD CONSTRAINT `EventLog_shiftId_fkey` FOREIGN KEY (`shiftId`) REFERENCES `Shift` (`id`) ON DELETE SET NULL ON UPDATE CASCADE; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index aa7ecdd..cbb1d77 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -121,6 +121,7 @@ model Publisher { comments String? reports Report[] Message Message[] + EventLog EventLog[] } model Availability { @@ -179,6 +180,7 @@ model Shift { reportId Int? @unique Report Report? @relation(fields: [reportId], references: [id]) isPublished Boolean @default(false) //NEW v1.0.1 + EventLog EventLog[] @@map("Shift") } @@ -256,6 +258,23 @@ model Message { type MessageType @default(Email) } +enum EventLogType { + AssignnementReplacementRequested + AssignnementReplacement + SentEmail +} + +model EventLog { + id Int @id @default(autoincrement()) + date DateTime + publisherId String? + publisher Publisher? @relation(fields: [publisherId], references: [id]) + shiftId Int? + shift Shift? @relation(fields: [shiftId], references: [id]) + content String + type EventLogType +} + //user auth and session management model User { id String @id @default(cuid())