Skip to content

Commit

Permalink
Calender view events (#120)
Browse files Browse the repository at this point in the history
Co-authored-by: PrkharMishra <[email protected]>
  • Loading branch information
2 people authored and Princekumarofficial committed Aug 27, 2024
1 parent f74b203 commit f7c1320
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 457 deletions.
6 changes: 3 additions & 3 deletions src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { getDate } from "./CalenderComponent/util";
import Month from "./CalenderComponent/Month";
import GlobalContext from "./context/GlobalContext";
import CalendarHeader from "./CalenderComponent/CalendarHeader";
import EventModal from "./CalenderComponent/EventModal";
import EventDetails from "./CalenderComponent/EventDetails";
import SidebarCalendar from "./CalenderComponent/SidebarCalendar";
import WeeklyView from "./CalenderComponent/WeeklyView";
import DailyView from "./CalenderComponent/DailyView";

export default function Calendar(){
const{ monthIndex , showEventModal,setShowEventModal,Current_view, weekOffset,dateOffset } = useContext(GlobalContext);
const{ monthIndex , showEventModal,Current_view, weekOffset,dateOffset } = useContext(GlobalContext);
const [currentMonth,setCurrentMonth]= useState(getMonth());
const [currentWeek,setCurrentWeek]= useState(getWeek(weekOffset));
const [displayDate,setDisplayDate]= useState(getDate(dateOffset));
Expand All @@ -31,7 +31,7 @@ export default function Calendar(){

return(
<div>
{ showEventModal && <EventModal /> }
{ showEventModal && <EventDetails /> }


<div className="flex flex-col h-screen">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default function CalendarHeader() {

</span>
{Isopen &&
<span className='absolute mt-10 bg-white rounded py-2 '>
<span className='absolute mt-10 bg-white rounded py-2 z-10'>
{drop_down_list.map((view_name,idx) => (

<p
Expand Down
98 changes: 26 additions & 72 deletions src/components/Calendar/CalenderComponent/DailyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ import dayjs from 'dayjs';
import GlobalContext from '../context/GlobalContext';
import { time_list } from './WeekDay';
import { selectedDayEvent } from '../context/GlobalContext';
import { labelsClasses } from '../context/ContextWrapper';

interface Event {
day: any;
rowIdx: any;
interface Event{
startDateTime:any,
endDateTime:any,
rowIdx:any,
}

let colors = "border-green-400 border-red-400 border-indigo-400 border-gray-400 border-blue-400 border-purple-400"
let hover_colors = "hover:bg-green-400 hover:bg-red-400 hover:bg-indigo-400 hover:bg-gray-400 hover:bg-blue-400 hover:bg-purple-400"
let text_colors = "text-green-400 text--red-400 text-indigo-400 text-gray-400 text-blue-300 text-purple-400"


export default function DailyView({ date }: { date: any }) {
const [dayEvents, setDayEvents] = useState([]);
const { setShowEventModal, setDaySelected, filteredEvents, setSelectedEvent, setTimeFrom, setTimeTo } =
useContext(GlobalContext);

useEffect(() => {
const events = filteredEvents.filter((evt: Event) => dayjs(evt.day).format("DD-MM-YY") === date.format("DD-MM-YY"));
const events = filteredEvents.filter((evt: Event) => dayjs(evt.startDateTime).format("DD-MM-YY") === date.format("DD-MM-YY"));
setDayEvents(events);
}, [filteredEvents, date]);

function getCurrentDate() {
return date.format("DD-MM-YY") === dayjs().format("DD-MM-YY") ? 'bg-blue-700 text-white rounded-full ' : '';
return date.format("DD-MM-YY") === dayjs().format("DD-MM-YY") ? 'text-white bg-blue-700 rounded-full ' : '';
}

function getCurrentDay() {
return date.format("DD-MM-YY") === dayjs().format("DD-MM-YY") ? 'text-blue-600' : '';
return date.format("DD-MM-YY") === dayjs().format("DD-MM-YY") ? 'text-blue-700' : '';
}

function handleTimeSelected(time: string, i: number) {
Expand All @@ -36,99 +43,46 @@ export default function DailyView({ date }: { date: any }) {
setTimeTo(time_list[i + 1]);
}
}

function getCurrentTimeIndicatorPosition() {
const currentTime = dayjs();
if (date.format("DD-MM-YY") === currentTime.format("DD-MM-YY")) {
const nowInMinutes = currentTime.hour() * 60 + currentTime.minute();
const closestTimeIndex = time_list.findIndex(time => {
const [hours, minutes] = time.split(/[: ]/);
const isPM = time.includes("PM");
let timeInMinutes = parseInt(hours) % 12 * 60 + (parseInt(minutes) || 0);
if (isPM) timeInMinutes += 12 * 60;
return timeInMinutes >= nowInMinutes;
});

if (closestTimeIndex > -1 && time_list[closestTimeIndex]) {
const closestTime = time_list[closestTimeIndex];
const [hours, minutes] = closestTime.split(/[: ]/);
const isPM = closestTime.includes("PM");
let timeInMinutes = parseInt(hours) % 12 * 60 + (parseInt(minutes) || 0);
if (isPM) timeInMinutes += 12 * 60;
const offset = nowInMinutes - timeInMinutes;
const topPosition = closestTimeIndex * 56 + (offset / 60) * 56;
return topPosition;
}
}
return null;
function displayColor(label:string){
return labelsClasses.get(label);
}

const currentTimeIndicatorPosition = getCurrentTimeIndicatorPosition();

return (
<div className='flex flex-col w-full space-y-4'>
<div className='flex flex-col w-full space-y-4 '>
<div className='flex flex-col items-start ml-12'>
<p className={`text-xs pl-1 text-gray-600 ${getCurrentDay()}`}>{date.format('ddd').toUpperCase()}</p>
<div className='flex item-center justify-center'>
<p className={`text-2xl p-1 ${getCurrentDate()}`}>{date.date()}</p>
<p className={`text-2xl p-1 ${getCurrentDate()}`}>{date.format('DD')}</p>
</div>
</div>
<span className='flex flex-col h-10 overflow-y-auto ml-10'>
<div
onClick={() => {
setShowEventModal(true);
setDaySelected(date);
}}
className='flex-1 cursor-pointer'>
{dayEvents.map((evt: selectedDayEvent, idx) => (
(evt.timeFrom === "From" || evt.timeTo === "to") && (
<div
onClick={() => setSelectedEvent(evt)}
key={idx}
className={`bg-${evt.label}-300 w-40 border border-gray-600 hover:bg-${evt.label}-400 cursor-pointer p-1 mx-2 text-gray-600 text-xs rounded mb-1 truncate`}
>
{evt.title}
</div>
)
))}
</div>
</span>
<span className='flex flex-row space-x-2'>
<div className='flex flex-col space-y-10 -mt-2'>
{time_list.map((time: string, i: number) => (
<p key={i} className='text-xs text-gray-600 font-extralight'>{time}</p>
))}
</div>
<div className='flex flex-col flex-grow relative'>
{currentTimeIndicatorPosition !== null && (
<div
style={{ top: `${currentTimeIndicatorPosition}px` }}
className='absolute left-0 w-full border-t-2 border-red-500'
>
<div
className='w-3 h-3 bg-red-500 rounded-full absolute'
style={{ top: '-6px', left: '-6px' }}
></div>
</div>
)}

{time_list.map((time: string, i: number) => (
<div
onClick={() => {
setShowEventModal(true);
setDaySelected(date);
handleTimeSelected(time, i);
}}
key={i}
className='h-14 w-full border border-gray-300'>
<div className='flex-1 cursor-pointer pt-1 overflow-y-auto'>
<div className='flex-1 pt-1 overflow-y-auto'>
{dayEvents.map((evt: selectedDayEvent, idx) => (
(evt.timeFrom === time) && (
(dayjs(evt.startDateTime).format('hh:00 A')=== time) && (
<div
key={idx}
className={`bg-${evt.label}-300 hover:bg-${evt.label}-400 cursor-pointer p-1 mx-2 text-gray-600 text-xs rounded mb-1 truncate`}
onClick={() => 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 truncate`}
onClick={() => {
setSelectedEvent(evt)
setShowEventModal(true)
}}
>
{evt.title}
{evt.job.company.name}
</div>
)
))}
Expand Down
117 changes: 117 additions & 0 deletions src/components/Calendar/CalenderComponent/EventDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import React,{useContext,useState} from 'react'
import GlobalContext from '../context/GlobalContext';
import dayjs from 'dayjs';
import { labelsClasses } from '../context/ContextWrapper';

export default function EventDetails() {
const { setShowEventModal, daySelected, selectedEvent} = useContext(GlobalContext);

const [description, setDescription] = useState<string>(selectedEvent ? selectedEvent.metadata : "");
const [selectedLabel, setSelectedLabel] = useState<[string, string]>(selectedEvent ? [selectedEvent.type, labelsClasses.get(selectedEvent.type) || ""] : ["", ""]);
const [timeFrom,setTimeFrom] = useState(selectedEvent ? dayjs(selectedEvent.startDateTime).format('hh:00 A') : "from")
const [timeTo,setTimeTo] = useState(selectedEvent ? dayjs(selectedEvent.endDateTime).format('hh:00 A') : "to")
const [checked,setChecked] = useState(selectedEvent ? selectedEvent.visibleToRecruiter : false)
const [companyName,setCompanyName] = useState(selectedEvent ? selectedEvent.job.company.name : "")
const [role,setRole] = useState(selectedEvent ? selectedEvent.job.role : "")
const [recruitmentType,setRecruitmentType] = useState(selectedEvent ? selectedEvent.job.season.type : "")
const [roundNumber,setRoundNumber] = useState(selectedEvent ? selectedEvent.roundNumber : 1)

function visibilityStatus(check:boolean){
return check ? "Yes" : "No";
}

return (
<div className="h-screen w-full fixed left-0 top-0 flex justify-center items-center z-50">
<form className="bg-white rounded-lg shadow-2xl w-1/4 ">
<header
className={'bg-gray-100 px-4 py-2 flex justify-between items-center'}
>
<span className="material-icons-outlined text-gray-400">
drag_handle
</span>
<button
onClick={()=>{setShowEventModal(false)}}>

<span className="material-icons-outlined text-gray-400 hover:text-red-400 p-2">
close
</span>
</button>
</header>
<div className="p-3">
<div className="grid grid-cols-7 items-end gap-y-4">

<span className="material-icons-outlined col-start-1 col-span-1 text-gray-400">
schedule
</span>
<p className="pl-2 col-start-2 col-span-3 font-medium text-gray-600">{daySelected.format("dddd, MMMM DD")}</p>
<div className="col-start-2 col-span-6 flex flex-row ">
<div className="relative flex flex-col mr-2">
<p className="rounded text-sm pl-2 font-medium text-gray-600"
>{timeFrom}</p>
</div>
<p className="pt-1 -mt-2">-</p>
<div className="relative flex flex-col ml-2">
<p
className="rounded text-sm font-medium text-gray-600"
>{timeTo}</p>
</div>
</div>
{description && <span className="material-icons-outlined col-start-1 col-span-1 text-gray-400 ">
segment
</span>}

{description &&<span className="col-start-2 col-span-6 border-0 text-gray-600 pb-2 w-full overflow-y-scroll font-medium h-5 "
>{description}</span>}
<span className="material-icons-outlined col-start-1 col-span-1 text-gray-400">
visibility
</span>
<span className='col-start-2 col-span-3 border-0 w-full font-medium'>Visible to Recruiter :</span>
<span className='col-start-5 col-span-3 -ml-5 border-0 w-full font-medium text-gray-600'>{visibilityStatus(checked)}</span>
<span className="material-icons-outlined col-start-1 col-span-1 text-gray-400">
label
</span>
<div className="relative w-full col-start-2 col-span-6">

<span className="col-start-2 col-span-6 font-medium w-full"
>{selectedLabel[0]}</span>
</div>

<span className="material-icons-outlined col-start-1 col-span-1 text-gray-400">
work
</span>
<div className='col-start-2 col-span-1 font-medium'>
Type :
</div>

<span className="col-start-3 col-span-5 font-medium w-full text-gray-600"
>{recruitmentType}</span>



<div className='col-start-2 col-span-2 font-medium'>
Company :
</div>
<span className="col-start-4 col-span-4 font-medium w-full -ml-5 h-7 overflow-y-scroll text-gray-600"
>{companyName}</span>
<div className='col-start-2 col-span-1 font-medium'>
Role :
</div>

<span className="col-start-3 col-span-5 font-medium w-full text-gray-600"
>{role}</span>
<div className='col-start-2 col-span-2 font-medium'>
Round :
</div>

<span className="col-start-4 -ml-16 col-span-1 text-center font-medium w-full text-gray-600"
>{roundNumber}</span>
</div>
</div>
<footer className="flex justify-end border-t p-3 mt-5 h-10">

</footer>
</form>
</div>
);
}

Loading

0 comments on commit f7c1320

Please sign in to comment.