diff --git a/frontend-react/src/App.js b/frontend-react/src/App.js index fc03c01..986869d 100644 --- a/frontend-react/src/App.js +++ b/frontend-react/src/App.js @@ -5,78 +5,86 @@ import { Switch, Route, Link } from 'react-router-dom'; +import {FormattedMessage, IntlProvider} from 'react-intl'; import GlobalContext from './GlobalContext'; import PeopleIndex from "./views/People/PeopleIndex"; import PeopleAdd from "./views/People/PeopleAdd"; import PeopleEdit from "./views/People/PeopleEdit"; import {PeopleService} from "./views/People/PeopleService"; +import messages from './locale/messages'; + +const defaultLocale = 'en'; function App() { + // this should be read from for example local storage and should be changeable. For now it's fixed. + const currentLocale = 'en'; return ( - -
- - + + + + + + + + }/> + + + + + 404 page + + + +
+
+ ); } diff --git a/frontend-react/src/locale/en.json b/frontend-react/src/locale/en.json new file mode 100644 index 0000000..cef5378 --- /dev/null +++ b/frontend-react/src/locale/en.json @@ -0,0 +1,22 @@ +{ + "app.navbar.banner": "People Management Limited", + "app.navbar.home": "Home", + "app.navbar.person.add": "Add person", + "app.navbar.signup": "Sign up", + "app.navbar.login": "Log in", + "people.index.table.id.header": "Id", + "people.index.table.firstName.header": "First name", + "people.index.table.lastName.header": "Last name", + "people.index.table.email.header": "E-mail", + "people.index.table.status.header": "Status", + "people.index.table.status.value.active": "Active", + "people.index.table.status.value.inactive": "Inactive", + "people.form.person.not.available": "Sorry, the person with id {personId} is not available", + "people.form.firstName.label": "First name", + "people.form.lastName.label": "Last name", + "people.form.email.label": "E-mail", + "people.form.status.label": "Status", + "people.form.status.value.active": "Active", + "people.form.status.value.inactive": "Inactive", + "people.form.submit.label": "Submit" +} diff --git a/frontend-react/src/locale/messages.js b/frontend-react/src/locale/messages.js new file mode 100644 index 0000000..0cf216c --- /dev/null +++ b/frontend-react/src/locale/messages.js @@ -0,0 +1,7 @@ +import enMessages from './en.json'; + +let messages = { + "en": enMessages +}; + +export default messages; diff --git a/frontend-react/src/views/People/PeopleForm.jsx b/frontend-react/src/views/People/PeopleForm.jsx index 0d4196c..e762263 100644 --- a/frontend-react/src/views/People/PeopleForm.jsx +++ b/frontend-react/src/views/People/PeopleForm.jsx @@ -3,6 +3,7 @@ import {useHistory} from 'react-router-dom'; import {isValidEmail, validateForm} from "../../utils/validators"; import GlobalContext from "../../GlobalContext"; import classNames from 'classnames'; +import {useIntl} from "react-intl"; const personValidators = { email: [isValidEmail] @@ -17,6 +18,7 @@ export function PeopleForm(params) { status: 0 }); + const {formatMessage} = useIntl(); const history = useHistory(); const {peopleService} = useContext(GlobalContext); let [errors, setErrors] = useState(validateForm(personValidators, formData)); @@ -83,11 +85,12 @@ export function PeopleForm(params) { return (loading ?
: (personNotAvailable && personId) - ?
Sorry, the person with id {personId} is not available
+ ?
{formatMessage({id: 'people.form.person.not.available'}, {personId: personId})}
:
- +
@@ -97,7 +100,7 @@ export function PeopleForm(params) { name="firstName" type="text" className={classNames("input", {'is-danger': errors.firstName})} - placeholder="First name" + placeholder={formatMessage({id: 'people.form.firstName.label'})} value={formData?.firstName} onInput={onInputChange} /> @@ -108,7 +111,8 @@ export function PeopleForm(params) {
- +
@@ -118,7 +122,7 @@ export function PeopleForm(params) { name="lastName" type="text" className={classNames("input", {'is-danger': errors.lastName})} - placeholder="Last name" + placeholder={formatMessage({id: 'people.form.lastName.label'})} value={formData?.lastName} onInput={onInputChange} /> @@ -129,7 +133,8 @@ export function PeopleForm(params) {
- +
@@ -139,7 +144,7 @@ export function PeopleForm(params) { name="email" type="text" className={classNames("input", {'is-danger': errors.email})} - placeholder="E-mail" + placeholder={formatMessage({id: 'people.form.email.label'})} value={formData?.email} onInput={onInputChange} /> @@ -150,7 +155,8 @@ export function PeopleForm(params) {
- +
@@ -162,8 +168,10 @@ export function PeopleForm(params) { className={classNames("input", {'is-danger': errors.status})} value={formData?.status} onInput={onInputChange}> - - + +
@@ -173,9 +181,10 @@ export function PeopleForm(params) {
-
) -}; +} diff --git a/frontend-react/src/views/People/PeopleIndex.jsx b/frontend-react/src/views/People/PeopleIndex.jsx index 43f6718..ad44e6f 100644 --- a/frontend-react/src/views/People/PeopleIndex.jsx +++ b/frontend-react/src/views/People/PeopleIndex.jsx @@ -1,5 +1,6 @@ import "bulma"; import {useContext, useEffect, useState} from "react"; +import {FormattedMessage, useIntl} from 'react-intl'; import {useHistory} from 'react-router-dom'; import GlobalContext from "../../GlobalContext"; @@ -7,6 +8,8 @@ export default function PeopleIndex() { const {peopleService} = useContext(GlobalContext); const [people, setPeople] = useState([]); const history = useHistory(); + const {formatMessage} = useIntl(); + useEffect(() => { peopleService.getAllPeople() .then(people => { @@ -22,11 +25,11 @@ export default function PeopleIndex() { - - - - - + + + + + @@ -36,7 +39,9 @@ export default function PeopleIndex() { - + )}
IdFirst nameLast nameE-mailStatus
{it.firstName} {it.lastName} {it.email}{it.status === 0 ? 'Active' : 'Inactive'}{it.status === 0 + ? formatMessage({id: 'people.index.table.status.value.active'}) + : formatMessage({id: 'people.index.table.status.value.inactive'})}