File tree Expand file tree Collapse file tree
framework/core/js/src/admin/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,13 +8,15 @@ import type Mithril from 'mithril';
88import Switch from '../../common/components/Switch' ;
99import { generateRandomString } from '../../common/utils/string' ;
1010import Form from '../../common/components/Form' ;
11+ import type User from '../../common/models/User' ;
1112
1213export interface ICreateUserModalAttrs extends IFormModalAttrs {
1314 username ?: string ;
1415 email ?: string ;
1516 password ?: string ;
1617 token ?: string ;
1718 provided ?: string [ ] ;
19+ onCreated ?: ( user : User ) => void ;
1820}
1921
2022export type SignupBody = {
@@ -208,17 +210,17 @@ export default class CreateUserModal<CustomAttrs extends ICreateUserModalAttrs =
208210 this . loading = true ;
209211
210212 app . store
211- . createRecord ( 'users' , { } )
213+ . createRecord < User > ( 'users' , { } )
212214 . save ( this . submitData ( ) , {
213215 errorHandler : this . onerror . bind ( this ) ,
214216 } )
215- . then ( ( ) => {
217+ . then ( ( createdUser ) => {
216218 if ( this . bulkAdd ( ) ) {
217219 this . resetData ( ) ;
218220 } else {
219221 this . hide ( ) ;
220222 }
221-
223+ this . attrs . onCreated ?. ( createdUser ) ;
222224 this . alertAttrs = null ;
223225 } )
224226 . finally ( ( ) => {
Original file line number Diff line number Diff line change @@ -62,15 +62,13 @@ export default class UserListPage extends AdminPage {
6262 * data provided by `AdminPayload.php`, or `flarum/statistics`
6363 * if installed.
6464 */
65- readonly userCount : number = app . data . modelStatistics . users . total ;
65+ private userCount : number = app . data . modelStatistics . users . total ;
6666
6767 /**
6868 * Get total number of user pages.
6969 */
7070 private getTotalPageCount ( ) : number {
71- if ( this . userCount === - 1 ) return 0 ;
72-
73- return Math . ceil ( this . userCount / this . numPerPage ) ;
71+ return Math . max ( 1 , Math . ceil ( Math . max ( 0 , this . userCount ) / this . numPerPage ) ) ;
7472 }
7573
7674 /**
@@ -207,7 +205,22 @@ export default class UserListPage extends AdminPage {
207205
208206 items . add (
209207 'createUser' ,
210- < Button className = "Button UserListPage-createUserBtn" icon = "fas fa-user-plus" onclick = { ( ) => app . modal . show ( CreateUserModal ) } >
208+ < Button
209+ className = "Button UserListPage-createUserBtn"
210+ icon = "fas fa-user-plus"
211+ onclick = { ( ) =>
212+ app . modal . show ( CreateUserModal , {
213+ onCreated : ( user : User ) => {
214+ this . userCount ++ ;
215+ if ( app . data ?. modelStatistics ?. users ) {
216+ app . data . modelStatistics . users . total = this . userCount ;
217+ }
218+ this . isLoadingPage = true ;
219+ this . loadPage ( this . pageNumber ) ;
220+ } ,
221+ } )
222+ }
223+ >
211224 { app . translator . trans ( 'core.admin.users.create_user_button' ) }
212225 </ Button > ,
213226 100
You can’t perform that action at this time.
0 commit comments