Add invite links
This commit is contained in:
@@ -4,6 +4,7 @@ import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { z } from 'zod'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { marathonsApi } from '@/api'
|
||||
import { Button, Input, Card, CardHeader, CardTitle, CardContent } from '@/components/ui'
|
||||
|
||||
const loginSchema = z.object({
|
||||
@@ -15,7 +16,7 @@ type LoginForm = z.infer<typeof loginSchema>
|
||||
|
||||
export function LoginPage() {
|
||||
const navigate = useNavigate()
|
||||
const { login, isLoading, error, clearError } = useAuthStore()
|
||||
const { login, isLoading, error, clearError, consumePendingInviteCode } = useAuthStore()
|
||||
const [submitError, setSubmitError] = useState<string | null>(null)
|
||||
|
||||
const {
|
||||
@@ -31,6 +32,19 @@ export function LoginPage() {
|
||||
clearError()
|
||||
try {
|
||||
await login(data)
|
||||
|
||||
// Check for pending invite code
|
||||
const pendingCode = consumePendingInviteCode()
|
||||
if (pendingCode) {
|
||||
try {
|
||||
const marathon = await marathonsApi.join(pendingCode)
|
||||
navigate(`/marathons/${marathon.id}`)
|
||||
return
|
||||
} catch {
|
||||
// If join fails (already member, etc), just go to marathons
|
||||
}
|
||||
}
|
||||
|
||||
navigate('/marathons')
|
||||
} catch {
|
||||
setSubmitError(error || 'Ошибка входа')
|
||||
|
||||
Reference in New Issue
Block a user