@@ -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 } } >
@@ -58,50 +49,62 @@ const Settings = observer(({themeMode, setTheme}: IProps) => {
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+ onSubmit = { ( e ) => {
80+ e . preventDefault ( ) ;
81+ submit ( ) ;
82+ } } >
83+ < TextField
84+ className = "newpass"
85+ margin = "dense"
86+ type = "password"
87+ label = "New Password *"
88+ value = { pass }
89+ disabled = { ! localAuthEnabled }
90+ onChange = { ( e ) => setPass ( e . target . value ) }
91+ fullWidth
92+ />
93+ < Tooltip title = { pass . length !== 0 ? '' : 'Password is required' } >
94+ < div >
95+ < Button
96+ className = "change"
97+ type = "submit"
98+ disabled = { ! localAuthEnabled || pass . length === 0 }
99+ color = "primary"
100+ variant = "contained"
101+ fullWidth >
102+ Change
103+ </ Button >
104+ </ div >
105+ </ Tooltip >
106+ </ form >
107+ ) ;
108+ } ;
109+
107110export default Settings ;
0 commit comments