2026-05-07 14:25:06 +00:00
|
|
|
import React, { useState, useEffect, useRef } from 'react'
|
|
|
|
|
import {
|
|
|
|
|
FaChevronLeft,
|
|
|
|
|
FaChevronRight,
|
|
|
|
|
FaMapMarkerAlt,
|
|
|
|
|
FaCalendarAlt,
|
|
|
|
|
FaUsers,
|
|
|
|
|
FaExpand,
|
|
|
|
|
FaCommentAlt,
|
|
|
|
|
FaPaperPlane,
|
|
|
|
|
} from 'react-icons/fa'
|
2026-06-25 22:55:44 +00:00
|
|
|
import { Button, Dialog } from '@/components/ui'
|
2026-05-25 20:00:57 +00:00
|
|
|
import { useDialogContext } from '@/components/ui/Dialog/Dialog'
|
2026-05-07 14:25:06 +00:00
|
|
|
import { EventCommentDto, EventDto } from '@/proxy/intranet/models'
|
|
|
|
|
import useLocale from '@/utils/hooks/useLocale'
|
|
|
|
|
import { currentLocalDate } from '@/utils/dateUtils'
|
|
|
|
|
import Avatar from '@/components/ui/Avatar/Avatar'
|
2026-07-08 06:14:40 +00:00
|
|
|
import { AVATAR_URL, MULTIVALUE_DELIMITER } from '@/constants/app.constant'
|
2026-05-07 14:25:06 +00:00
|
|
|
import { intranetService } from '@/services/intranet.service'
|
|
|
|
|
import dayjs from 'dayjs'
|
|
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
2026-05-08 08:38:57 +00:00
|
|
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
2026-06-26 19:02:53 +00:00
|
|
|
import ImageLightbox from './ImageLightbox'
|
|
|
|
|
import LikeButton from './LikeButton'
|
|
|
|
|
import { imageSrc } from './widgetUtils'
|
2026-05-07 14:25:06 +00:00
|
|
|
|
|
|
|
|
dayjs.extend(relativeTime)
|
|
|
|
|
|
|
|
|
|
interface EventModalProps {
|
|
|
|
|
event: EventDto
|
|
|
|
|
onClose: () => void
|
2026-06-26 19:02:53 +00:00
|
|
|
onLikeChange?: (event: EventDto) => void
|
2026-05-07 14:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-26 19:02:53 +00:00
|
|
|
function EventModalContent({ event, onClose, onLikeChange }: EventModalProps) {
|
2026-05-07 14:25:06 +00:00
|
|
|
const currentLocale = useLocale()
|
2026-07-08 06:14:40 +00:00
|
|
|
const photos = (event.photos || '').split(MULTIVALUE_DELIMITER).filter(Boolean)
|
2026-05-08 08:38:57 +00:00
|
|
|
const { translate } = useLocalization()
|
2026-05-25 20:00:57 +00:00
|
|
|
const { isMaximized } = useDialogContext()
|
2026-05-07 14:25:06 +00:00
|
|
|
|
|
|
|
|
// Photo slider state
|
|
|
|
|
const [activePhoto, setActivePhoto] = useState(0)
|
|
|
|
|
const [lightboxOpen, setLightboxOpen] = useState(false)
|
|
|
|
|
const [lightboxIndex, setLightboxIndex] = useState(0)
|
|
|
|
|
|
|
|
|
|
// Comments state
|
|
|
|
|
const [comments, setComments] = useState<EventCommentDto[]>(event.comments || [])
|
|
|
|
|
const [commentText, setCommentText] = useState('')
|
|
|
|
|
const [submitting, setSubmitting] = useState(false)
|
|
|
|
|
const commentInputRef = useRef<HTMLTextAreaElement>(null)
|
|
|
|
|
const commentsEndRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
2026-05-08 18:11:56 +00:00
|
|
|
// Likes state
|
|
|
|
|
const [likes, setLikes] = useState(event.likes)
|
|
|
|
|
const [isLiked, setIsLiked] = useState(event.isLiked)
|
|
|
|
|
const [liking, setLiking] = useState(false)
|
|
|
|
|
|
2026-05-07 14:25:06 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
// Refresh comments from API on open
|
|
|
|
|
intranetService.getEventComments(event.id).then((res) => {
|
|
|
|
|
if (res.data) setComments(res.data)
|
|
|
|
|
})
|
|
|
|
|
}, [event.id])
|
|
|
|
|
|
|
|
|
|
const scrollToBottom = () => {
|
|
|
|
|
commentsEndRef.current?.scrollIntoView({ behavior: 'smooth' })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleSubmitComment = async () => {
|
|
|
|
|
if (!commentText.trim() || submitting) return
|
|
|
|
|
setSubmitting(true)
|
|
|
|
|
try {
|
|
|
|
|
const res = await intranetService.createEventComment(event.id, commentText.trim())
|
|
|
|
|
if (res.data) {
|
|
|
|
|
setComments((prev) => [...prev, res.data!])
|
|
|
|
|
setCommentText('')
|
|
|
|
|
setTimeout(scrollToBottom, 100)
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
setSubmitting(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
|
|
|
if (e.key === 'Enter' && !e.shiftKey) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
handleSubmitComment()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-08 18:11:56 +00:00
|
|
|
const handleLike = async () => {
|
|
|
|
|
if (liking) return
|
|
|
|
|
setLiking(true)
|
|
|
|
|
// Optimistic update
|
|
|
|
|
setIsLiked((prev) => !prev)
|
|
|
|
|
setLikes((prev) => (isLiked ? Math.max(0, prev - 1) : prev + 1))
|
|
|
|
|
try {
|
|
|
|
|
const res = await intranetService.likeEvent(event.id)
|
|
|
|
|
if (res.data) {
|
2026-06-26 19:02:53 +00:00
|
|
|
const updatedEvent = {
|
|
|
|
|
...event,
|
|
|
|
|
likes: res.data.likes,
|
|
|
|
|
isLiked: res.data.isLiked,
|
|
|
|
|
}
|
|
|
|
|
setLikes(updatedEvent.likes)
|
|
|
|
|
setIsLiked(updatedEvent.isLiked)
|
|
|
|
|
onLikeChange?.(updatedEvent)
|
2026-05-08 18:11:56 +00:00
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
// Revert on error
|
|
|
|
|
setIsLiked((prev) => !prev)
|
|
|
|
|
setLikes((prev) => (isLiked ? prev + 1 : Math.max(0, prev - 1)))
|
|
|
|
|
} finally {
|
|
|
|
|
setLiking(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 14:25:06 +00:00
|
|
|
const openLightbox = (idx: number) => {
|
|
|
|
|
setLightboxIndex(idx)
|
|
|
|
|
setLightboxOpen(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const closeLightbox = () => setLightboxOpen(false)
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2026-05-25 20:00:57 +00:00
|
|
|
<Dialog.Body className="flex flex-col min-h-0">
|
|
|
|
|
{/* Header */}
|
|
|
|
|
<div className="pb-3 pr-16 border-b border-gray-200 dark:border-gray-700 flex-shrink-0">
|
|
|
|
|
<div className="flex items-start justify-between gap-4">
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<h2 className="text-xl font-bold text-gray-900 dark:text-white leading-tight">
|
|
|
|
|
{event.name}
|
|
|
|
|
</h2>
|
|
|
|
|
<div className="flex flex-wrap items-center gap-4 mt-2 text-sm text-gray-600 dark:text-gray-400">
|
|
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
<FaCalendarAlt className="w-3.5 h-3.5 text-green-500" />
|
|
|
|
|
{currentLocalDate(event.date, currentLocale || 'tr')}
|
|
|
|
|
</span>
|
|
|
|
|
{event.place && (
|
2026-05-07 14:25:06 +00:00
|
|
|
<span className="flex items-center gap-1">
|
2026-05-25 20:00:57 +00:00
|
|
|
<FaMapMarkerAlt className="w-3.5 h-3.5 text-red-500" />
|
|
|
|
|
{event.place}
|
2026-05-07 14:25:06 +00:00
|
|
|
</span>
|
|
|
|
|
)}
|
2026-05-25 20:00:57 +00:00
|
|
|
{event.participantsCount > 0 && (
|
|
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
<FaUsers className="w-3.5 h-3.5 text-blue-500" />
|
|
|
|
|
{event.participantsCount}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
<div>
|
2026-06-26 19:02:53 +00:00
|
|
|
<LikeButton
|
2026-05-25 20:00:57 +00:00
|
|
|
onClick={handleLike}
|
|
|
|
|
disabled={liking}
|
2026-06-26 19:02:53 +00:00
|
|
|
isLiked={isLiked}
|
|
|
|
|
likes={likes}
|
|
|
|
|
/>
|
2026-05-07 14:25:06 +00:00
|
|
|
</div>
|
2026-05-25 20:00:57 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{event.user && (
|
|
|
|
|
<div className="flex items-center gap-2 mt-3">
|
|
|
|
|
<Avatar
|
|
|
|
|
size={28}
|
|
|
|
|
shape="circle"
|
|
|
|
|
src={AVATAR_URL(event.user.id, event.user.tenantId)}
|
|
|
|
|
/>
|
|
|
|
|
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">
|
|
|
|
|
{event.user.fullName}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Scrollable body */}
|
|
|
|
|
<div className={`overflow-y-auto ${isMaximized ? 'flex-1 min-h-0' : 'max-h-[62vh]'}`}>
|
|
|
|
|
{/* Photo Gallery */}
|
|
|
|
|
{photos.length > 0 && (
|
|
|
|
|
<div className="m-3 border-b border-gray-200 dark:border-gray-700">
|
|
|
|
|
{/* Main photo */}
|
|
|
|
|
<div className="relative w-full rounded-lg overflow-hidden dark:bg-gray-900 mb-2 mx-auto">
|
|
|
|
|
<img
|
2026-06-26 19:02:53 +00:00
|
|
|
src={imageSrc(photos[activePhoto])}
|
2026-05-25 20:00:57 +00:00
|
|
|
alt={`${event.name} ${activePhoto + 1}`}
|
|
|
|
|
className="w-full h-56 object-contain cursor-zoom-in"
|
|
|
|
|
onClick={() => openLightbox(activePhoto)}
|
|
|
|
|
/>
|
2026-06-25 22:55:44 +00:00
|
|
|
<Button
|
2026-05-25 20:00:57 +00:00
|
|
|
onClick={() => openLightbox(activePhoto)}
|
2026-06-25 22:55:44 +00:00
|
|
|
variant="plain"
|
|
|
|
|
shape="none"
|
|
|
|
|
icon={<FaExpand className="h-4 w-4" />}
|
|
|
|
|
className="absolute top-2 right-2 !h-7 !w-7 !rounded-lg !px-0 bg-black/50 text-white transition-colors hover:!bg-black/70"
|
2026-08-14 11:32:31 +00:00
|
|
|
title={translate('::App.Platform.Fullscreen')}
|
2026-06-25 22:55:44 +00:00
|
|
|
/>
|
2026-05-07 14:25:06 +00:00
|
|
|
{photos.length > 1 && (
|
2026-05-25 20:00:57 +00:00
|
|
|
<>
|
2026-06-25 22:55:44 +00:00
|
|
|
<Button
|
2026-05-25 20:00:57 +00:00
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
setActivePhoto((i) => (i - 1 + photos.length) % photos.length)
|
|
|
|
|
}}
|
2026-06-25 22:55:44 +00:00
|
|
|
variant="plain"
|
|
|
|
|
shape="circle"
|
|
|
|
|
icon={<FaChevronLeft className="h-4 w-4" />}
|
|
|
|
|
className="absolute left-2 top-1/2 !h-8 !w-8 -translate-y-1/2 !px-0 bg-black/50 text-white transition-colors hover:!bg-black/70"
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
2026-05-25 20:00:57 +00:00
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
setActivePhoto((i) => (i + 1) % photos.length)
|
|
|
|
|
}}
|
2026-06-25 22:55:44 +00:00
|
|
|
variant="plain"
|
|
|
|
|
shape="circle"
|
|
|
|
|
icon={<FaChevronRight className="h-4 w-4" />}
|
|
|
|
|
className="absolute right-2 top-1/2 !h-8 !w-8 -translate-y-1/2 !px-0 bg-black/50 text-white transition-colors hover:!bg-black/70"
|
|
|
|
|
/>
|
2026-05-25 20:00:57 +00:00
|
|
|
</>
|
2026-05-07 14:25:06 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
2026-05-25 20:00:57 +00:00
|
|
|
{/* Thumbnail strip */}
|
|
|
|
|
{photos.length > 1 && (
|
|
|
|
|
<div className="flex gap-2 overflow-x-auto pb-1">
|
|
|
|
|
{photos.map((photo, idx) => (
|
2026-06-25 22:55:44 +00:00
|
|
|
<Button
|
2026-05-25 20:00:57 +00:00
|
|
|
key={idx}
|
|
|
|
|
onClick={() => setActivePhoto(idx)}
|
2026-06-25 22:55:44 +00:00
|
|
|
variant="plain"
|
|
|
|
|
shape="none"
|
|
|
|
|
className={`flex-shrink-0 !h-16 !w-16 !rounded-lg !px-0 overflow-hidden border-2 transition-all ${
|
2026-05-25 20:00:57 +00:00
|
|
|
idx === activePhoto
|
|
|
|
|
? 'border-green-500 opacity-100'
|
|
|
|
|
: 'border-transparent opacity-60 hover:opacity-90'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<img
|
2026-06-26 19:02:53 +00:00
|
|
|
src={imageSrc(photo)}
|
2026-05-25 20:00:57 +00:00
|
|
|
alt={`Thumbnail ${idx + 1}`}
|
|
|
|
|
className="w-full h-full object-cover"
|
|
|
|
|
/>
|
2026-06-25 22:55:44 +00:00
|
|
|
</Button>
|
2026-05-25 20:00:57 +00:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-05-07 14:25:06 +00:00
|
|
|
|
2026-05-25 20:00:57 +00:00
|
|
|
{/* Description */}
|
|
|
|
|
{event.description && (
|
|
|
|
|
<div className="pb-2 border-b border-gray-200 dark:border-gray-700">
|
|
|
|
|
<p className="text-sm text-gray-700 dark:text-gray-300 whitespace-pre-line">
|
|
|
|
|
{event.description}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-05-07 14:25:06 +00:00
|
|
|
|
2026-05-25 20:00:57 +00:00
|
|
|
{/* Comments Section */}
|
|
|
|
|
<div className="py-3">
|
|
|
|
|
<h3 className="text-sm font-semibold text-gray-900 dark:text-white flex items-center gap-2 mb-2">
|
|
|
|
|
<FaCommentAlt className="w-4 h-4 text-green-500" />
|
2026-08-14 14:03:34 +00:00
|
|
|
{translate('::App.Events.Comments')} ({comments.length})
|
2026-05-25 20:00:57 +00:00
|
|
|
</h3>
|
2026-05-07 14:25:06 +00:00
|
|
|
|
2026-05-25 20:00:57 +00:00
|
|
|
{/* Comment List */}
|
|
|
|
|
<div className="max-h-64 overflow-y-auto">
|
|
|
|
|
{comments.length === 0 ? (
|
|
|
|
|
<p className="text-sm text-gray-400 dark:text-gray-500 text-center">
|
2026-08-14 14:03:34 +00:00
|
|
|
{translate('::App.Events.NoComment')}
|
2026-05-25 20:00:57 +00:00
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
comments.map((comment) => (
|
|
|
|
|
<div key={comment.id} className="flex gap-3">
|
|
|
|
|
{comment.user && (
|
|
|
|
|
<Avatar
|
|
|
|
|
size={32}
|
|
|
|
|
shape="circle"
|
|
|
|
|
src={AVATAR_URL(comment.user.id, comment.user.tenantId)}
|
|
|
|
|
className="flex-shrink-0"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<div className="bg-gray-50 dark:bg-gray-700/60 rounded-xl px-3 py-2">
|
|
|
|
|
<p className="text-xs font-semibold text-gray-800 dark:text-gray-200">
|
2026-08-14 11:32:31 +00:00
|
|
|
{comment.user?.fullName ?? translate('::App.Platform.User')}
|
2026-05-25 20:00:57 +00:00
|
|
|
</p>
|
|
|
|
|
<p className="text-sm text-gray-700 dark:text-gray-300 mt-0.5 whitespace-pre-line">
|
|
|
|
|
{comment.content}
|
2026-05-07 14:25:06 +00:00
|
|
|
</p>
|
|
|
|
|
</div>
|
2026-05-25 20:00:57 +00:00
|
|
|
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1 px-1">
|
|
|
|
|
{dayjs(comment.creationTime).fromNow()}
|
|
|
|
|
</p>
|
2026-05-07 14:25:06 +00:00
|
|
|
</div>
|
2026-05-25 20:00:57 +00:00
|
|
|
</div>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
<div ref={commentsEndRef} />
|
2026-05-07 14:25:06 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-05-25 20:00:57 +00:00
|
|
|
</div>
|
|
|
|
|
</Dialog.Body>
|
2026-05-07 14:25:06 +00:00
|
|
|
|
2026-06-26 08:59:13 +00:00
|
|
|
<Dialog.Footer className="pt-2 border-t border-gray-200 dark:border-gray-700 flex-shrink-0 flex items-end gap-1">
|
2026-05-25 20:00:57 +00:00
|
|
|
<div className="flex flex-1 gap-2 items-end">
|
|
|
|
|
<textarea
|
|
|
|
|
ref={commentInputRef}
|
|
|
|
|
value={commentText}
|
|
|
|
|
autoFocus
|
|
|
|
|
onChange={(e) => setCommentText(e.target.value)}
|
|
|
|
|
onKeyDown={handleKeyDown}
|
2026-08-14 14:03:34 +00:00
|
|
|
placeholder={translate('::App.Events.EventAttendance')}
|
2026-05-25 20:00:57 +00:00
|
|
|
rows={1}
|
2026-06-26 19:02:53 +00:00
|
|
|
className="flex-1 resize-none px-2 py-1 text-sm rounded-xl bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 transition-colors"
|
2026-05-25 20:00:57 +00:00
|
|
|
/>
|
2026-06-25 22:55:44 +00:00
|
|
|
<Button
|
2026-05-25 20:00:57 +00:00
|
|
|
type="button"
|
2026-06-26 08:59:13 +00:00
|
|
|
size="sm"
|
2026-05-25 20:00:57 +00:00
|
|
|
onClick={handleSubmitComment}
|
|
|
|
|
disabled={!commentText.trim() || submitting}
|
2026-06-25 22:55:44 +00:00
|
|
|
variant="solid"
|
|
|
|
|
icon={<FaPaperPlane className="h-4 w-4" />}
|
|
|
|
|
/>
|
2026-05-25 20:00:57 +00:00
|
|
|
</div>
|
2026-08-14 11:32:31 +00:00
|
|
|
<Button size="sm" onClick={onClose} type="button" variant="solid">
|
2026-05-25 20:00:57 +00:00
|
|
|
{translate('::App.Platform.Close')}
|
2026-06-25 22:55:44 +00:00
|
|
|
</Button>
|
2026-05-25 20:00:57 +00:00
|
|
|
</Dialog.Footer>
|
2026-05-07 14:25:06 +00:00
|
|
|
|
2026-06-26 19:02:53 +00:00
|
|
|
<ImageLightbox
|
|
|
|
|
images={photos}
|
|
|
|
|
activeIndex={lightboxIndex}
|
|
|
|
|
isOpen={lightboxOpen}
|
|
|
|
|
altPrefix={event.name}
|
|
|
|
|
getSrc={imageSrc}
|
|
|
|
|
onClose={closeLightbox}
|
|
|
|
|
onChangeIndex={setLightboxIndex}
|
|
|
|
|
/>
|
2026-05-07 14:25:06 +00:00
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-26 19:02:53 +00:00
|
|
|
const EventModal: React.FC<EventModalProps> = ({ event, onClose, onLikeChange }) => {
|
2026-05-25 20:00:57 +00:00
|
|
|
return (
|
|
|
|
|
<Dialog isOpen onClose={onClose} onRequestClose={onClose} width={768}>
|
2026-06-26 19:02:53 +00:00
|
|
|
<EventModalContent event={event} onClose={onClose} onLikeChange={onLikeChange} />
|
2026-05-25 20:00:57 +00:00
|
|
|
</Dialog>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 14:25:06 +00:00
|
|
|
export default EventModal
|