add oauth app connected

This commit is contained in:
lendry
2026-06-26 10:49:34 +03:00
parent d5e6b58955
commit b81c0cedbb
18 changed files with 838 additions and 59 deletions

View File

@@ -7,13 +7,16 @@ import { useToast } from '@/components/id/toast-provider';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { createManagedBot, getApiErrorMessage } from '@/lib/api';
import { useEmbeddedAuthFallback } from '@/lib/embedded-auth-bridge';
import { cn } from '@/lib/utils';
type Step = 'name' | 'username' | 'done';
export function BotCreateMiniAppContent() {
const { token, user, isPinLocked } = useAuth();
const { token, isPinLocked, isLoading } = useAuth();
const embeddedToken = useEmbeddedAuthFallback();
const { showToast } = useToast();
const effectiveToken = token ?? embeddedToken;
const [step, setStep] = useState<Step>('name');
const [name, setName] = useState('');
@@ -21,11 +24,11 @@ export function BotCreateMiniAppContent() {
const [creating, setCreating] = useState(false);
const [createdBot, setCreatedBot] = useState<{ username: string; token: string; botId: string } | null>(null);
const canUse = Boolean(token && user && !isPinLocked);
const canUse = Boolean(effectiveToken && !isPinLocked);
const usernamePreview = useMemo(() => `${username.replace(/_bot$/i, '').trim()}_bot`, [username]);
async function handleCreate() {
if (!canUse) return;
if (!canUse || !effectiveToken) return;
const trimmedName = name.trim();
const trimmedUsername = username.replace(/_bot$/i, '').trim();
if (!trimmedName) {
@@ -40,7 +43,7 @@ export function BotCreateMiniAppContent() {
setCreating(true);
try {
const response = await createManagedBot({ name: trimmedName, username: trimmedUsername }, token);
const response = await createManagedBot({ name: trimmedName, username: trimmedUsername }, effectiveToken);
setCreatedBot({
username: response.bot?.username ?? usernamePreview,
token: response.token ?? '',
@@ -61,6 +64,15 @@ export function BotCreateMiniAppContent() {
showToast('Токен скопирован');
}
if (isLoading && !effectiveToken) {
return (
<div className="flex min-h-screen items-center justify-center p-6 text-center text-sm text-[#667085]">
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Загрузка...
</div>
);
}
if (!canUse) {
return (
<div className="flex min-h-screen items-center justify-center p-6 text-center text-sm text-[#667085]">