11import React from 'react' ;
22import PropTypes from 'prop-types' ;
33import { Button , StatefulButton } from '@openedx/paragon' ;
4- import { injectIntl , intlShape } from '@edx/frontend-platform/i18n' ;
4+ import { useIntl } from '@edx/frontend-platform/i18n' ;
55
66import messages from './FormControls.messages' ;
77
88import { VisibilitySelect } from './Visibility' ;
99import { useIsVisibilityEnabled } from '../../data/hooks' ;
1010
1111const FormControls = ( {
12- cancelHandler, changeHandler, visibility, visibilityId, saveState, intl,
12+ cancelHandler,
13+ changeHandler,
14+ visibility = 'private' ,
15+ visibilityId,
16+ saveState = null ,
1317} ) => {
18+ const intl = useIntl ( ) ;
1419 const buttonState = saveState === 'error' ? null : saveState ;
1520 const isVisibilityEnabled = useIsVisibilityEnabled ( ) ;
1621
@@ -42,18 +47,24 @@ const FormControls = ({
4247 type = "submit"
4348 state = { buttonState }
4449 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+ ) ,
4859 } }
4960 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.
5768 if ( buttonState === 'pending' ) {
5869 e . preventDefault ( ) ;
5970 }
@@ -66,19 +77,12 @@ const FormControls = ({
6677 ) ;
6778} ;
6879
69- export default injectIntl ( FormControls ) ;
80+ export default FormControls ;
7081
7182FormControls . propTypes = {
7283 saveState : PropTypes . oneOf ( [ null , 'pending' , 'complete' , 'error' ] ) ,
7384 visibility : PropTypes . oneOf ( [ 'private' , 'all_users' ] ) ,
7485 visibilityId : PropTypes . string . isRequired ,
7586 cancelHandler : PropTypes . func . isRequired ,
7687 changeHandler : PropTypes . func . isRequired ,
77-
78- intl : intlShape . isRequired ,
79- } ;
80-
81- FormControls . defaultProps = {
82- visibility : 'private' ,
83- saveState : null ,
8488} ;
0 commit comments