1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { Button , StatefulButton } from '@openedx/paragon' ;
4
- import { injectIntl , intlShape } from '@edx/frontend-platform/i18n' ;
4
+ import { useIntl } from '@edx/frontend-platform/i18n' ;
5
5
6
6
import messages from './FormControls.messages' ;
7
7
8
8
import { VisibilitySelect } from './Visibility' ;
9
9
import { useIsVisibilityEnabled } from '../../data/hooks' ;
10
10
11
11
const FormControls = ( {
12
- cancelHandler, changeHandler, visibility, visibilityId, saveState, intl,
12
+ cancelHandler,
13
+ changeHandler,
14
+ visibility = 'private' ,
15
+ visibilityId,
16
+ saveState = null ,
13
17
} ) => {
18
+ const intl = useIntl ( ) ;
14
19
const buttonState = saveState === 'error' ? null : saveState ;
15
20
const isVisibilityEnabled = useIsVisibilityEnabled ( ) ;
16
21
@@ -42,18 +47,24 @@ const FormControls = ({
42
47
type = "submit"
43
48
state = { buttonState }
44
49
labels = { {
45
- default : intl . formatMessage ( messages [ 'profile.formcontrols.button.save' ] ) ,
46
- pending : intl . formatMessage ( messages [ 'profile.formcontrols.button.saving' ] ) ,
47
- complete : intl . formatMessage ( messages [ 'profile.formcontrols.button.saved' ] ) ,
50
+ default : intl . formatMessage (
51
+ messages [ 'profile.formcontrols.button.save' ] ,
52
+ ) ,
53
+ pending : intl . formatMessage (
54
+ messages [ 'profile.formcontrols.button.saving' ] ,
55
+ ) ,
56
+ complete : intl . formatMessage (
57
+ messages [ 'profile.formcontrols.button.saved' ] ,
58
+ ) ,
48
59
} }
49
60
onClick = { ( e ) => {
50
- // Swallow clicks if the state is pending.
51
- // We do this instead of disabling the button to prevent
52
- // it from losing focus (disabled elements cannot have focus).
53
- // Disabling it would causes upstream issues in focus management.
54
- // Swallowing the onSubmit event on the form would be better, but
55
- // we would have to add that logic for every field given our
56
- // current structure of the application.
61
+ // Swallow clicks if the state is pending.
62
+ // We do this instead of disabling the button to prevent
63
+ // it from losing focus (disabled elements cannot have focus).
64
+ // Disabling it would causes upstream issues in focus management.
65
+ // Swallowing the onSubmit event on the form would be better, but
66
+ // we would have to add that logic for every field given our
67
+ // current structure of the application.
57
68
if ( buttonState === 'pending' ) {
58
69
e . preventDefault ( ) ;
59
70
}
@@ -66,19 +77,12 @@ const FormControls = ({
66
77
) ;
67
78
} ;
68
79
69
- export default injectIntl ( FormControls ) ;
80
+ export default FormControls ;
70
81
71
82
FormControls . propTypes = {
72
83
saveState : PropTypes . oneOf ( [ null , 'pending' , 'complete' , 'error' ] ) ,
73
84
visibility : PropTypes . oneOf ( [ 'private' , 'all_users' ] ) ,
74
85
visibilityId : PropTypes . string . isRequired ,
75
86
cancelHandler : PropTypes . func . isRequired ,
76
87
changeHandler : PropTypes . func . isRequired ,
77
-
78
- intl : intlShape . isRequired ,
79
- } ;
80
-
81
- FormControls . defaultProps = {
82
- visibility : 'private' ,
83
- saveState : null ,
84
88
} ;
0 commit comments