-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from coldsurfers/feature/implement-hotsurf
fix: fixed transpile nextjs config
- Loading branch information
Showing
58 changed files
with
514 additions
and
901 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,80 @@ | ||
'use client' | ||
|
||
import LoginForm from '../../../ui/LoginForm' | ||
import { | ||
LoginForm as LoginFormUI, | ||
type LoginFormRefHandle, | ||
} from '@coldsurfers/hotsurf' | ||
import { useRouter } from 'next/navigation' | ||
import { useCallback, useEffect, useState, useRef } from 'react' | ||
import useLoginMutation from '@hooks/useLoginMutation' | ||
import { ME_QUERY } from '@hooks/useMeQuery' | ||
import storage from '@utils/storage/storage' | ||
import Loader from '@ui/Loader' | ||
|
||
const SignInPage = () => <LoginForm /> | ||
const SigninPage = () => { | ||
const router = useRouter() | ||
const formRef = useRef<LoginFormRefHandle>(null) | ||
const [mutate, { data, loading, client }] = useLoginMutation() | ||
const [errorMessage, setErrorMessage] = useState<string>('') | ||
|
||
export default SignInPage | ||
const login = useCallback( | ||
(params: { email: string; password: string }) => | ||
mutate({ | ||
variables: { | ||
input: params, | ||
}, | ||
}), | ||
[mutate] | ||
) | ||
|
||
useEffect(() => { | ||
if (!data?.login) return | ||
// eslint-disable-next-line no-shadow | ||
const { login } = data | ||
switch (login.__typename) { | ||
case 'HttpError': | ||
setErrorMessage(login.message) | ||
break | ||
case 'UserWithToken': | ||
storage.set('@billets/token', login.token) | ||
client.refetchQueries({ | ||
include: [ME_QUERY], | ||
}) | ||
break | ||
default: | ||
break | ||
} | ||
}, [client, data, router]) | ||
|
||
useEffect(() => { | ||
const onKeypress = (e: KeyboardEvent) => { | ||
if (e.key === 'Enter') { | ||
const currentInputValue = formRef.current?.currentInputValue() | ||
if (currentInputValue) { | ||
login(currentInputValue) | ||
} | ||
} | ||
} | ||
document.addEventListener('keypress', onKeypress) | ||
|
||
return () => { | ||
document.removeEventListener('keypress', onKeypress) | ||
} | ||
}, [login]) | ||
|
||
return ( | ||
<LoginFormUI | ||
ref={formRef} | ||
onPressLoginButton={login} | ||
withRequestButtonUI | ||
onPressRequestButtonUI={useCallback(() => { | ||
router.push('/auth/request') | ||
}, [router])} | ||
isLoading={loading} | ||
LoadingUI={<Loader />} | ||
errorMessage={errorMessage} | ||
/> | ||
) | ||
} | ||
|
||
export default SigninPage |
Oops, something went wrong.