forked from Mirrors/gomuks
web/timeline: use form for confirmation modals
This commit is contained in:
parent
83a4df9375
commit
9cae8701e5
2 changed files with 8 additions and 7 deletions
|
@ -13,7 +13,7 @@
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
import { use, useCallback, useState } from "react"
|
import React, { use, useCallback, useState } from "react"
|
||||||
import { MemDBEvent } from "@/api/types"
|
import { MemDBEvent } from "@/api/types"
|
||||||
import useEvent from "@/util/useEvent.ts"
|
import useEvent from "@/util/useEvent.ts"
|
||||||
import { ModalCloseContext } from "../../modal/Modal.tsx"
|
import { ModalCloseContext } from "../../modal/Modal.tsx"
|
||||||
|
@ -33,14 +33,15 @@ const ConfirmWithMessageModal = ({
|
||||||
}: ConfirmWithMessageProps) => {
|
}: ConfirmWithMessageProps) => {
|
||||||
const [reason, setReason] = useState("")
|
const [reason, setReason] = useState("")
|
||||||
const closeModal = use(ModalCloseContext)
|
const closeModal = use(ModalCloseContext)
|
||||||
const onConfirmWrapped = useEvent(() => {
|
const onConfirmWrapped = useEvent((evt: React.FormEvent) => {
|
||||||
|
evt.preventDefault()
|
||||||
closeModal()
|
closeModal()
|
||||||
onConfirm(reason)
|
onConfirm(reason)
|
||||||
})
|
})
|
||||||
const onChangeReason = useCallback((evt: React.ChangeEvent<HTMLInputElement>) => {
|
const onChangeReason = useCallback((evt: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setReason(evt.target.value)
|
setReason(evt.target.value)
|
||||||
}, [])
|
}, [])
|
||||||
return <>
|
return <form onSubmit={onConfirmWrapped}>
|
||||||
<h3>{title}</h3>
|
<h3>{title}</h3>
|
||||||
<div className="timeline-event-container">
|
<div className="timeline-event-container">
|
||||||
<TimelineEvent evt={evt} prevEvt={null} disableMenu={true} />
|
<TimelineEvent evt={evt} prevEvt={null} disableMenu={true} />
|
||||||
|
@ -50,10 +51,10 @@ const ConfirmWithMessageModal = ({
|
||||||
</div>
|
</div>
|
||||||
<input autoFocus value={reason} type="text" placeholder={placeholder} onChange={onChangeReason} />
|
<input autoFocus value={reason} type="text" placeholder={placeholder} onChange={onChangeReason} />
|
||||||
<div className="confirm-buttons">
|
<div className="confirm-buttons">
|
||||||
<button onClick={closeModal}>Cancel</button>
|
<button type="button" onClick={closeModal}>Cancel</button>
|
||||||
<button onClick={onConfirmWrapped}>{confirmButton}</button>
|
<button type="submit">{confirmButton}</button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</form>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ConfirmWithMessageModal
|
export default ConfirmWithMessageModal
|
||||||
|
|
|
@ -45,7 +45,7 @@ div.event-context-menu-extra {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
div.confirm-message-modal {
|
div.confirm-message-modal > form {
|
||||||
width: min(40rem, 80vw);
|
width: min(40rem, 80vw);
|
||||||
max-height: min(40rem, 80vh);
|
max-height: min(40rem, 80vh);
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
Loading…
Add table
Reference in a new issue