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

View file

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

View file

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