aboutsummaryrefslogtreecommitdiffstats
path: root/apps/Settings/components/Settings.js
blob: c09a1bda47aea9a6e0ea399d783a80f29a60b15e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import styles from '../styles/Settings.module.scss'
import React from 'react'
import {close} from 'helpers/windowActions'
import useUser from 'hooks/useUser'
import usePopup from 'hooks/usePopup'
import useSettings from 'hooks/useSettings'
import useApps from 'hooks/useApps'
import {saveSettings} from '../api'

const Settings = () => {
  const {setPopup} = usePopup()
  const {setApps} = useApps()
  const {settings: {theme, language}, setSettings, t} = useSettings()
  const {user} = useUser()

  const handleSave = e => {
    e.preventDefault;

    saveSettings({_id: user._id, theme, language})
    .then(() => {
      setPopup({
        content: t('settings_saved'),
        time: 2000,
      })
      close('Settings', setApps)
    })
    .catch(() => {
      setpopup({
        content: t('settings_save_error'),
        time: 2000,
        error: true,
      })
    })
  }

  return (
    <div className={styles.settings}>
      <div>{t('language')}</div>
      <div>
        {['en', 'pl', 'es', 'de'].map(l => (
          <span
            key={l}
            className={language === l ? styles.settings__langactive : ''}
            onClick={()=>{setSettings(prev => ({...prev, language: l}))}}
          >{l.toUpperCase()}</span>
        ))}
      </div>
      <div>{t('color_theme')}</div>
      <div>
        {['green', 'blue', 'black'].map(c => (
          <span
            key={c}
            onClick={()=>{setSettings(prev => ({...prev, theme: c}))}}
            className={theme === c ? styles.settings__active : ''}
          />
        ))}
      </div>
      <input
        type="button"
        className="window__button"
        value={t('save')}
        onClick={handleSave}
      />
    </div>
  )
}

export default Settings