From 95ae307dcc7c34de60950650bcdda2a8f8d66763 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Mon, 4 Mar 2024 14:00:02 +0200 Subject: [PATCH 1/6] fix myschedule - code copied instead of using existing component due to different data structure --- components/publisher/ShiftsList.tsx | 2 +- components/sidemenuData.js | 10 +++--- pages/cart/publishers/myschedule.tsx | 47 ++++++++++++++++------------ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/components/publisher/ShiftsList.tsx b/components/publisher/ShiftsList.tsx index 07d176c..49cc71a 100644 --- a/components/publisher/ShiftsList.tsx +++ b/components/publisher/ShiftsList.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import toast from "react-hot-toast"; import { useRouter } from "next/router"; import Link from "next/link"; diff --git a/components/sidemenuData.js b/components/sidemenuData.js index 7c7053f..56e9119 100644 --- a/components/sidemenuData.js +++ b/components/sidemenuData.js @@ -15,11 +15,11 @@ const sidemenu = [ text: "График", url: "/cart/calendar/schedule", }, - // { - // id: "myshedule", - // text: "Моя График", - // url: "/cart/publishers/myschedule", - // }, + { + id: "myshedule", + text: "Моя График", + url: "/cart/publishers/myschedule", + }, { id: "locations", text: "Местоположения", diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index e1726f5..d9fb1eb 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -6,6 +6,7 @@ import axiosServer from '../../../src/axiosServer'; import common from '../../../src/helpers/common'; import ShiftsList from '../../../components/publisher/ShiftsList'; +import { monthNamesBG, GetTimeFormat, GetDateFormat } from "../../../src/helpers/const" import { useSession, getSession } from 'next-auth/react'; export default function MySchedulePage({ assignments }) { @@ -18,16 +19,37 @@ export default function MySchedulePage({ assignments }) { return ( +

Моите смени

-

Моите смени

- + {assignments && assignments.map((assignment) => ( +
+
{assignment.dateStr + ":"}
{/*This is the column for the date. I've given it a fixed width (w-8) which you can adjust*/} +
+
+ {GetTimeFormat(assignment.shift.startTime)} - {GetTimeFormat(assignment.shift.endTime)} + + +
+
+
+ ))}
); } -//get future assignmenrs for the current user (session.user.id) +//get future assignments for the current user (session.user.id) export const getServerSideProps = async (context) => { const session = await getSession(context); @@ -72,6 +94,7 @@ export const getServerSideProps = async (context) => { if (assignment.shift && assignment.shift.startTime) { return { ...assignment, + dateStr: assignment.shift.startTime.toLocaleDateString("bg-BG", { day: "numeric", month: "long" }), shift: { ...assignment.shift, startTime: assignment.shift.startTime.toISOString(), @@ -82,26 +105,10 @@ export const getServerSideProps = async (context) => { return assignment; }); - const singleKey = "all"; - const assignmentsStructure = { - assignments: { - items: { - [singleKey]: [], - }, - keys: [singleKey], - months: { - [singleKey]: "Всички смени", - }, - }, - selectedtab: singleKey, - }; - transformedAssignments.forEach(assignment => { - assignmentsStructure.assignments.items[singleKey].push(assignment); - }); return { - props: assignmentsStructure + props: { assignments: transformedAssignments } } } From a9d7df72627648e1b23cdba1e848bb74b3600d8d Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Mon, 4 Mar 2024 14:03:32 +0200 Subject: [PATCH 2/6] Mobile-first UI for my schedule --- pages/cart/publishers/myschedule.tsx | 58 +++++++++++++++++----------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/pages/cart/publishers/myschedule.tsx b/pages/cart/publishers/myschedule.tsx index d9fb1eb..1d33c12 100644 --- a/pages/cart/publishers/myschedule.tsx +++ b/pages/cart/publishers/myschedule.tsx @@ -13,36 +13,50 @@ export default function MySchedulePage({ assignments }) { const { data: session, status } = useSession(); if (status === "loading") { - return
Loading...
; + return
Loading...
; } return ( -

Моите смени

- {assignments && assignments.map((assignment) => ( -
-
{assignment.dateStr + ":"}
{/*This is the column for the date. I've given it a fixed width (w-8) which you can adjust*/} -
-
- {GetTimeFormat(assignment.shift.startTime)} - {GetTimeFormat(assignment.shift.endTime)} - - +

Моите смени

+
+ {assignments && assignments.map((assignment) => ( +
+
+

{assignment.dateStr}

+
+
+
+
+
Час
+
+ {GetTimeFormat(assignment.shift.startTime)} - {GetTimeFormat(assignment.shift.endTime)} +
+
+
+
Действия
+
+ + +
+
+
-
- ))} + ))} +
From e22d121f0f924b21bc6dc5831ed600c09009fc90 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 5 Mar 2024 15:26:41 +0200 Subject: [PATCH 3/6] add Messages table and availability dateOfEntry --- .env.development | 4 ++-- _doc/notes.mb | 2 +- components/availability/AvailabilityForm.js | 2 ++ .../migration.sql | 18 ++++++++++++++++++ prisma/schema.prisma | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 prisma/migrations/20240305111150_add_availability_date_of_entry/migration.sql diff --git a/.env.development b/.env.development index e623f71..afec269 100644 --- a/.env.development +++ b/.env.development @@ -11,5 +11,5 @@ TELEGRAM_BOT=true SSL_KEY=./certificates/localhost-key.pem SSL_CERT=./certificates/localhost.pem -# DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev -DATABASE_URL=mysql://cart:cartpw@localhost:3306/cart +DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev +# DATABASE_URL=mysql://cart:cartpw@localhost:3306/cart diff --git a/_doc/notes.mb b/_doc/notes.mb index 26e9cbd..4862741 100644 --- a/_doc/notes.mb +++ b/_doc/notes.mb @@ -109,7 +109,7 @@ next start export OPENAI_API_KEY=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 # personal export OPENAI_API_KEY=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 # dev-bro -# -------------update PRISMA schema/sync database ------------------------ # +# ----------------------------------------------update PRISMA schema/sync database ----------------------------------------------- # # prisma migrate dev --create-only npx prisma generate npx prisma migrate dev --name fix_nextauth_schema --create-only diff --git a/components/availability/AvailabilityForm.js b/components/availability/AvailabilityForm.js index 4605a19..c1fe4c7 100644 --- a/components/availability/AvailabilityForm.js +++ b/components/availability/AvailabilityForm.js @@ -193,6 +193,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o repeatWeekly: doRepeat, dayOfMonth: doRepeat ? null : startTime.getDate(), endDate: doRepeat ? repeatUntil : null, + dateOfEntry: new Date(), }; } @@ -207,6 +208,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o availability.repeatWeekly = doRepeat; availability.dayOfMonth = doRepeat ? null : availability.startTime.getDate(); availability.endDate = doRepeat ? repeatUntil : null; + availability.dateOfEntry = new Date(); return availability; } diff --git a/prisma/migrations/20240305111150_add_availability_date_of_entry/migration.sql b/prisma/migrations/20240305111150_add_availability_date_of_entry/migration.sql new file mode 100644 index 0000000..d0d0e08 --- /dev/null +++ b/prisma/migrations/20240305111150_add_availability_date_of_entry/migration.sql @@ -0,0 +1,18 @@ +-- AlterTable +ALTER TABLE `Availability` ADD COLUMN `dateOfEntry` DATETIME(3) NULL; + +-- CreateTable +CREATE TABLE `Message` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `publisherId` VARCHAR(191) NOT NULL, + `date` DATETIME(3) NOT NULL, + `content` VARCHAR(191) NOT NULL, + `isRead` BOOLEAN NOT NULL DEFAULT false, + `isPublic` BOOLEAN NOT NULL DEFAULT false, + `type` ENUM('Email', 'SMS', 'Push', 'InApp') NOT NULL DEFAULT 'Email', + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `Message` ADD CONSTRAINT `Message_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 33be971..2ea7b1f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -133,7 +133,7 @@ model Availability { repeatWeekly Boolean? // New field to indicate weekly repetition // until now dayofweek was used for repetition when dayOfMonth is null repeatFrequency Int? // New field to indicate repetition frequency endDate DateTime? // New field for the end date of repetition - //dateOfEntry DateTime? //NEW v1.0.1 trade storage for intuintivity + dateOfEntry DateTime? //NEW v1.0.1 trade storage for intuintivity } model CartEvent { From a9f726519fb52b64d520c03d7226968320a464d2 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 5 Mar 2024 15:33:38 +0200 Subject: [PATCH 4/6] hide my schedule in production --- components/sidemenuData.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/sidemenuData.js b/components/sidemenuData.js index 56e9119..7c7053f 100644 --- a/components/sidemenuData.js +++ b/components/sidemenuData.js @@ -15,11 +15,11 @@ const sidemenu = [ text: "График", url: "/cart/calendar/schedule", }, - { - id: "myshedule", - text: "Моя График", - url: "/cart/publishers/myschedule", - }, + // { + // id: "myshedule", + // text: "Моя График", + // url: "/cart/publishers/myschedule", + // }, { id: "locations", text: "Местоположения", From c15da32fd2d94927761e869351657c862ee32f5c Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 5 Mar 2024 16:21:28 +0200 Subject: [PATCH 5/6] reload availabilities from DB in case of delete error --- components/availability/AvailabilityForm.js | 34 +++++++++------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/components/availability/AvailabilityForm.js b/components/availability/AvailabilityForm.js index c1fe4c7..3b4dd89 100644 --- a/components/availability/AvailabilityForm.js +++ b/components/availability/AvailabilityForm.js @@ -56,30 +56,27 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o }, []); - - // Define the minimum and maximum times const minTime = new Date(); minTime.setHours(8, 0, 0, 0); // 8:00 AM const maxTime = new Date(); maxTime.setHours(20, 0, 0, 0); // 8:00 PM + const fetchItemFromDB = async () => { + const id = parseInt(router.query.id); + if (existingItems.length == 0 && id) { + try { + const response = await axiosInstance.get(`/api/data/availabilities/${id}`); + setAvailabilities([response.data]); + setEditMode(true); + } catch (error) { + console.error(error); + toast.error("Error fetching availability data."); + } + } + }; useEffect(() => { - const fetchItemFromDB = async () => { - const id = parseInt(router.query.id); - if (existingItems.length == 0 && id) { - try { - const response = await axiosInstance.get(`/api/data/availabilities/${id}`); - setAvailabilities([response.data]); - setEditMode(true); - } catch (error) { - console.error(error); - toast.error("Error fetching availability data."); - } - } - }; - fetchItemFromDB(); }, [router.query.id]); @@ -212,10 +209,6 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o return availability; } - - - - const handleDelete = async (e) => { e.preventDefault(); try { @@ -236,6 +229,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o alert("Нещо се обърка при изтриването. Моля, опитайте отново или се свържете с нас"); console.log(JSON.stringify(error)); toast.error(error.response?.data?.message || "An error occurred"); + fetchItemFromDB(); } }; From 2accbbbe2610056a6986a833f31fe69f4c037a76 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Tue, 5 Mar 2024 16:22:03 +0200 Subject: [PATCH 6/6] hide delete error message --- components/availability/AvailabilityForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/availability/AvailabilityForm.js b/components/availability/AvailabilityForm.js index 3b4dd89..f95870e 100644 --- a/components/availability/AvailabilityForm.js +++ b/components/availability/AvailabilityForm.js @@ -226,7 +226,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o handleCompletion({ deleted: true }); } } catch (error) { - alert("Нещо се обърка при изтриването. Моля, опитайте отново или се свържете с нас"); + //alert("Нещо се обърка при изтриването. Моля, опитайте отново или се свържете с нас"); console.log(JSON.stringify(error)); toast.error(error.response?.data?.message || "An error occurred"); fetchItemFromDB();