@@ -99,20 +88,22 @@ export default function WeekDay({ day }: { day: any }) {
key={i}
className='border border-gray-300 h-14 w-full'
onClick={() => {
- setShowEventModal(true);
setDaySelected(day);
handleTimeSelected(time,i);
}}
>
{dayEvents.map((evt: selectedDayEvent, idx) => (
- (evt.timeFrom === time) && (
+ (dayjs(evt.startDateTime).format('hh:00 A') === time) && (
setSelectedEvent(evt)}
+ className={`bg-${displayColor(evt.type)}-300 hover:bg-${displayColor(evt.type)}-400 cursor-pointer p-1 mx-2 text-gray-600 text-xs rounded mb-1 `}
+ onClick={() => {
+ setSelectedEvent(evt)
+ setShowEventModal(true)
+ }}
>
- {evt.title}
+ {evt.job.company.name}
)
))}
diff --git a/src/components/Calendar/context/ContextWrapper.tsx b/src/components/Calendar/context/ContextWrapper.tsx
index 1c2dafb6..c569b0ee 100644
--- a/src/components/Calendar/context/ContextWrapper.tsx
+++ b/src/components/Calendar/context/ContextWrapper.tsx
@@ -1,111 +1,113 @@
-import React,{ useState , useReducer, useEffect, useMemo } from 'react'
-import dayjs from 'dayjs'
-import GlobalContext from './GlobalContext'
-import { DispatchCallEventsAction } from './GlobalContext';
-import { updateLabelAction } from './GlobalContext';
+import React, { useState, useReducer, useEffect, useMemo } from 'react';
+import dayjs from 'dayjs';
+import GlobalContext from './GlobalContext';
import { selectedDayEvent } from './GlobalContext';
+import { fetchEvents } from '@/helpers/api';
+export const labelsClasses = new Map([
+ ["INTERVIEW", "green"],
+ ["PPT", "red"],
+ ["TEST", "indigo"],
+ ["COMPLETED", "blue"],
+ ["APPLICATION", "purple"]
+]);
-
-function savedEventsReducer(state:any,{type,payload}:DispatchCallEventsAction){
- switch(type){
- case 'push':
- return [...state,payload];
- case 'update':
- return state.map((evt:any) => evt.id === payload.id ? payload : evt)
- case 'delete':
- return state.filter((evt:any) => evt.id !== payload.id )
+function savedEventsReducer(state: selectedDayEvent[], { type, payload }: { type: string, payload: any }) {
+ switch (type) {
+ case 'fetch':
+ return payload;
default:
throw new Error();
}
}
-function initEvents(){
- const storageEvents = typeof window!="undefined"?localStorage.getItem('savedEvents'):null
- const parsedEvents = storageEvents ? JSON.parse(storageEvents) : []
- return parsedEvents
-}
-
-export default function ContextWrapper(props: { children: React.ReactNode }) {
- const[monthIndex,setMonthIndex] = useState(dayjs().month());
- const[weekOffset,setWeekOffset] = useState(0);
- const[dateOffset,setDateOffset]=useState(0);
- const[Current_view,SetCurrent_view] = useState
("Month")
- const[showEventModal,setShowEventModal] = useState(false);
- const [daySelected, setDaySelected] = useState(dayjs());
- const [selectedEvent, setSelectedEvent] = useState(null);
- const[labels,setLabels] = useState([])
- const [savedEvents,dispatchCallEvents] = useReducer(savedEventsReducer,[],initEvents);
- const [timeFrom, setTimeFrom] = useState(selectedEvent ? selectedEvent.timeFrom : "from");
- const [timeTo, setTimeTo] = useState(selectedEvent ? selectedEvent.timeTo : "to");
-
- const filteredEvents = useMemo(() => {
- return savedEvents.filter((evt:any) =>
- labels.filter((lbl:updateLabelAction) => lbl.checked)
- .map((lbl:updateLabelAction) => lbl.label)
- .includes(evt.label)
- );
- },[savedEvents,labels]);
-
+export default function ContextWrapper(props: any) {
+ const [monthIndex, setMonthIndex] = useState(dayjs().month());
+ const [weekOffset, setWeekOffset] = useState(0);
+ const [dateOffset, setDateOffset] = useState(0);
+ const [Current_view, SetCurrent_view] = useState('Month');
+ const [showEventModal, setShowEventModal] = useState(false);
+ const [daySelected, setDaySelected] = useState(dayjs());
+ const [selectedEvent, setSelectedEvent] = useState(null);
+ const [labels, setLabels] = useState(() => {
+ return Array.from(labelsClasses.keys()).map(label => ({
+ label,
+ checked: true
+ }));
+ });
+ const [savedEvents, dispatchCallEvents] = useReducer(savedEventsReducer, []);
+ const [timeFrom, setTimeFrom] = useState('from');
+ const [timeTo, setTimeTo] = useState('to');
- useEffect(() => {
- setLabels((prevLabels) => {
- return [...new Set(savedEvents.map((evt:updateLabelAction) => evt.label))].map((label:any) =>
- {
- const currentLabel = prevLabels.find(lbl => lbl.label === label)
- return {
- label,
- checked : currentLabel ? currentLabel.checked :true,
- }
- })
- })
- },[savedEvents])
-
- useEffect(() => {
- localStorage.setItem("savedEvents",JSON.stringify(savedEvents));
- },[savedEvents])
+ const filteredEvents = useMemo(() => {
+ return savedEvents.filter((evt:selectedDayEvent) =>
+ labels
+ .filter((lbl) => lbl.checked)
+ .map((lbl) => lbl.label)
+ .includes(evt.type)
+ );
+ }, [savedEvents, labels]);
- useEffect(() => {
- if(!showEventModal){
- setSelectedEvent(null);
+ useEffect(() => {
+ async function fetchAndSetEvents() {
+ try {
+ const data = await fetchEvents();
+ dispatchCallEvents({ type: 'fetch', payload: data });
+ } catch (error) {
+ console.error('Failed to fetch events:', error);
}
- },[showEventModal])
-
- function updateLabel(newLabel:updateLabelAction){
- setLabels(labels.map((lbl) => lbl.label === newLabel.label ? newLabel : lbl))
}
+ fetchAndSetEvents();
+ }, []);
+ useEffect(() => {
+ setLabels((prevLabels) => {
+ const uniqueEventTypes = [...new Set(savedEvents.map((evt) => evt.type))];
- return (
- {
+ const currentLabel = prevLabels.find((lbl) => lbl.label === label);
+ return {
+ label: label,
+ checked: currentLabel ? currentLabel.checked : true,
+ };
+ });
+ });
+ }, [savedEvents]);
- }} >
- {props.children}
+ function updateLabel(newLabel: { label: string, checked: boolean }) {
+ setLabels((prevLabels) => prevLabels.map((lbl) => (lbl.label === newLabel.label ? newLabel : lbl)));
+ }
+
+ return (
+
+ {props.children}
- )
+ );
}
diff --git a/src/components/Calendar/context/GlobalContext.tsx b/src/components/Calendar/context/GlobalContext.tsx
index 42666307..8c2f6ebd 100644
--- a/src/components/Calendar/context/GlobalContext.tsx
+++ b/src/components/Calendar/context/GlobalContext.tsx
@@ -1,6 +1,5 @@
import React from "react";
import dayjs, { Dayjs } from "dayjs";
-
export interface DispatchCallEventsAction {
type: string;
payload: any;
@@ -11,14 +10,30 @@ export interface updateLabelAction {
checked: boolean;
}
+export interface Job {
+ id: string;
+ role: string;
+ company: {
+ id: string;
+ name: string;
+ };
+ season: {
+ id: string;
+ type: string;
+ year:number;
+ };
+}
+
export interface selectedDayEvent{
- title:string,
- description:string,
- label:string,
- id:string;
- day: number | null;
- timeFrom: string;
- timeTo: string;
+ id:string,
+ startDateTime:Date,
+ endDateTime:Date,
+ metadata:string,
+ roundNumber:number,
+ type:string,
+ visibleToRecruiter:boolean,
+ job:Job
+
}
diff --git a/src/helpers/api.ts b/src/helpers/api.ts
index 5ff12641..7efc667a 100644
--- a/src/helpers/api.ts
+++ b/src/helpers/api.ts
@@ -438,3 +438,8 @@ export const postJobCoordinator = async (
body: body,
});
};
+
+export const fetchEvents = async () => {
+ return apiCall("/events");
+
+};
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 8f4bedb0..19796579 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4911,16 +4911,7 @@ string-convert@^0.2.0:
resolved "https://registry.yarnpkg.com/string-convert/-/string-convert-0.2.1.tgz#6982cc3049fbb4cd85f8b24568b9d9bf39eeff97"
integrity sha512-u/1tdPl4yQnPBjnVrmdLo9gtuLvELKsAoRapekWggdiQNvvvum+jYF329d84NAa660KQw7pB2n36KrIKVoXa3A==
-"string-width-cjs@npm:string-width@^4.2.0":
- version "4.2.3"
- resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
- integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
- dependencies:
- emoji-regex "^8.0.0"
- is-fullwidth-code-point "^3.0.0"
- strip-ansi "^6.0.1"
-
-string-width@^4.1.0:
+"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -4992,14 +4983,7 @@ string.prototype.trimstart@^1.0.8:
define-properties "^1.2.1"
es-object-atoms "^1.0.0"
-"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
- version "6.0.1"
- resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
- integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
- dependencies:
- ansi-regex "^5.0.1"
-
-strip-ansi@^6.0.0, strip-ansi@^6.0.1:
+"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==