This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useStore } from '../store/useStore';
|
||||
import { authApi, familyApi } from '../api/client';
|
||||
import { authApi, familyApi, inviteLinkApi } from '../api/client';
|
||||
import { Users, LogOut, Settings, Plus, Loader2, Eye, EyeOff } from 'lucide-react';
|
||||
|
||||
export default function NoFamily() {
|
||||
@@ -13,6 +13,38 @@ export default function NoFamily() {
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [joiningFamily, setJoiningFamily] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
checkPendingInvite();
|
||||
}, []);
|
||||
|
||||
const checkPendingInvite = async () => {
|
||||
const pendingToken = localStorage.getItem('pendingInviteToken');
|
||||
if (!pendingToken) return;
|
||||
|
||||
localStorage.removeItem('pendingInviteToken');
|
||||
|
||||
try {
|
||||
setJoiningFamily(true);
|
||||
const response = await inviteLinkApi.join(pendingToken);
|
||||
if (response.data.success) {
|
||||
const meResponse = await authApi.me();
|
||||
setUser(meResponse.data);
|
||||
navigate(`/family/${response.data.family_id}`);
|
||||
} else {
|
||||
setError(response.data.message);
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (err.response?.status === 400) {
|
||||
setError('Ссылка-приглашение недействительна или истекла');
|
||||
} else {
|
||||
setError('Ошибка при присоединении к семье');
|
||||
}
|
||||
} finally {
|
||||
setJoiningFamily(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
@@ -68,6 +100,17 @@ export default function NoFamily() {
|
||||
}
|
||||
};
|
||||
|
||||
if (joiningFamily) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center gradient-bg">
|
||||
<div className="flex items-center gap-3 text-white">
|
||||
<Loader2 className="w-8 h-8 animate-spin" />
|
||||
<span className="text-xl font-medium">Присоединение к семье...</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen gradient-bg flex items-center justify-center px-4">
|
||||
<div className="w-full max-w-md">
|
||||
|
||||
Reference in New Issue
Block a user