From ace2e08db2d390a78ebf9f735be9415aef221612 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 28 Dec 2022 00:36:42 -0800 Subject: [PATCH] Hotfix for LoginModal to see whats wrong --- components/LoginModal/index.tsx | 125 ++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 47 deletions(-) diff --git a/components/LoginModal/index.tsx b/components/LoginModal/index.tsx index d6886bf5..e0f67e21 100644 --- a/components/LoginModal/index.tsx +++ b/components/LoginModal/index.tsx @@ -2,11 +2,12 @@ import React, { useState } from 'react' import { setCookie } from 'cookies-next' import Router, { useRouter } from 'next/router' import { useTranslation } from 'react-i18next' -import { AxiosResponse } from 'axios' +import axios, { AxiosError, AxiosResponse } from 'axios' import api from '~utils/api' import { accountState } from '~utils/accountState' +import Alert from '~components/Alert' import Button from '~components/Button' import Input from '~components/Input' import { @@ -21,23 +22,28 @@ import changeLanguage from '~utils/changeLanguage' import CrossIcon from '~public/icons/Cross.svg' import './index.scss' -interface Props {} - interface ErrorMap { [index: string]: string email: string password: string } +interface GranblueAxiosError { + response: AxiosResponse + request: any + code: number +} + const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ -const LoginModal = (props: Props) => { +const LoginModal = () => { const router = useRouter() const { t } = useTranslation('common') // Set up form states and error handling const [formValid, setFormValid] = useState(false) + const [axiosError, setAxiosError] = useState() const [errors, setErrors] = useState({ email: '', password: '', @@ -45,6 +51,7 @@ const LoginModal = (props: Props) => { // States const [open, setOpen] = useState(false) + const [alertOpen, setAlertOpen] = useState(false) // Set up form refs const emailInput: React.RefObject = React.createRef() @@ -109,6 +116,19 @@ const LoginModal = (props: Props) => { }) .then((id) => fetchUserInfo(id)) .then((infoResponse) => storeUserInfo(infoResponse)) + .catch((error: Error | AxiosError) => { + console.log(error) + + if (axios.isAxiosError(error)) { + const axiosError: AxiosError = error + console.log(axiosError.request) + console.log(axiosError.response) + console.log(axiosError.code) + setAlertOpen(true) + + setAxiosError(axiosError) + } + }) } } @@ -181,53 +201,64 @@ const LoginModal = (props: Props) => { } return ( - - -
  • - {t('menu.login')} -
  • -
    - -
    -
    -

    {t('modals.login.title')}

    + + { + setAlertOpen(false) + }} + open={alertOpen} + > + + +
  • + {t('menu.login')} +
  • +
    + +
    +
    +

    {t('modals.login.title')}

    +
    + + +
    - - - -
    -
    - + + - + -
    +