1+ import { useState } from "react" ;
12import Dots from "../common/Dots" ;
23import UserAvatar from "./avatar" ;
34
@@ -9,12 +10,12 @@ type HumanListItemProps = {
910 rollUpName ?: boolean ; // is currently only intended to be used in Chat
1011 unreadCount ?: number ; // only intended to be used in chat
1112 statusMessage ?: string ;
12- onDelete ?: ( id : number ) => void ;
13+ onDelete ?: ( id : number ) => Promise < void > ;
1314 onOpen ?: ( user : { id : number ; name : string ; pictureUrl : string } ) => void ;
14- onAccept ?: ( id : number ) => void ;
15- onReject ?: ( id : number ) => void ;
16- onCancel ?: ( id : number ) => void ;
17- onRequest ?: ( id : number ) => void ;
15+ onAccept ?: ( id : number ) => Promise < void > ;
16+ onReject ?: ( id : number ) => Promise < void > ;
17+ onCancel ?: ( id : number ) => Promise < void > ;
18+ onRequest ?: ( id : number ) => Promise < void > ;
1819 hasDots ?: boolean ;
1920 dotsActions ?: object ;
2021} ;
@@ -73,46 +74,36 @@ export function HumanListItem(props: HumanListItemProps) {
7374 < span className = "badge badge-primary" > { unreadCount } </ span >
7475 ) : undefined }
7576 { onAccept && (
76- < button
77- type = "button"
77+ < ActionButton
7878 className = "btn btn-primary btn-sm m-1"
79- onClick = { ( e ) => {
80- e . stopPropagation ( ) ;
81- onAccept ( id ) ;
82- } }
79+ onClick = { async ( ) => await onAccept ( id ) }
8380 >
8481 承認
85- </ button >
82+ </ ActionButton >
8683 ) }
8784 { onReject && (
88- < button
89- type = "button"
85+ < ActionButton
9086 className = "btn btn-sm m-1"
91- onClick = { ( e ) => {
92- e . stopPropagation ( ) ;
93- onReject ( id ) ;
94- } }
87+ onClick = { async ( ) => await onReject ( id ) }
9588 >
9689 拒否
97- </ button >
90+ </ ActionButton >
9891 ) }
9992 { onCancel && (
100- < button
101- type = "button"
93+ < ActionButton
10294 className = "btn btn-sm m-1"
103- onClick = { ( ) => onCancel ( id ) }
95+ onClick = { async ( ) => await onCancel ( id ) }
10496 >
10597 キャンセル
106- </ button >
98+ </ ActionButton >
10799 ) }
108100 { onRequest && (
109- < button
110- type = "button"
101+ < ActionButton
111102 className = "btn btn-sm m-1 bg-primary text-white"
112- onClick = { ( ) => onRequest ( id ) }
103+ onClick = { async ( ) => await onRequest ( id ) }
113104 >
114105 リクエスト
115- </ button >
106+ </ ActionButton >
116107 ) }
117108 { hasDots && (
118109 < Dots
@@ -141,3 +132,32 @@ export function HumanListItem(props: HumanListItemProps) {
141132 </ div >
142133 ) ;
143134}
135+
136+ export function ActionButton ( {
137+ onClick,
138+ className,
139+ children,
140+ } : {
141+ onClick : ( ) => Promise < void > ;
142+ className : string ;
143+ children : string ; // change this to React.Element or something if you want to put something other than text in here
144+ } ) {
145+ const [ inProgress , setInProgress ] = useState < boolean > ( false ) ;
146+ return inProgress ? (
147+ < button type = "button" className = { className } disabled >
148+ < span className = "loading loading-spinner" />
149+ </ button >
150+ ) : (
151+ < button
152+ type = "button"
153+ className = { className }
154+ onClick = { async ( e ) => {
155+ e . stopPropagation ( ) ;
156+ setInProgress ( true ) ;
157+ await onClick ( ) ;
158+ } }
159+ >
160+ { children }
161+ </ button >
162+ ) ;
163+ }
0 commit comments