From 8720a56c7d392f3fc8469fdf382d4a405e367f8b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 07:24:01 +0000 Subject: [PATCH] feat: add eventid query parameter to auto-open event details - Add eventid URL parameter support to open specific event on page load - Automatically fetch and display event detail drawer when eventid is present - Show error message if event ID is invalid or doesn't exist - Update URL when opening/closing event detail drawer - Add error message UI with dismiss functionality - Maintain eventid in URL for shareable links to specific events --- src/pages/repair/RepairAdmin.tsx | 82 ++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/src/pages/repair/RepairAdmin.tsx b/src/pages/repair/RepairAdmin.tsx index 2124111..9044c08 100644 --- a/src/pages/repair/RepairAdmin.tsx +++ b/src/pages/repair/RepairAdmin.tsx @@ -213,6 +213,7 @@ export default function App() { const [userInfo, setUserInfo] = useState() const [currentMember, setCurrentMember] = useState() const [token, setToken] = useState() + const [errorMessage, setErrorMessage] = useState("") useEffect(() => { const check = async () => { @@ -244,6 +245,39 @@ export default function App() { check() }, []) + // Handle eventid query parameter to auto-open event detail + useEffect(() => { + const loadEventFromUrl = async () => { + if (!token) return // Wait for authentication + + const params = new URLSearchParams(window.location.search) + const eventId = params.get('eventid') + + if (eventId) { + try { + const { data, error } = await saturdayClient.GET("/events/{eventId}", { + params: { + path: { + eventId: eventId, + }, + }, + }) + + if (error || !data) { + setErrorMessage(`无法找到工单 #${eventId},该工单可能不存在或已被删除`) + } else { + setActiveEvent(data as PublicEvent) + onOpen() + } + } catch (err) { + setErrorMessage(`加载工单 #${eventId} 时出错`) + } + } + } + + loadEventFromUrl() + }, [token]) + const list = useAsyncList({ async load() { setIsLoading(true) @@ -299,10 +333,12 @@ export default function App() { // Update URL query params when page or statusFilter changes useEffect(() => { - const params = new URLSearchParams() + const params = new URLSearchParams(window.location.search) params.set('page', page.toString()) if (statusFilter.length > 0) { params.set('status', statusFilter.join(',')) + } else { + params.delete('status') } const newUrl = `${window.location.pathname}?${params.toString()}` window.history.replaceState({}, '', newUrl) @@ -367,6 +403,22 @@ export default function App() { const onOpenEventDetail = (event: PublicEvent) => { setActiveEvent(event) onOpen() + + // Update URL with eventid + const params = new URLSearchParams(window.location.search) + params.set('eventid', event.eventId) + const newUrl = `${window.location.pathname}?${params.toString()}` + window.history.replaceState({}, '', newUrl) + } + + const onCloseEventDetail = () => { + onOpenChange() + + // Remove eventid from URL + const params = new URLSearchParams(window.location.search) + params.delete('eventid') + const newUrl = `${window.location.pathname}?${params.toString()}` + window.history.replaceState({}, '', newUrl) } const MobileEventCard = ({ event }: { event: PublicEvent }) => ( @@ -566,13 +618,35 @@ export default function App() { } isOpen={isOpen} onOpenChange={onOpenChange} - onClose={() => { - onOpenChange() - }} + onClose={onCloseEventDetail} onDelete={() => {}} onEdit={() => {}} > + + {/* Error Message Display */} + {errorMessage && ( +
+
+
+ + + +
+

{errorMessage}

+
+ +
+
+
+ )} ) }