mirror of
https://github.com/m1ngsama/FUJI.git
synced 2025-12-25 02:56:38 +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 { 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()
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -144,14 +144,16 @@ function TicketDetailDrawer(props: {
|
||||||
{isLoading}
|
{isLoading}
|
||||||
</DrawerHeader>
|
</DrawerHeader>
|
||||||
<DrawerBody>
|
<DrawerBody>
|
||||||
<EventDetail ref={eventDetailRef} eventId={props.event?.eventId}></EventDetail>
|
<EventDetail ref={eventDetailRef} eventId={props.event?.eventId}>
|
||||||
|
{
|
||||||
|
event => (
|
||||||
<div className="mb-12 flex flex-col gap-2">
|
<div className="mb-12 flex flex-col gap-2">
|
||||||
{
|
{
|
||||||
availableActions?.map((action) => {
|
availableActions?.map((action) => {
|
||||||
return (
|
return (
|
||||||
<action.jsxHandler
|
<action.jsxHandler
|
||||||
key={action.action}
|
key={action.action}
|
||||||
event={props.event}
|
event={event}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
identityContext={props.identity}
|
identityContext={props.identity}
|
||||||
onUpdated={onEventUpdated}
|
onUpdated={onEventUpdated}
|
||||||
|
|
@ -161,9 +163,12 @@ function TicketDetailDrawer(props: {
|
||||||
>
|
>
|
||||||
</action.jsxHandler>
|
</action.jsxHandler>
|
||||||
)
|
)
|
||||||
})
|
}) || <></>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</EventDetail>
|
||||||
</DrawerBody>
|
</DrawerBody>
|
||||||
<DrawerFooter>
|
<DrawerFooter>
|
||||||
<Button variant="flat" onPress={onClose}>
|
<Button variant="flat" onPress={onClose}>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue