File tree Expand file tree Collapse file tree 4 files changed +22
-9
lines changed Expand file tree Collapse file tree 4 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 1- import { useContext } from 'react' ;
1+ import { useContext , useState } from 'react' ;
22import { useToastBarDispatch } from '@embeddedchat/ui-elements' ;
33import RCContext from '../context/RCInstance' ;
44import {
@@ -10,6 +10,7 @@ import {
1010
1111export const useRCAuth = ( ) => {
1212 const { RCInstance } = useContext ( RCContext ) ;
13+ const [ loading , setLoading ] = useState ( false ) ;
1314 const setIsTotpModalOpen = totpModalStore (
1415 ( state ) => state . setIsTotpModalOpen
1516 ) ;
@@ -34,6 +35,7 @@ export const useRCAuth = () => {
3435 const dispatchToastMessage = useToastBarDispatch ( ) ;
3536
3637 const handleLogin = async ( userOrEmail , password , code ) => {
38+ setLoading ( true ) ;
3739 try {
3840 const res = await RCInstance . login ( userOrEmail , password , code ) ;
3941 const permissions = await RCInstance . permissionInfo ( ) ;
@@ -78,10 +80,13 @@ export const useRCAuth = () => {
7880 }
7981 } catch ( e ) {
8082 console . error ( 'A error occurred while setting up user' , e ) ;
83+ } finally {
84+ setLoading ( false ) ;
8185 }
8286 } ;
8387
8488 return {
8589 handleLogin,
90+ loading,
8691 } ;
8792} ;
Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ import {
2424} from '../../store' ;
2525import MessageList from '../MessageList' ;
2626import TotpModal from '../TotpModal/TwoFactorTotpModal' ;
27- import { useRCAuth } from '../../hooks/useRCAuth' ;
2827import LoginForm from '../LoginForm/LoginForm' ;
2928import ThreadMessageList from '../Thread/ThreadMessageList' ;
3029import RecentMessageButton from './RecentMessageButton' ;
@@ -75,7 +74,6 @@ const ChatBody = ({
7574 uiKitModalData : state . uiKitModalData ,
7675 } ) ) ;
7776
78- const { handleLogin } = useRCAuth ( ) ;
7977 const { handleServerInteraction } = useUiKitActionManager ( ) ;
8078
8179 const isUserAuthenticated = useUserStore (
@@ -365,7 +363,7 @@ const ChatBody = ({
365363 />
366364 ) }
367365
368- < TotpModal handleLogin = { handleLogin } />
366+ < TotpModal />
369367 < LoginForm />
370368
371369 { uiKitModalOpen && (
Original file line number Diff line number Diff line change 77 Input ,
88 Icon ,
99 useTheme ,
10+ Throbber ,
1011} from '@embeddedchat/ui-elements' ;
1112import { useLoginStore } from '../../store' ;
1213import { useRCAuth } from '../../hooks/useRCAuth' ;
@@ -22,7 +23,7 @@ export default function LoginForm() {
2223 const setIsLoginModalOpen = useLoginStore (
2324 ( state ) => state . setIsLoginModalOpen
2425 ) ;
25- const { handleLogin } = useRCAuth ( ) ;
26+ const { handleLogin, loading } = useRCAuth ( ) ;
2627
2728 const { theme } = useTheme ( ) ;
2829
@@ -132,11 +133,12 @@ export default function LoginForm() {
132133 < Button
133134 type = "primary"
134135 onClick = { handleSubmit }
136+ disabled = { loading }
135137 css = { css `
136138 margin : 10px 0 ;
137139 ` }
138140 >
139- Login
141+ { loading ? < Throbber /> : ' Login' }
140142 </ Button >
141143 </ Box >
142144 </ GenericModal >
Original file line number Diff line number Diff line change @@ -7,10 +7,13 @@ import {
77 Modal ,
88 Input ,
99 Button ,
10+ Throbber ,
1011} from '@embeddedchat/ui-elements' ;
1112import { totpModalStore , useUserStore } from '../../store' ;
13+ import { useRCAuth } from '../../hooks/useRCAuth' ;
1214
13- export default function TotpModal ( { handleLogin } ) {
15+ export default function TotpModal ( ) {
16+ let { handleLogin, loading } = useRCAuth ( ) ;
1417 const [ accessCode , setAccessCode ] = useState ( null ) ;
1518 const isTotpModalOpen = totpModalStore ( ( state ) => state . isTotpModalOpen ) ;
1619 const setIsTotpModalOpen = totpModalStore (
@@ -55,8 +58,13 @@ export default function TotpModal({ handleLogin }) {
5558 < Button type = "secondary" onClick = { handleClose } >
5659 Cancel
5760 </ Button >
58- < Button type = "primary" onClick = { handleSubmit } >
59- Submit
61+ < Button
62+ type = "primary"
63+ onClick = { handleSubmit }
64+ disabled = { loading }
65+ style = { { height : '36px' } }
66+ >
67+ { loading ? < Throbber /> : "Submit" }
6068 </ Button >
6169 </ Modal . Footer >
6270 </ Box >
You can’t perform that action at this time.
0 commit comments