mirror of
https://github.com/m1ngsama/FUJI.git
synced 2025-12-24 10:51:27 +00:00
fix commit
This commit is contained in:
parent
b4350c9b50
commit
478a7146f5
3 changed files with 52 additions and 24 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue