Skip to content

Commit

Permalink
Feature: A new modal window for changing languages [fixes #96] (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
najeebkp authored Oct 9, 2022
1 parent 6d43fa2 commit 039d677
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 37 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
39 changes: 2 additions & 37 deletions src/pages/components/AppBarMediRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import React, { useState } from 'react';
import i18n from 'i18next';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import MenuItem from '@material-ui/core/MenuItem';
import Menu from '@material-ui/core/Menu';
import TranslateIcon from '@material-ui/icons/Translate';
import MedirepoIconW from '../../assets/medirepo-white.png';
import MedirepoIconB from '../../assets/medirepo-black.png';
import { useHistory, withRouter } from 'react-router-dom';
Expand All @@ -16,6 +12,7 @@ import { useUserDispatch, signOut, useUserState } from '../../context/UserContex
import { useDarkState } from '../../context/ThemeContext';
import { useTranslation } from 'react-i18next';
import { localesList } from '../../i18n';
import TranslateModal from './TranslateModal';

const useStyles = makeStyles((theme) => ({
img: {
Expand All @@ -36,18 +33,9 @@ function AppBarMediRepo(props) {
const history = useHistory();
const classes = useStyles();
const { t } = useTranslation();
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);

const handleMenu = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
const handleLanguage = (lang) => {
i18n.changeLanguage(lang);
handleClose();
};

return (
Expand All @@ -61,30 +49,7 @@ function AppBarMediRepo(props) {
<Typography variant="h6" className={classes.title}>
{t('medicalReport')}
</Typography>
<IconButton aria-label="Language" aria-controls="menu-appbar" aria-haspopup="true" onClick={handleMenu} color="inherit">
<TranslateIcon />
</IconButton>
<Menu
id="menu-appbar"
anchorEl={anchorEl}
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
keepMounted
transformOrigin={{
vertical: 'top',
horizontal: 'right',
}}
open={open}
onClose={handleClose}
>
{localesList.map((localesList) => (
<MenuItem key={localesList.locale} onClick={() => handleLanguage(localesList.locale)}>
{localesList.description}
</MenuItem>
))}
</Menu>
<TranslateModal localesList={localesList} onClick={handleLanguage} />
{isAuthenticated && (
<Button onClick={(e) => signOut(userDispatch, history)} color="inherit">
{t('logout')}
Expand Down
67 changes: 67 additions & 0 deletions src/pages/components/TranslateModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Modal from '@material-ui/core/Modal';
import TranslateIcon from '@material-ui/icons/Translate';
import IconButton from '@material-ui/core/IconButton';
import Button from '@material-ui/core/Button';

const useStyles = makeStyles((theme) => ({
modal: {
display: 'flex',
padding: theme.spacing(1),
alignItems: 'center',
justifyContent: 'center',
},
paper: {
width: 640,
backgroundColor: theme.palette.background.paper,
border: '2px solid #000',
boxShadow: theme.shadows[5],
padding: theme.spacing(2, 4, 3),
},
button: {
margin: '10px',
width: '100px',
cursor: 'pointer',
},
}));

function TranslateModal({ localesList, onClick }) {
const classes = useStyles();
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);

const handleChangeLang = (language) => {
onClick(language);
handleClose();
};

return (
<div>
<IconButton aria-label="Language" aria-controls="menu-appbar" aria-haspopup="true" onClick={handleOpen} color="inherit">
<TranslateIcon />
</IconButton>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="simple-modal-title"
aria-describedby="simple-modal-description"
className={classes.modal}
>
<div className={classes.paper}>
<h2 id="simple-modal-title">Select Language</h2>
<div>
{localesList.map((localesList) => (
<Button variant="outlined" key={localesList.locale} onClick={() => handleChangeLang(localesList.locale)} className={classes.button}>
{localesList.description}
</Button>
))}
</div>
</div>
</Modal>
</div>
);
}

export default TranslateModal;

1 comment on commit 039d677

@vercel
Copy link

@vercel vercel bot commented on 039d677 Oct 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

medirepo – ./

medirepo-git-main-andrgab.vercel.app
medirepo-andrgab.vercel.app
medirepo.vercel.app

Please sign in to comment.