mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
78 lines
3.5 KiB
TypeScript
78 lines
3.5 KiB
TypeScript
import { FC, MouseEvent, useEffect, useState } from 'react';
|
|
import dayjs from 'dayjs';
|
|
|
|
type Props = {
|
|
day: any
|
|
monthIndex: number
|
|
dayOffList: any[]
|
|
onClickDate?: () => any
|
|
onClickEvent?: (event: any) => any
|
|
};
|
|
|
|
const colorClasses = ['bg-amber-500', 'bg-emerald-500', 'bg-indigo-500', 'bg-fuchsia-500']
|
|
|
|
const DayInCalendar: FC<Props> = ({ day, monthIndex, dayOffList, onClickDate, onClickEvent }) => {
|
|
const [event, setEvent] = useState<any>(null)
|
|
|
|
useEffect(() => {
|
|
const result = dayOffList.find(item => dayjs(item.date).format('DDMMYY') === dayjs(day).format('DDMMYY'))
|
|
setEvent(result)
|
|
}, [day, dayOffList])
|
|
|
|
const handleClikEvent = (e: MouseEvent<HTMLElement>, selectedEvent: any) => {
|
|
e.stopPropagation()
|
|
// alert(JSON.stringify(selectedEvent))
|
|
onClickEvent!(selectedEvent)
|
|
}
|
|
|
|
const handleAddEvent = () => {
|
|
onClickDate!()
|
|
}
|
|
|
|
const getDayStyle = (day: any) => {
|
|
if (day.format('DD-MM-YY') === dayjs().format('DD-MM-YY')) { // TODAY
|
|
return 'text-white bg-blue-500 w-7 h-7 rounded-full flex justify-center items-center mt-2'
|
|
} else if (day.format('MM-YY') !== dayjs().month(monthIndex).format('MM-YY')) { // DAY IN NOT CURRENT MONTH
|
|
return 'text-gray-300 dark:text-zinc-600'
|
|
} else if (dayjs(day).format('dddd').toLowerCase() === 'sunday') { // SUNDAY
|
|
return 'text-rose-500 dark:text-rose-900'
|
|
} else {
|
|
return ''
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className={`relative border border-border flex flex-col items-center ${day.format('DD-MM-YY') === dayjs().format('DD-MM-YY') ? '' : ''}`}>
|
|
{/* <div className='absolute h-full w-full z-0' onClick={() => alert('absolute')}></div> */}
|
|
<header className='flex flex-col items-center w-full z-10'>
|
|
<p className={`text-sm p-1 font-medium my-1 ${getDayStyle(day)}`}>{dayjs(day).format('DD')}</p>
|
|
</header>
|
|
<div className='flex flex-1 flex-col w-full cursor-pointer z-10' onClick={handleAddEvent}>
|
|
{event &&
|
|
<span className={`bg-rose-500 dark:bg-rose-900 p-[3px] px-1 2xl:p-1 ml-1 mr-2 mb-1 text-white font-medium rounded truncate hover:bg-opacity-70 text-[10px] 2xl:text-xs`}
|
|
onClick={(e) => handleClikEvent(e, event)}
|
|
>
|
|
{event.name}
|
|
</span>
|
|
}
|
|
{/* {activities!.slice(0, 1).map((task, key) =>
|
|
<span key={key} className={`${colorClasses[Math.floor(Math.random() * colorClasses.length)]} p-[3px] px-1 2xl:p-1 ml-1 mr-2 mb-1 text-white font-medium rounded truncate hover:bg-opacity-70 text-xsm 2xl:text-xs`}
|
|
onClick={() => alert('this gonna be activities')}
|
|
>
|
|
{task.activity_txt}
|
|
</span>
|
|
)}
|
|
{activities!.length > 1 &&
|
|
<span className={`bg-gray-500 p-[3px] px-1 2xl:p-1 ml-1 mr-2 mb-1 text-white font-medium rounded truncate hover:bg-opacity-70 text-xsm 2xl:text-xs`}
|
|
onClick={() => alert('this gonna be activities')}
|
|
>
|
|
+{activities!.length - 1} Aktivitas Lainnya..
|
|
</span>} */}
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default DayInCalendar; |