@@ -22,15 +22,6 @@ interface IProps {
2222}
2323
2424const Settings = observer ( ( { themeMode, setTheme} : IProps ) => {
25- const [ pass , setPass ] = useState ( '' ) ;
26- const { currentUser, elevateStore} = useStores ( ) ;
27- const localAuthEnabled = config . get ( 'localAuth' ) ;
28-
29- const submit = ( ) => {
30- currentUser . changePassword ( pass ) ;
31- setPass ( '' ) ;
32- } ;
33-
3425 return (
3526 < DefaultPage title = "Settings" maxWidth = { 400 } >
3627 < Grid size = { { xs : 12 } } >
@@ -54,54 +45,67 @@ const Settings = observer(({themeMode, setTheme}: IProps) => {
5445 </ Paper >
5546 </ Grid >
5647 < Grid size = { { xs : 12 } } >
57- < Paper elevation = { 6 } sx = { { padding : 2 } } id = "changepw-form" >
48+ < Paper elevation = { 6 } sx = { { padding : 2 } } >
5849 < Typography variant = "h6" sx = { { marginBottom : 2 } } >
5950 Change Password
6051 </ Typography >
61- { localAuthEnabled && ! elevateStore . elevated ? (
62- < ElevationForm />
63- ) : (
64- < form
65- onSubmit = { ( e ) => {
66- e . preventDefault ( ) ;
67- submit ( ) ;
68- } } >
69- < TextField
70- className = "newpass"
71- margin = "dense"
72- type = "password"
73- label = "New Password *"
74- value = { pass }
75- disabled = { ! localAuthEnabled }
76- onChange = { ( e ) => setPass ( e . target . value ) }
77- fullWidth
78- />
79- < Tooltip
80- title = {
81- ! localAuthEnabled
82- ? 'Password login is disabled on this server.'
83- : pass . length !== 0
84- ? ''
85- : 'Password is required'
86- } >
87- < div >
88- < Button
89- className = "change"
90- type = "submit"
91- disabled = { ! localAuthEnabled || pass . length === 0 }
92- color = "primary"
93- variant = "contained"
94- fullWidth >
95- Change
96- </ Button >
97- </ div >
98- </ Tooltip >
99- </ form >
100- ) }
52+ < ChangePasswordForm />
10153 </ Paper >
10254 </ Grid >
10355 </ DefaultPage >
10456 ) ;
10557} ) ;
10658
59+ const ChangePasswordForm = ( ) => {
60+ const [ pass , setPass ] = useState ( '' ) ;
61+ const { currentUser, elevateStore} = useStores ( ) ;
62+ const localAuthEnabled = config . get ( 'localAuth' ) ;
63+
64+ const submit = ( ) => {
65+ currentUser . changePassword ( pass ) ;
66+ setPass ( '' ) ;
67+ } ;
68+
69+ if ( ! localAuthEnabled ) {
70+ return < Typography > Password login is disabled on this server.</ Typography > ;
71+ }
72+
73+ if ( ! elevateStore . elevated ) {
74+ return < ElevationForm /> ;
75+ }
76+
77+ return (
78+ < form
79+ id = "changepw-form"
80+ onSubmit = { ( e ) => {
81+ e . preventDefault ( ) ;
82+ submit ( ) ;
83+ } } >
84+ < TextField
85+ className = "newpass"
86+ margin = "dense"
87+ type = "password"
88+ label = "New Password *"
89+ value = { pass }
90+ disabled = { ! localAuthEnabled }
91+ onChange = { ( e ) => setPass ( e . target . value ) }
92+ fullWidth
93+ />
94+ < Tooltip title = { pass . length !== 0 ? '' : 'Password is required' } >
95+ < div >
96+ < Button
97+ className = "change"
98+ type = "submit"
99+ disabled = { ! localAuthEnabled || pass . length === 0 }
100+ color = "primary"
101+ variant = "contained"
102+ fullWidth >
103+ Change
104+ </ Button >
105+ </ div >
106+ </ Tooltip >
107+ </ form >
108+ ) ;
109+ } ;
110+
107111export default Settings ;
0 commit comments