import { useEffect, useState } from "react" import type { components } from "../../types/saturday" import { saturdayClient } from "../../utils/client" import { Textarea, Input, Chip } from "@heroui/react" import type { PublicMember } from "../../store/member" import dayjs from "dayjs" import { EventStatus, UserEventAction } from "../../types/event" type PublicEvent = components["schemas"]["PublicEvent"] type EventLog = components["schemas"]["EventLog"] function EventLogItem(props: { eventLog: EventLog actor?: PublicMember }) { return (
{/*
*/}
{ UserEventAction.find(v => v.action === props.eventLog.action)?.text || props.eventLog.action }
{ props.actor?.avatar ? actor avatar : <> } { props.actor ? props.actor.alias : "" }
{dayjs(props.eventLog.gmtCreate).format("YYYY-MM-DD HH:mm")}
) } function EventStatusChip(props: { status: string }) { switch (props.status) { case EventStatus.open: return 未开始 case EventStatus.accepted: return 维修中 case EventStatus.committed: return 维修中 case EventStatus.closed: return 已完成 case EventStatus.cancelled: return 已取消 } } const filterEventLog = (event: PublicEvent) => { const eventLogs = event.logs const filteredLogs: (EventLog & { actor?: PublicMember })[] = [] // find the first log that action is "create" const createLog = eventLogs.find(log => log.action === "create") filteredLogs.push(createLog) // find the first log that action is "cancel" const cancelLog = eventLogs.find(log => log.action === "cancel") if (cancelLog) { filteredLogs.push(cancelLog) return filteredLogs } // find the last log that action is "accept" const acceptLog = eventLogs.findLast(log => log.action === "accept") if (acceptLog) { filteredLogs.push({ ...acceptLog, actor: event.member, }) } // find the last log that action is "close" const closeLog = eventLogs.findLast(log => log.action === "close") if (closeLog) { filteredLogs.push({ ...closeLog, actor: event.closedBy, }) } return filteredLogs } export default function EventDetail(props: { eventId?: number }) { const [event, setEvent] = useState() const fetchAndSetEvent = async (eventId: number) => { const { data } = await saturdayClient.GET("/events/{EventId}", { params: { path: { EventId: eventId, }, }, }) setEvent(data) } useEffect(() => { const url = new URL(window.location.href) const eventId = props.eventId ?? url.searchParams.get("eventId") if (!eventId) { return } fetchAndSetEvent(eventId as unknown as number) }, []) return ( event ? (

维修详情

#{event.eventId}