add oauth app connected
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
updateManagedBot,
|
||||
updateManagedBotProfile
|
||||
} from '@/lib/api';
|
||||
import { useEmbeddedAuthFallback } from '@/lib/embedded-auth-bridge';
|
||||
import { parseComposerMenuButtonJson } from '@/lib/bot-menu-button';
|
||||
|
||||
function FieldTextarea({
|
||||
@@ -77,7 +78,9 @@ function SectionCard({
|
||||
export function BotManageMiniAppContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const botId = searchParams.get('botId') ?? '';
|
||||
const { token, user, isPinLocked } = useAuth();
|
||||
const { token, isPinLocked, isLoading } = useAuth();
|
||||
const embeddedToken = useEmbeddedAuthFallback();
|
||||
const effectiveToken = token ?? embeddedToken;
|
||||
const { showToast } = useToast();
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -94,13 +97,13 @@ export function BotManageMiniAppContent() {
|
||||
const [tokenPrefix, setTokenPrefix] = useState('');
|
||||
const [newToken, setNewToken] = useState<string | null>(null);
|
||||
|
||||
const canUse = Boolean(token && user && !isPinLocked && botId);
|
||||
const canUse = Boolean(effectiveToken && !isPinLocked && botId);
|
||||
|
||||
const loadBot = useCallback(async () => {
|
||||
if (!canUse) return;
|
||||
if (!canUse || !effectiveToken) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const bot = await fetchBot(botId, token);
|
||||
const bot = await fetchBot(botId, effectiveToken);
|
||||
setName(bot.name);
|
||||
setUsername(bot.username);
|
||||
setDescription(bot.description ?? '');
|
||||
@@ -121,7 +124,7 @@ export function BotManageMiniAppContent() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [botId, canUse, showToast, token]);
|
||||
}, [botId, canUse, effectiveToken, showToast]);
|
||||
|
||||
useEffect(() => {
|
||||
void loadBot();
|
||||
@@ -130,7 +133,7 @@ export function BotManageMiniAppContent() {
|
||||
const usernameWithoutSuffix = useMemo(() => username.replace(/_bot$/i, ''), [username]);
|
||||
|
||||
async function handleSaveBasic() {
|
||||
if (!canUse) return;
|
||||
if (!canUse || !effectiveToken) return;
|
||||
setSavingBasic(true);
|
||||
try {
|
||||
const bot = await updateManagedBot(
|
||||
@@ -139,7 +142,7 @@ export function BotManageMiniAppContent() {
|
||||
name: name.trim(),
|
||||
username: usernameWithoutSuffix.trim()
|
||||
},
|
||||
token
|
||||
effectiveToken
|
||||
);
|
||||
setName(bot.name);
|
||||
setUsername(bot.username);
|
||||
@@ -152,7 +155,7 @@ export function BotManageMiniAppContent() {
|
||||
}
|
||||
|
||||
async function handleSaveProfile() {
|
||||
if (!canUse) return;
|
||||
if (!canUse || !effectiveToken) return;
|
||||
setSavingProfile(true);
|
||||
try {
|
||||
const bot = await updateManagedBotProfile(
|
||||
@@ -164,7 +167,7 @@ export function BotManageMiniAppContent() {
|
||||
menuButtonUrl: menuButtonUrl.trim(),
|
||||
menuButtonText: menuButtonText.trim() || 'App'
|
||||
},
|
||||
token
|
||||
effectiveToken
|
||||
);
|
||||
setDescription(bot.description ?? '');
|
||||
setAboutText(bot.aboutText ?? '');
|
||||
@@ -183,10 +186,10 @@ export function BotManageMiniAppContent() {
|
||||
}
|
||||
|
||||
async function handleRevokeToken() {
|
||||
if (!canUse) return;
|
||||
if (!canUse || !effectiveToken) return;
|
||||
setRevoking(true);
|
||||
try {
|
||||
const response = await revokeManagedBotToken(botId, token);
|
||||
const response = await revokeManagedBotToken(botId, effectiveToken);
|
||||
setNewToken(response.token ?? null);
|
||||
setTokenPrefix(response.bot?.tokenPrefix ?? tokenPrefix);
|
||||
showToast('Токен перевыпущен');
|
||||
@@ -207,6 +210,15 @@ export function BotManageMiniAppContent() {
|
||||
return <div className="flex min-h-screen items-center justify-center p-6 text-sm text-[#667085]">Не указан botId</div>;
|
||||
}
|
||||
|
||||
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]">
|
||||
|
||||
Reference in New Issue
Block a user