-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(next): update ticket title and content (#957)
- Loading branch information
Showing
9 changed files
with
174 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
next/web/src/App/Admin/Tickets/Ticket/components/TicketCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { useState } from 'react'; | ||
import { useToggle } from 'react-use'; | ||
import { Input, Modal } from 'antd'; | ||
|
||
import { UserLabel, UserLabelProps } from '@/App/Admin/components/UserLabel'; | ||
import { ReplyCard, ReplyCardProps } from './ReplyCard'; | ||
import { MarkdownEditor } from './ReplyEditor'; | ||
|
||
interface UpdateData { | ||
title: string; | ||
content: string; | ||
} | ||
|
||
export interface TicketCardProps { | ||
ticket: { | ||
id: string; | ||
author?: UserLabelProps['user']; | ||
authorId: string; | ||
createdAt: string; | ||
title: string; | ||
content: string; | ||
contentSafeHTML: string; | ||
files?: ReplyCardProps['files']; | ||
}; | ||
updateable?: boolean; | ||
onUpdate?: (data: UpdateData) => void | Promise<void>; | ||
} | ||
|
||
export function TicketCard({ ticket, updateable, onUpdate }: TicketCardProps) { | ||
const [editModalOpen, toggleEditModal] = useToggle(false); | ||
const [tempTitle, setTempTitle] = useState(''); | ||
const [tempContent, setTempContent] = useState(''); | ||
const [isUpdating, setIsUpdating] = useState(false); | ||
|
||
const handleEdit = () => { | ||
setTempTitle(ticket.title); | ||
setTempContent(ticket.content); | ||
toggleEditModal(); | ||
}; | ||
|
||
const handleUpdate = async () => { | ||
if (isUpdating || !onUpdate) { | ||
return; | ||
} | ||
setIsUpdating(true); | ||
try { | ||
await onUpdate({ title: tempTitle, content: tempContent }); | ||
toggleEditModal(false); | ||
} finally { | ||
setIsUpdating(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<ReplyCard | ||
id={ticket.id} | ||
author={ticket.author ? <UserLabel user={ticket.author} /> : 'unknown'} | ||
createTime={ticket.createdAt} | ||
content={ticket.contentSafeHTML} | ||
files={ticket.files} | ||
menuItems={ | ||
updateable | ||
? [ | ||
{ | ||
key: 'edit', | ||
label: '编辑', | ||
onClick: handleEdit, | ||
}, | ||
] | ||
: undefined | ||
} | ||
/> | ||
|
||
<Modal | ||
open={editModalOpen} | ||
width={650} | ||
title="编辑标题和内容" | ||
onCancel={toggleEditModal} | ||
onOk={handleUpdate} | ||
confirmLoading={isUpdating} | ||
> | ||
<Input | ||
placeholder="标题" | ||
value={tempTitle} | ||
onChange={(e) => setTempTitle(e.target.value)} | ||
style={{ marginBottom: 20 }} | ||
/> | ||
<MarkdownEditor value={tempContent} onChange={setTempContent} onSubmit={handleUpdate} /> | ||
</Modal> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.