Skip to content

Commit

Permalink
Merge pull request #24 from coldsurfers/feature/implement-hotsurf
Browse files Browse the repository at this point in the history
fix: fixed transpile nextjs config
  • Loading branch information
yungblud authored Jan 31, 2024
2 parents 8bdbf5e + 67446b2 commit 6a920cb
Show file tree
Hide file tree
Showing 58 changed files with 514 additions and 901 deletions.
13 changes: 0 additions & 13 deletions packages/accounts-ui/.eslintrc

This file was deleted.

2 changes: 0 additions & 2 deletions packages/accounts-ui/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions packages/accounts-ui/.prettierrc.json

This file was deleted.

53 changes: 0 additions & 53 deletions packages/accounts-ui/package.json

This file was deleted.

96 changes: 0 additions & 96 deletions packages/accounts-ui/src/LoginForm.tsx

This file was deleted.

30 changes: 0 additions & 30 deletions packages/accounts-ui/src/LoginFormLoader.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions packages/accounts-ui/src/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/accounts-ui/tsconfig.json

This file was deleted.

79 changes: 76 additions & 3 deletions packages/billets-admin-client/app/auth/signin/page.tsx
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
Loading

0 comments on commit 6a920cb

Please sign in to comment.