fix commit

This commit is contained in:
Clas Wen 2025-05-24 13:54:06 +08:00
parent b4350c9b50
commit 478a7146f5
3 changed files with 52 additions and 24 deletions

View file

@ -3,7 +3,7 @@ import type { PublicMember } from "../../store/member"
import { EventStatus, type PublicEvent } from "../../types/event" import { EventStatus, type PublicEvent } from "../../types/event"
import { saturdayApiBaseUrl } from "../../utils/client" import { saturdayApiBaseUrl } from "../../utils/client"
import { Button, Form, Select, SelectItem, Textarea } from "@heroui/react" import { Button, Form, Select, SelectItem, Textarea } from "@heroui/react"
import { useState } from "react" import { useEffect, useState } from "react"
export type IdentityContext = { export type IdentityContext = {
member: PublicMember member: PublicMember
@ -52,7 +52,7 @@ const EventActionCommitForm = (props: {
items={EventSizeOptions} items={EventSizeOptions}
label="维修难度" label="维修难度"
size="sm" size="sm"
value={formData.size} selectedKeys={formData.size ? [formData.size] : []}
onChange={(value) => { onChange={(value) => {
setFormData({ ...formData, size: value.target.value.split(",")[0] }) setFormData({ ...formData, size: value.target.value.split(",")[0] })
}} }}
@ -94,16 +94,25 @@ export const EventActionCommit = (props: EventActionProps) => {
description: "", description: "",
}) })
useEffect(() => {
const description = props.event?.logs.findLast(v => v.action == "commit")?.description
setFormData({
size: props.event.size || "",
description: description || "",
})
}, [props.event])
const onSubmit = async () => { const onSubmit = async () => {
props.onLoading("commit") props.onLoading("commit")
const res = await fetch(`${saturdayApiBaseUrl}/member/events/${props.event.eventId}/commit`, { const res = await fetch(`${saturdayApiBaseUrl}/member/events/${props.event.eventId}/commit`, {
method: "POST", method: "POST",
headers: { headers: {
Authorization: `Bearer ${props.identityContext.token}`, Authorization: `Bearer ${props.identityContext.token}`,
ContentType: "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
size: formData.size, size: formData.size,
problem: formData.description, content: formData.description,
}), }),
}).then(res => res.json()) }).then(res => res.json())
props.onLoading() props.onLoading()
@ -128,9 +137,16 @@ export const EventActionCommit = (props: EventActionProps) => {
} }
export const EventActionAlterCommit = (props: EventActionProps) => { export const EventActionAlterCommit = (props: EventActionProps) => {
const [formData, setFormData] = useState({ const [formData, setFormData] = useState({
size: props.event.size, size: "",
description: props.event.problem, description: "",
}) })
useEffect(() => {
const description = props.event?.logs?.findLast(v => v.action == "commit" || v.action == "alterCommit")?.description
setFormData({
size: props.event.size || "",
description: description || "",
})
}, [props.event])
const onSubmit = async () => { const onSubmit = async () => {
props.onLoading("alterCommit") props.onLoading("alterCommit")
@ -138,10 +154,11 @@ export const EventActionAlterCommit = (props: EventActionProps) => {
method: "PATCH", method: "PATCH",
headers: { headers: {
Authorization: `Bearer ${props.identityContext.token}`, Authorization: `Bearer ${props.identityContext.token}`,
ContentType: "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
size: formData.size, size: formData.size,
problem: formData.description, content: formData.description,
}), }),
}).then(res => res.json()) }).then(res => res.json())
props.onLoading() props.onLoading()

View file

@ -95,11 +95,13 @@ const filterEventLog = (event: PublicEvent) => {
} }
export type EventDetailRef = { export type EventDetailRef = {
refresh: () => Promise<PublicEvent | undefined> refresh: () => Promise<PublicEvent | undefined>
event: PublicEvent | undefined
} }
const EventDetail = forwardRef<EventDetailRef, { const EventDetail = forwardRef<EventDetailRef, {
eventId?: number eventId?: number
onRefresh?: () => void onRefresh?: () => void
action?: React.ReactNode action?: React.ReactNode
children?: (event: PublicEvent) => React.ReactNode
}>((props, ref) => { }>((props, ref) => {
const [event, setEvent] = useState<PublicEvent | undefined>() const [event, setEvent] = useState<PublicEvent | undefined>()
@ -132,6 +134,7 @@ const EventDetail = forwardRef<EventDetailRef, {
// 暴露给父组件的方法 // 暴露给父组件的方法
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
refresh, refresh,
event,
})) }))
return ( return (
@ -174,6 +177,9 @@ const EventDetail = forwardRef<EventDetailRef, {
} }
</div> </div>
</div> </div>
<div>
{props.children(event)}
</div>
</section> </section>
) )
: <div></div> : <div></div>

View file

@ -144,26 +144,31 @@ function TicketDetailDrawer(props: {
{isLoading} {isLoading}
</DrawerHeader> </DrawerHeader>
<DrawerBody> <DrawerBody>
<EventDetail ref={eventDetailRef} eventId={props.event?.eventId}></EventDetail> <EventDetail ref={eventDetailRef} eventId={props.event?.eventId}>
<div className="mb-12 flex flex-col gap-2">
{ {
availableActions?.map((action) => { event => (
return ( <div className="mb-12 flex flex-col gap-2">
<action.jsxHandler {
key={action.action} availableActions?.map((action) => {
event={props.event} return (
isLoading={isLoading} <action.jsxHandler
identityContext={props.identity} key={action.action}
onUpdated={onEventUpdated} event={event}
onLoading={(action) => { isLoading={isLoading}
setIsLoading(action) identityContext={props.identity}
}} onUpdated={onEventUpdated}
> onLoading={(action) => {
</action.jsxHandler> setIsLoading(action)
) }}
}) >
</action.jsxHandler>
)
}) || <></>
}
</div>
)
} }
</div> </EventDetail>
</DrawerBody> </DrawerBody>
<DrawerFooter> <DrawerFooter>
<Button variant="flat" onPress={onClose}> <Button variant="flat" onPress={onClose}>