diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3b53150..4057cf9 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -2,40 +2,25 @@ module.exports = { env: { browser: true, es2021: true, + node: true, }, extends: [ - 'xo', + 'react-app', + 'react-app/jest', + 'eslint:recommended', 'plugin:react/recommended', ], - overrides: [ - { - env: { - node: true, - }, - files: [ - '.eslintrc.{js,cjs}', - ], - parserOptions: { - sourceType: 'script', - }, - }, - { - extends: [ - 'xo-typescript', - ], - files: [ - '*.ts', - '*.tsx', - ], - }, - ], parserOptions: { ecmaVersion: 'latest', sourceType: 'module', }, - plugins: [ - 'react', - ], + plugins: ['react'], rules: { + // Customize your rules as needed. For now, this keeps the default settings. + }, + settings: { + react: { + version: 'detect', + }, }, -}; +}; \ No newline at end of file diff --git a/src/views-desktop/login.tsx b/src/views-desktop/login.tsx index da8ea67..871c54d 100644 --- a/src/views-desktop/login.tsx +++ b/src/views-desktop/login.tsx @@ -1,197 +1,344 @@ -import * as React from 'react'; -import * as mui from '@mui/material'; -import {useNavigate} from 'react-router-dom'; -import {useTranslation} from 'react-i18next'; +import * as React from "react"; +import * as mui from "@mui/material"; +import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; // Components -import ArrowForward from '@mui/icons-material/ArrowForward'; -import VisibilityIcon from '@mui/icons-material/Visibility'; -import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; -import {os} from '../services/util/open'; -import WhiteHueTextField from '../components/textfields/white-hue'; -import LoginButton from '../components/buttons/login-button'; -import NewAccountDialog from '../components/dialogs/new_account'; -import LanguageSelector from '../components/select/language'; +import ArrowForward from "@mui/icons-material/ArrowForward"; +import VisibilityIcon from "@mui/icons-material/Visibility"; +import VisibilityOffIcon from "@mui/icons-material/VisibilityOff"; +import { os } from "../services/util/open"; +import WhiteHueTextField from "../components/textfields/white-hue"; +import LoginButton from "../components/buttons/login-button"; +import NewAccountDialog from "../components/dialogs/new_account"; +import LanguageSelector from "../components/select/language"; // Services -import {session_and_local_auth, get_hash} from '../services/authentication/auth'; -import {getViewingKey} from '../services/storage/keys'; +import { + session_and_local_auth, + get_hash, +} from "../services/authentication/auth"; +import { getViewingKey } from "../services/storage/keys"; // Images -import full_logo from '../assets/logo/desktop-full-logo.svg'; -import loginimage from '../assets/images/backgrounds/sign-up-bg.jpeg'; +import full_logo from "../assets/logo/desktop-full-logo.svg"; +import loginimage from "../assets/images/backgrounds/sign-up-bg.jpeg"; // Typography -import {TitleText, SmallText, BodyText, SmallText400} from '../components/typography/typography'; -import {Languages} from '../types/languages'; +import { + TitleText, + SmallText, + BodyText, + SmallText400, +} from "../components/typography/typography"; +import { Languages } from "../types/languages"; // Errors -import {type AvailError} from '../types/errors'; +import { type AvailError } from "../types/errors"; // Alerts import { - ErrorAlert, WarningAlert, SuccessAlert, InfoAlert, -} from '../components/snackbars/alerts'; -import Layout from './reusable/layout'; + ErrorAlert, + WarningAlert, + SuccessAlert, + InfoAlert, +} from "../components/snackbars/alerts"; +import Layout from "./reusable/layout"; function Login() { - const [password, setPassword] = React.useState(''); - const [open, setOpen] = React.useState(false); - const [passwordHidden, setPasswordHidden] = React.useState(true); - const [newAccountDialog, setNewAccountDialog] = React.useState(false); - - const [success, setSuccess] = React.useState(false); - const [info, setInfo] = React.useState(false); - const [error, setError] = React.useState(false); - const [warning, setWarning] = React.useState(false); - - const [message, setMessage] = React.useState(''); - const [language, setLanguage] = React.useState(Languages.English); - - const navigate = useNavigate(); - - const {t} = useTranslation(); - - const md = mui.useMediaQuery('(min-width:1000px)'); - const lg = mui.useMediaQuery('(min-width:1200px)'); - - const handleLogin = () => { - session_and_local_auth(password, navigate, setError, setMessage, false).then(() => { - setMessage(t('login.messages.success')); - setSuccess(true); - - navigate('/home'); - }).catch(async error_ => { - const error = error_ as AvailError; - - if (error.error_type.toString() === 'Network') { - setMessage('No Wifi Connection'); - setWarning(true); - - getViewingKey(password).then(() => { - navigate('/home'); - }).catch(error_ => { - console.log(error_); - setMessage(t('login.messages.error')); - setError(true); - }); - - return; - } - - setMessage(t('login.messages.error')); - setError(true); - }); - }; - - return ( - - - {/* --Alerts-- */} - - - - - - {/* New Account Dialog */} - { - setNewAccountDialog(false); - }}/> - - - - - - {/* Right side contents in a Grid */} - - - - - - - - - {t('login.tagline.part1')} - {t('login.tagline.part2')} - - - {/* --Password Input-- */} - ) => { - setPassword(event.target.value); - }} - value={password} - type={passwordHidden ? 'password' : ''} - inputProps={{style: {color: '#fff'}}} - InputLabelProps={{style: {color: '#fff'}}} - sx={{width: lg ? '70%' : (md ? '80%' : '90%'), marginTop: '30%'}} - InputProps={{ - endAdornment: ( - - {passwordHidden ? { - setPasswordHidden(false); - }} /> : { - setPasswordHidden(true); - }} />} - - ), - }} - onKeyDown={e => { - if (e.key === 'Enter') { - handleLogin(); - } - }} - /> - - { - handleLogin(); - }} - sx={{marginTop: '5%'}} - endIcon={} - > - {t('login.CTAButton')} - - - - {t('login.access')} - { - navigate('/recovery'); - }}> - {t('login.recover')} - - - - Want to create a new account ? - { - setNewAccountDialog(true); - }}> - New Account - - - - - - ); + const [password, setPassword] = React.useState(""); + const [open, setOpen] = React.useState(false); + const [passwordHidden, setPasswordHidden] = React.useState(true); + const [newAccountDialog, setNewAccountDialog] = React.useState(false); + + const [success, setSuccess] = React.useState(false); + const [info, setInfo] = React.useState(false); + const [error, setError] = React.useState(false); + const [warning, setWarning] = React.useState(false); + + const [message, setMessage] = React.useState(""); + const [language, setLanguage] = React.useState(Languages.English); + + const navigate = useNavigate(); + + const { t } = useTranslation(); + + const md = mui.useMediaQuery("(min-width:1000px)"); + const lg = mui.useMediaQuery("(min-width:1200px)"); + + const handleLogin = () => { + session_and_local_auth(password, navigate, setError, setMessage, false) + .then(() => { + setMessage(t("login.messages.success")); + setSuccess(true); + + navigate("/home"); + }) + .catch(async (error_) => { + const error = error_ as AvailError; + + if (error.error_type.toString() === "Network") { + setMessage("No Wifi Connection"); + setWarning(true); + + getViewingKey(password) + .then(() => { + navigate("/home"); + }) + .catch((error_) => { + console.log(error_); + setMessage(t("login.messages.error")); + setError(true); + }); + + return; + } + + setMessage(t("login.messages.error")); + setError(true); + }); + }; + + return ( + + {/* --Alerts-- */} + + + + + + {/* New Account Dialog */} + { + setNewAccountDialog(false); + }} + /> + + + + + {/* Right side contents in a Grid */} + + + + + + + + + + {" "} + {t("login.tagline.part1")}{" "} + + + {" "} + {t("login.tagline.part2")}{" "} + + + + {/* --Password Input-- */} + ) => { + setPassword(event.target.value); + }} + value={password} + type={passwordHidden ? "password" : ""} + inputProps={{ style: { color: "#fff" } }} + InputLabelProps={{ style: { color: "#fff" } }} + sx={{ width: lg ? "70%" : md ? "80%" : "90%", marginTop: "30%" }} + InputProps={{ + endAdornment: ( + + {passwordHidden ? ( + { + setPasswordHidden(false); + }} + /> + ) : ( + { + setPasswordHidden(true); + }} + /> + )} + + ), + }} + onKeyDown={(e) => { + if (e.key === "Enter") { + handleLogin(); + } + }} + /> + + { + handleLogin(); + }} + sx={{ marginTop: "5%" }} + endIcon={} + > + {t("login.CTAButton")} + + + + + {" "} + {t("login.access")} + + { + navigate("/recovery"); + }} + > + + {t("login.recover")} + + + + + + Want to create a new account ? + + { + setNewAccountDialog(true); + }} + > + + New Account + + + + + + + ); } export default Login;