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}

+
+ +
+
+
+ )} ) }