diff --git a/components/sidemenuData.js b/components/sidemenuData.js index e884535..fb62d4b 100644 --- a/components/sidemenuData.js +++ b/components/sidemenuData.js @@ -1,5 +1,9 @@ import { UserRole } from "@prisma/client"; +// import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +// import { faStar } from '@fortawesome/free-solid-svg-icons'; // Star icon +// import { faClipboardList } from '@fortawesome/free-solid-svg-icons'; // Clipboard icon +import { FaStar } from 'react-icons/fa'; // Import FontAwesome icons const sidemenu = [ @@ -103,6 +107,19 @@ const sidemenu = [ text: "Календар", url: "/cart/calendar", roles: [UserRole.ADMIN, UserRole.POWERUSER], + }, + { + id: "surveys", + // text: "Анкети", + // add new icon before text + // text: "Анкети", + text: ( + + + Анкети + + ), + url: "/cart/surveys", }, { id: "cart-reports", text: "Отчети", diff --git a/components/survey/SurveyForm.js b/components/survey/SurveyForm.js deleted file mode 100644 index 4ed75be..0000000 --- a/components/survey/SurveyForm.js +++ /dev/null @@ -1,169 +0,0 @@ -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" -import { MessageType, Message, Survey } from "@prisma/client"; -// import { content } from 'googleapis/build/src/apis/content'; -import { DatePicker } from '@mui/x-date-pickers/DatePicker'; -// import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3'; -// import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs' -import dayjs from 'dayjs'; - -const common = require('src/helpers/common'); - - -// ------------------ ------------------ -// This component is used to create and edit -/* location model: - -model Survey { - id Int @id @default(autoincrement()) - content String - answers Json? - messages Message[] - publicFrom DateTime? - publicUntil DateTime? -} - -model Message { - id Int @id @default(autoincrement()) - publisher Publisher @relation(fields: [publisherId], references: [id]) - publisherId String - date DateTime - content String - isRead Boolean @default(false) - isPublic Boolean @default(false) - type MessageType @default(Email) - publicUntil DateTime? - shownDate DateTime? - answer String? - answerDate DateTime? - - Survey Survey? @relation(fields: [surveyId], references: [id]) - surveyId Int? -} -*/ - -export default function SurveyForm({ existingItem }) { - - const router = useRouter(); - const [editMode, setEditMode] = useState(existingItem ? true : false); - const [item, setItem] = useState(existingItem || { - content: "Нова анкета", - answers: [], - publicFrom: new Date().toISOString(), - publicUntil: new Date().toISOString(), - }); - - useState(() => setEditMode(existingItem ? true : false), [existingItem]); - - - const handleChange = ({ target }) => { - setItem({ ...item, [target.name]: target.value }); - }; - - const handleDateChange = (fieldName, newDate) => { - setItem((prevItem) => ({ - ...prevItem, - [fieldName]: newDate - })); - }; - - const handleSubmit = async (e) => { - e.preventDefault(); - try { - //get all publisherIds and create a message for each - const pubs = await axiosInstance.get("/api/data/publishers"); - const messages = pubs.data.map(pub => { - return { - publisherId: pub.id, - content: JSON.stringify({ message: item.content, options: item.answers }), - date: new Date(), - isPublic: false, - type: MessageType.InApp, - publicUntil: item.publicUntil, - } - }); - item.messages = { create: messages }; - const { data } = await axiosInstance.post("/api/data/surveys", item); - toast.success("Анкетата е създадена успешно"); - router.push("/cart/surveys"); - } catch (error) { - toast.error("Възникна грешка при създаването на анкетата"); - console.error("Error creating survey:", error); - } - } - - const handleDelete = async (e) => { - e.preventDefault(); - if (!editMode) return; - try { - await axiosInstance.delete(`/api/data/surveys/${existingItem.id}`); - - toast.success("Записът изтрит", { - position: "bottom-center", - }); - - } catch (error) { - //alert("Нещо се обърка при изтриването. Моля, опитайте отново или се свържете с нас"); - console.log(JSON.stringify(error)); - toast.error(error.response?.data?.message || "Нещо се обърка при изтриването. Моля, опитай отново и се свържете с нас ако проблема продължи."); - } - }; - return ( -
- < form className="bg-white dark:bg-gray-800 shadow-md rounded px-8 pt-6 pb-8 mb-4" onSubmit={handleSubmit} > - -

Анкета {existingItem?.id}

-
- - handleDateChange('publicFrom', newDate)} value={dayjs(item.publicFrom)} /> -
-
- - handleDateChange('publicUntil', newDate)} value={dayjs(item.publicUntil)} /> -
-
- -