1- import React , { Component } from 'react' ;
1+ import { useContext , useEffect } from 'react' ;
22import { Link } from 'react-router-dom' ;
33
4- import { injectIntl , intlShape } from '@edx/frontend-platform/i18n' ;
4+ /* eslint-disable import/no-extraneous-dependencies */
5+ import { injectIntl , useIntl } from '@edx/frontend-platform/i18n' ;
56import { logInfo } from '@edx/frontend-platform/logging' ;
67import { AppContext } from '@edx/frontend-platform/react' ;
78import { ensureConfig , mergeConfig , getConfig } from '@edx/frontend-platform' ;
9+ /* eslint-enable import/no-extraneous-dependencies */
810import messages from './messages' ;
911
1012mergeConfig ( {
@@ -16,48 +18,41 @@ ensureConfig([
1618 'JS_FILE_VAR' ,
1719] , 'ExamplePage' ) ;
1820
19- class ExamplePage extends Component {
20- constructor ( props , context ) {
21- super ( props , context ) ;
22-
23- logInfo ( 'The example page can log info, which means logging is configured correctly.' ) ;
24- }
25-
26- renderAuthenticatedUser ( ) {
27- if ( this . context . authenticatedUser === null ) {
28- return null ;
29- }
30- return (
31- < div >
32- < p > Authenticated Username: < strong > { this . context . authenticatedUser . username } </ strong > </ p >
33- < p >
34- Authenticated user's name:
35- < strong > { this . context . authenticatedUser . name } </ strong >
36- (Only available if user account has been fetched)
37- </ p >
38- </ div >
39- ) ;
40- }
41-
42- render ( ) {
43- return (
44- < div >
45- < h1 > { this . context . config . SITE_NAME } example page.</ h1 >
46- < p > { this . props . intl . formatMessage ( messages [ 'example.message' ] ) } </ p >
47- { this . renderAuthenticatedUser ( ) }
48- < p > EXAMPLE_VAR env var came through: < strong > { getConfig ( ) . EXAMPLE_VAR } </ strong > </ p >
49- < p > JS_FILE_VAR var came through: < strong > { getConfig ( ) . JS_FILE_VAR } </ strong > </ p >
50- < p > Visit < Link to = "/authenticated" > authenticated page</ Link > .</ p >
51- < p > Visit < Link to = "/error_example" > error page</ Link > .</ p >
52- </ div >
53- ) ;
21+ function AuthenticatedUser ( ) {
22+ const { authenticatedUser } = useContext ( AppContext ) ;
23+ if ( authenticatedUser === null ) {
24+ return null ;
5425 }
26+ return (
27+ < div >
28+ < p > Authenticated Username: < strong > { authenticatedUser . username } </ strong > </ p >
29+ < p >
30+ Authenticated user's name:
31+ < strong > { authenticatedUser . name } </ strong >
32+ (Only available if user account has been fetched)
33+ </ p >
34+ </ div >
35+ ) ;
5536}
5637
57- ExamplePage . contextType = AppContext ;
38+ function ExamplePage ( ) {
39+ const intl = useIntl ( ) ;
5840
59- ExamplePage . propTypes = {
60- intl : intlShape . isRequired ,
61- } ;
41+ useEffect ( ( ) => {
42+ logInfo ( 'The example page can log info, which means logging is configured correctly.' ) ;
43+ } , [ ] ) ;
44+
45+ return (
46+ < div >
47+ < h1 > { getConfig ( ) . SITE_NAME } example page.</ h1 >
48+ < p > { intl . formatMessage ( messages [ 'example.message' ] ) } </ p >
49+ < AuthenticatedUser />
50+ < p > EXAMPLE_VAR env var came through: < strong > { getConfig ( ) . EXAMPLE_VAR } </ strong > </ p >
51+ < p > JS_FILE_VAR var came through: < strong > { getConfig ( ) . JS_FILE_VAR } </ strong > </ p >
52+ < p > Visit < Link to = "/authenticated" > authenticated page</ Link > .</ p >
53+ < p > Visit < Link to = "/error_example" > error page</ Link > .</ p >
54+ </ div >
55+ ) ;
56+ }
6257
6358export default injectIntl ( ExamplePage ) ;
0 commit comments