Skip to content

Commit 2fffade

Browse files
committed
add language picker for auth forms
1 parent 8aa205c commit 2fffade

File tree

10 files changed

+102
-58
lines changed

10 files changed

+102
-58
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
API_URL=https://forautobackend.herokuapp.com
2-
API_URL_b=http://localhost:3030
1+
API_URL_A=https://forautobackend.herokuapp.com
2+
API_URL=http://localhost:3030

components/AuthForm/parts/ForgotForm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { reduxForm } from 'redux-form'
33
import { useTranslation } from 'react-i18next'
44
import PropTypes from 'prop-types'
55
import styles from '../AuthForm.module.scss'
6-
import { Button, Spacer } from '~components'
6+
import { Button, Spacer, LanguageList } from '~components'
77

88
const formName = 'forgotPasswordForm'
99

@@ -21,6 +21,9 @@ const Component = ({ children, onSubmit, handleSubmit, title }) => {
2121
<Button fluid type={Button.types.GHOST} isInternalLink href="/sign-in">
2222
{t('button.signIn')}
2323
</Button>
24+
<div style={{ marginTop: '2rem' }}>
25+
<LanguageList />
26+
</div>
2427
</form>
2528
)
2629
}

components/AuthForm/parts/SignInForm.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
Spacer,
1313
GoogleButton,
1414
FacebookButton,
15+
LanguageList,
1516
} from '~components'
1617

1718
const formName = 'signInForm'
@@ -23,10 +24,16 @@ const Component = ({ handleSubmit, onSubmit, children, title }) => {
2324
<form className={styles.container}>
2425
{title && <h4>{title}</h4>}
2526
<div className={styles.social}>
26-
<GoogleButton title="Sign in with Google" href="https://forautobackend.herokuapp.com/oauth/google" />
27+
<GoogleButton
28+
title="Sign in with Google"
29+
href="https://forautobackend.herokuapp.com/oauth/google"
30+
/>
2731
</div>
2832
<div className={styles.social}>
29-
<FacebookButton title="Sign in with Facebook" href="https://forautobackend.herokuapp.com/oauth/facebook" />
33+
<FacebookButton
34+
title="Sign in with Facebook"
35+
href="https://forautobackend.herokuapp.com/oauth/facebook"
36+
/>
3037
</div>
3138
{children}
3239
<BaseButton
@@ -54,6 +61,9 @@ const Component = ({ handleSubmit, onSubmit, children, title }) => {
5461
>
5562
{t('button.signUp')}
5663
</Button>
64+
<div style={{ marginTop: '2rem' }}>
65+
<LanguageList />
66+
</div>
5767
</form>
5868
)
5969
}

components/AuthForm/parts/SignUpForm.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { reduxForm } from 'redux-form'
33
import { useTranslation } from 'react-i18next'
44
import PropTypes from 'prop-types'
55
import styles from '../AuthForm.module.scss'
6-
import { Button, Spacer, GoogleButton, FacebookButton } from '~components'
6+
import {
7+
Button,
8+
Spacer,
9+
LanguageList,
10+
GoogleButton,
11+
FacebookButton,
12+
} from '~components'
713

814
const formName = 'signUpForm'
915

@@ -34,6 +40,9 @@ const Component = ({ onSubmit, children, handleSubmit, title }) => {
3440
<Button fluid type={Button.types.GHOST} isInternalLink href="/sign-in">
3541
{t('button.signIn')}
3642
</Button>
43+
<div style={{ marginTop: '2rem' }}>
44+
<LanguageList />
45+
</div>
3746
</form>
3847
)
3948
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react'
2+
import { map } from 'lodash'
3+
import { useTranslation } from 'react-i18next'
4+
import classNames from 'classnames'
5+
import styles from './LanguageList.module.scss'
6+
import config from '~config'
7+
import EnglishIcon from '~public/icons/language/us.svg'
8+
import EstonianIcon from '~public/icons/language/et.svg'
9+
import RussianIcon from '~public/icons/language/ru.svg'
10+
import { BaseButton } from '~components'
11+
12+
const { langType } = config
13+
14+
const languages = {
15+
[langType.en]: {
16+
locale: [langType.en],
17+
icon: <EnglishIcon />,
18+
},
19+
[langType.et]: {
20+
locale: [langType.et],
21+
icon: <EstonianIcon />,
22+
},
23+
[langType.ru]: {
24+
locale: [langType.ru],
25+
icon: <RussianIcon />,
26+
},
27+
}
28+
29+
const LanguageList = () => {
30+
const { i18n } = useTranslation()
31+
const { language = 'en' } = i18n
32+
return (
33+
<div className={styles.languages}>
34+
{map(languages, (lang, key) => {
35+
const active = key === language
36+
return (
37+
<BaseButton
38+
key={key}
39+
className={classNames(
40+
styles.languageOption,
41+
active && styles.active
42+
)}
43+
onClick={() => i18n.changeLanguage(key)}
44+
>
45+
{lang.icon}
46+
</BaseButton>
47+
)
48+
})}
49+
</div>
50+
)
51+
}
52+
53+
export default LanguageList
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@import 'vars.scss';
2+
3+
4+
.languages {
5+
display: flex;
6+
flex-wrap: wrap;
7+
justify-content: flex-end;
8+
}
9+
10+
.languageOption {
11+
padding: spacing(1);
12+
border-radius: 50%;
13+
&.active {
14+
background: $color-primary;
15+
}
16+
}

components/LanguageSwitch/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as LanguageSwitch } from './LanguageSwitch'
2+
export { default as LanguageList } from './LanguageList'

components/Navigation/NavigationDrawer.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,9 @@ import config from '~config'
99
import EnglishIcon from '~public/icons/language/us.svg'
1010
import EstonianIcon from '~public/icons/language/et.svg'
1111
import RussianIcon from '~public/icons/language/ru.svg'
12-
import { BaseDrawer, BaseButton } from '~components'
13-
14-
const { langType } = config
15-
16-
const languages = {
17-
[langType.en]: {
18-
locale: [langType.en],
19-
icon: <EnglishIcon />,
20-
},
21-
[langType.et]: {
22-
locale: [langType.et],
23-
icon: <EstonianIcon />,
24-
},
25-
[langType.ru]: {
26-
locale: [langType.ru],
27-
icon: <RussianIcon />,
28-
},
29-
}
12+
import { BaseDrawer, BaseButton, LanguageList } from '~components'
3013

3114
const NavigationDrawer = () => {
32-
const { i18n } = useTranslation()
33-
const { language = 'en' } = i18n
3415
return (
3516
<BaseDrawer>
3617
<div className={styles.drawer}>
@@ -39,23 +20,7 @@ const NavigationDrawer = () => {
3920
</BaseButton>
4021
<NavigationContent className={styles.option} fontSize={36} />
4122
</div>
42-
<div className={styles.languages}>
43-
{map(languages, (lang, key) => {
44-
const active = key === language
45-
return (
46-
<BaseButton
47-
key={key}
48-
className={classNames(
49-
styles.languageOption,
50-
active && styles.active
51-
)}
52-
onClick={() => i18n.changeLanguage(key)}
53-
>
54-
{lang.icon}
55-
</BaseButton>
56-
)
57-
})}
58-
</div>
23+
<LanguageList />
5924
</BaseDrawer>
6025
)
6126
}

components/Navigation/NavigationDrawer.module.scss

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,3 @@
5151
}
5252
}
5353
}
54-
55-
.languages {
56-
display: flex;
57-
flex-wrap: wrap;
58-
justify-content: flex-end;
59-
}
60-
61-
.languageOption {
62-
padding: spacing(1);
63-
border-radius: 50%;
64-
&.active {
65-
background: $color-primary;
66-
}
67-
}

components/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BaseDrawer } from './Drawer'
44
import { VehicleCard } from './Cards'
55
import { Loader } from './Loader'
66
import { Spacer } from './Spacer'
7-
import { LanguageSwitch } from './LanguageSwitch'
7+
import { LanguageSwitch, LanguageList } from './LanguageSwitch'
88
import { LogoAbstract } from './Logo'
99
import { Layout } from './Layout'
1010
import { BasicHeader, Header } from './Header'
@@ -55,6 +55,7 @@ export {
5555
BaseDrawer,
5656
BaseInput,
5757
LanguageSwitch,
58+
LanguageList,
5859
Loader,
5960
LogoAbstract,
6061
ArrowPagination,

0 commit comments

Comments
 (0)