diff --git a/_doc/notes.mb b/_doc/notes.mb index a109fda..a833b61 100644 --- a/_doc/notes.mb +++ b/_doc/notes.mb @@ -102,8 +102,9 @@ npm install -g next next build next start ## ------------------------------- dev -----------------------------------### - - +#get docker logs + sudo docker logs pw-nextjs-app-1 >> ./app.log + # aider: export OPENAI_API_KEY=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 # personal export OPENAI_API_KEY=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 # dev-bro diff --git a/components/availability/AvailabilityForm.js b/components/availability/AvailabilityForm.js index 6dad867..9ea300a 100644 --- a/components/availability/AvailabilityForm.js +++ b/components/availability/AvailabilityForm.js @@ -16,6 +16,7 @@ import bg from 'date-fns/locale/bg'; // Bulgarian locale import { bgBG } from '../x-date-pickers/locales/bgBG'; // Your custom translation file import { ToastContainer } from 'react-toastify'; +import axios from 'axios'; @@ -181,123 +182,98 @@ export default function AvailabilityForm({ publisherId, existingItem, inline, on delete availability.date; //remove date from availability as it is not part of the db model // ---------------------- CB UI -------------- - if (config.checkboxUI.enabled) { - const selectedSlots = timeSlots.filter(slot => slot.isChecked); - // Sort the selected intervals by start time - const sortedSlots = [...selectedSlots].sort((a, b) => a.startTime - b.startTime); + const selectedSlots = timeSlots.filter(slot => slot.isChecked); + // Sort the selected intervals by start time + const sortedSlots = [...selectedSlots].sort((a, b) => a.startTime - b.startTime); - // Group continuous slots - const groupedIntervals = []; - let currentGroup = [sortedSlots[0]]; + // Group continuous slots + const groupedIntervals = []; + let currentGroup = [sortedSlots[0]]; - for (let i = 1; i < sortedSlots.length; i++) { - const previousSlot = currentGroup[currentGroup.length - 1]; - const currentSlot = sortedSlots[i]; - // Calculate the difference in hours between slots - const difference = (currentSlot.startTime - previousSlot.endTime) / (60 * 60 * 1000); + for (let i = 1; i < sortedSlots.length; i++) { + const previousSlot = currentGroup[currentGroup.length - 1]; + const currentSlot = sortedSlots[i]; + // Calculate the difference in hours between slots + const difference = (currentSlot.startTime - previousSlot.endTime) / (60 * 60 * 1000); - // Assuming each slot represents an exact match to the increment (1.5 hours), we group them - if (difference === 0) { - currentGroup.push(currentSlot); - } else { - groupedIntervals.push(currentGroup); - currentGroup = [currentSlot]; - } - } - // Don't forget the last group - if (currentGroup.length > 0) { + // Assuming each slot represents an exact match to the increment (1.5 hours), we group them + if (difference === 0) { + currentGroup.push(currentSlot); + } else { groupedIntervals.push(currentGroup); + currentGroup = [currentSlot]; } - - // Create availability objects from grouped slots - const availabilities = groupedIntervals.map(group => { - const startTime = group[0].startTime; - const endTime = group[group.length - 1].endTime; - return { - publisherId: availability.publisherId, - startTime: startTime, - endTime: endTime, - isWithTransportIn: group[0].isFirst && timeSlots[0].isWithTransport, - isWithTransportOut: group[group.length - 1].isLast && timeSlots[timeSlots.length - 1].isWithTransport, - // Add other necessary fields, like isWithTransport if applicable - }; - }); - - //if more than one interval, we delete and recreate the availability, as it is not possble to map them - if (availability.id && availabilities.length > 1) { - await axiosInstance.delete(urls.apiUrl + availability.id); - delete availability.id; - } - - // const firstSlotWithTransport = timeSlots[0].checked && timeSlots[0]?.isWithTransport; - // const lastSlotWithTransport = timeSlots[timeSlots.length - 1].checked && timeSlots[timeSlots.length - 1]?.isWithTransport; - - availabilities.forEach(async av => { - // expand availability - const avToStore = { - ...availability, - ...av, - startTime: av.startTime, - endTime: av.endTime, - name: "От календара", - id: undefined, - - // isWithTransportIn: firstSlotWithTransport, - // isWithTransportOut: lastSlotWithTransport, - - }; - console.log("AvailabilityForm: handleSubmit: " + av); - if (availability.id) { - // UPDATE EXISTING ITEM - await axiosInstance.put(urls.apiUrl + availability.id, { - ...avToStore, - }); - } else { - // CREATE NEW ITEM - await axiosInstance.post(urls.apiUrl, avToStore); - } - handleCompletion(avToStore); // Assuming `handleCompletion` is defined to handle post-save logic - }); - - - } - // ---------------------- TimePicker UI -------------- - else { - availability.publisher = { connect: { id: availability.publisherId } }; - delete availability.publisherId; + // Don't forget the last group + if (currentGroup.length > 0) { + groupedIntervals.push(currentGroup); + } + // Create availability objects from grouped slots + const availabilities = groupedIntervals.map(group => { + const startTime = group[0].startTime; + const endTime = group[group.length - 1].endTime; + return { + publisherId: availability.publisherId, + startTime: startTime, + endTime: endTime, + isWithTransportIn: group[0].isFirst && timeSlots[0].isWithTransport, + isWithTransportOut: group[group.length - 1].isLast && timeSlots[timeSlots.length - 1].isWithTransport, + // Add other necessary fields, like isWithTransport if applicable + }; + }); + + //if more than one interval, we delete and recreate the availability, as it is not possble to map them + if (availability.id && availabilities.length > 1) { + await axiosInstance.delete(urls.apiUrl + availability.id); + delete availability.id; + } + + // const firstSlotWithTransport = timeSlots[0].checked && timeSlots[0]?.isWithTransport; + // const lastSlotWithTransport = timeSlots[timeSlots.length - 1].checked && timeSlots[timeSlots.length - 1]?.isWithTransport; + + availabilities.forEach(async av => { + // expand availability + const avToStore = { + ...availability, + ...av, + startTime: av.startTime, + endTime: av.endTime, + name: "От календара", + id: undefined, + + // isWithTransportIn: firstSlotWithTransport, + // isWithTransportOut: lastSlotWithTransport, + + }; + console.log("AvailabilityForm: handleSubmit: " + av); if (availability.id) { - console.log('editing avail# ' + availability.id); - //delete availability.id; - // UPDATE EXISTING ITEM - var itemUpdate = { ...availability, id: undefined }; await axiosInstance.put(urls.apiUrl + availability.id, { - ...itemUpdate, - }); - toast.success("Task Updated", { - position: "bottom-center", + ...avToStore, }); } else { // CREATE NEW ITEM - console.log('creating new avail: ' + availability); - const response = await axiosInstance.post(urls.apiUrl, availability); - const createdItem = response.data; - availability.id = createdItem.id; - toast.success("Task Saved", { - position: "bottom-center", - }); + await axiosInstance.post(urls.apiUrl, avToStore); } - } + handleCompletion(avToStore); // Assuming `handleCompletion` is defined to handle post-save logic + }); handleCompletion(availability); } catch (error) { alert("Нещо се обърка. Моля, опитайте отново по-късно."); toast.error("Нещо се обърка. Моля, опитайте отново по-късно."); console.error(error.message); - } - }; + try { + const { data: session, status } = useSession(); + const userId = session.user.id; + axiosInstance.post('/log', { message: error.message, userId: userId }); + } + catch (err) { + console.error("Error logging error: ", err); + } + }; + } const handleDelete = async (e) => { e.preventDefault(); @@ -346,7 +322,6 @@ export default function AvailabilityForm({ publisherId, existingItem, inline, on const itemStartDate = new Date(item?.startTime); const itemEndDate = new Date(item?.endTime); - while (currentTime < endTime) { let slotStart = new Date(currentTime); let slotEnd = new Date(currentTime + increment * 60 * 60 * 1000); // Calculate slot end time @@ -370,7 +345,6 @@ export default function AvailabilityForm({ publisherId, existingItem, inline, on return slots; }; - const TimeSlotCheckboxes = ({ slots, setSlots, item }) => { const [allDay, setAllDay] = useState(false); @@ -474,39 +448,13 @@ export default function AvailabilityForm({ publisherId, existingItem, inline, on
setAvailability({ ...availability, endTime: value })} />
-
- {config?.checkboxUI && config.checkboxUI.enabled ? ( -
- {/* Time slot checkboxes */} - -
- ) : ( - <> - {/* Start Time Picker */} -
- setAvailability({ ...availability, startTime: value })} /> -
- - {/* End Time Picker */} -
- setAvailability({ ...availability, endTime: value })} /> -
-
- -
- - )} +
+ {/* Time slot checkboxes */} + +
-