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 registerSchema = z.object({
|
||||
@@ -27,7 +28,7 @@ type RegisterForm = z.infer<typeof registerSchema>
|
||||
|
||||
export function RegisterPage() {
|
||||
const navigate = useNavigate()
|
||||
const { register: registerUser, isLoading, error, clearError } = useAuthStore()
|
||||
const { register: registerUser, isLoading, error, clearError, consumePendingInviteCode } = useAuthStore()
|
||||
const [submitError, setSubmitError] = useState<string | null>(null)
|
||||
|
||||
const {
|
||||
@@ -47,6 +48,19 @@ export function RegisterPage() {
|
||||
password: data.password,
|
||||
nickname: data.nickname,
|
||||
})
|
||||
|
||||
// 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, just go to marathons
|
||||
}
|
||||
}
|
||||
|
||||
navigate('/marathons')
|
||||
} catch {
|
||||
setSubmitError(error || 'Ошибка регистрации')
|
||||
|
||||
Reference in New Issue
Block a user