@@ -124,11 +124,10 @@ const UserList = () => {
124
124
setAmount ( ( prev ) => ( { ...prev , price : subscribe . price } ) ) ;
125
125
try {
126
126
const res = await Parse . Cloud . run ( "allowedusers" ) ;
127
- console . log ( "res " , res ) ;
128
127
setUserCounts ( ( obj ) => ( {
129
128
...obj ,
130
- allowed : res ,
131
- totalAllowed : subscribe ?. totalAllowedUser || 0
129
+ allowed : parseInt ( res ) ,
130
+ totalAllowed : parseInt ( subscribe ?. totalAllowedUser ) || 0
132
131
} ) ) ;
133
132
} catch ( err ) {
134
133
console . log ( "err while get users" , err ) ;
@@ -207,9 +206,8 @@ const UserList = () => {
207
206
return "-" ;
208
207
}
209
208
} ;
210
- const handleClose = ( ) => {
211
- setIsActiveModal ( { } ) ;
212
- } ;
209
+ const handleClose = ( ) => setIsActiveModal ( { } ) ;
210
+
213
211
const handleToggleSubmit = async ( user ) => {
214
212
const index = userList . findIndex ( ( obj ) => obj . objectId === user . objectId ) ;
215
213
if ( index !== - 1 ) {
@@ -248,16 +246,17 @@ const UserList = () => {
248
246
setIsBuyLoader ( true ) ;
249
247
try {
250
248
const resAddon = await Parse . Cloud . run ( "buyaddonusers" , {
251
- users : amount . quantity
249
+ users : parseInt ( amount . quantity )
252
250
} ) ;
253
251
if ( resAddon ) {
254
252
const _resAddon = JSON . parse ( JSON . stringify ( resAddon ) ) ;
255
253
if ( _resAddon . status === "success" ) {
256
254
setUserCounts ( ( obj ) => ( {
257
255
...obj ,
258
- allowed : obj . allowed + amount . quantity ,
259
- totalAllowed : _resAddon . addon
256
+ allowed : parseInt ( obj . allowed ) + parseInt ( amount . quantity ) ,
257
+ totalAllowed : parseInt ( _resAddon . addon )
260
258
} ) ) ;
259
+ setAmount ( ( obj ) => ( { ...obj , quantity : 1 } ) ) ;
261
260
}
262
261
}
263
262
} catch ( err ) {
@@ -274,6 +273,15 @@ const UserList = () => {
274
273
const price = e . target ?. value > 0 ? isSubscribe . priceperUser * quantity : 0 ;
275
274
setAmount ( ( prev ) => ( { ...prev , quantity : quantity , price : price } ) ) ;
276
275
} ;
276
+ const handleBuyUsers = ( allowed , totalAllowed ) => {
277
+ if ( allowed && totalAllowed ) {
278
+ setUserCounts ( ( obj ) => ( {
279
+ ...obj ,
280
+ allowed : parseInt ( obj . allowed ) + parseInt ( allowed ) ,
281
+ totalAllowed : parseInt ( totalAllowed )
282
+ } ) ) ;
283
+ }
284
+ } ;
277
285
return (
278
286
< div className = "relative" >
279
287
< Title title = { isAdmin ? "Users" : "Page not found" } />
@@ -482,6 +490,7 @@ const UserList = () => {
482
490
< AddUser
483
491
setIsAlert = { setIsAlert }
484
492
handleUserData = { handleUserData }
493
+ handleBuyUsers = { handleBuyUsers }
485
494
closePopup = { ( ) => handleModal ( "form" ) }
486
495
setFormHeader = { setFormHeader }
487
496
/>
0 commit comments