From 18de957c61876064ba1d2993959edef727a41fed Mon Sep 17 00:00:00 2001 From: Denozordec Date: Sat, 21 Mar 2026 01:07:36 +0700 Subject: [PATCH] refactor: simplify ProvidersPage by removing unused API connection logic Removed unnecessary state variables and connection testing logic from ProvidersPage. Updated the UI to clarify API login and password handling, directing users to the appropriate section for account credentials. This streamlines the component and enhances user experience. --- src/pages/ProvidersPage.jsx | 111 +++++------------------------------- 1 file changed, 13 insertions(+), 98 deletions(-) diff --git a/src/pages/ProvidersPage.jsx b/src/pages/ProvidersPage.jsx index a76fd02..cd63dd1 100644 --- a/src/pages/ProvidersPage.jsx +++ b/src/pages/ProvidersPage.jsx @@ -3,9 +3,7 @@ import { UiModal } from '../components/UiModal' import { EmptyState } from '../components/EmptyState' import { PageHeader } from '../components/PageHeader' import { faviconUrlFromWebsite } from '../lib/utils' -import { noBrowserSuggestProps, passwordCredentialInputProps } from '../lib/noBrowserSuggestProps' -import { testApiConnection } from '../lib/api' -import { IconPlugConnected } from '@tabler/icons-react' +import { noBrowserSuggestProps } from '../lib/noBrowserSuggestProps' const emptyForm = { name: '', @@ -23,10 +21,6 @@ export function ProvidersPage({ db, actions }) { const [form, setForm] = useState(emptyForm) const [editingId, setEditingId] = useState(null) const [isModalOpen, setIsModalOpen] = useState(false) - const [apiProbeLogin, setApiProbeLogin] = useState('') - const [apiProbePassword, setApiProbePassword] = useState('') - const [testConnectionLoading, setTestConnectionLoading] = useState(false) - const [testConnectionResult, setTestConnectionResult] = useState(null) const onSubmit = (event) => { event.preventDefault() @@ -40,9 +34,6 @@ export function ProvidersPage({ db, actions }) { } setForm(emptyForm) setEditingId(null) - setApiProbeLogin('') - setApiProbePassword('') - setTestConnectionResult(null) setIsModalOpen(false) } @@ -59,35 +50,9 @@ export function ProvidersPage({ db, actions }) { apiBaseUrl: provider.apiBaseUrl || '', }) setEditingId(provider.id) - setApiProbeLogin('') - setApiProbePassword('') - setTestConnectionResult(null) setIsModalOpen(true) } - const canTestApi = - form.apiType === 'billmanager' && - form.apiBaseUrl?.trim() && - apiProbeLogin?.trim() && - apiProbePassword?.trim() - - const onTestConnection = async () => { - if (!canTestApi) { - setTestConnectionResult({ ok: false, error: 'Заполните URL API и тестовый логин/пароль аккаунта' }) - return - } - setTestConnectionLoading(true) - setTestConnectionResult(null) - try { - const result = await testApiConnection(form.apiBaseUrl, `${apiProbeLogin}:${apiProbePassword}`) - setTestConnectionResult(result) - } catch (err) { - setTestConnectionResult({ ok: false, error: err.message || 'Ошибка проверки' }) - } finally { - setTestConnectionLoading(false) - } - } - return ( <> @@ -103,9 +68,6 @@ export function ProvidersPage({ db, actions }) { onClick={() => { setForm(emptyForm) setEditingId(null) - setApiProbeLogin('') - setApiProbePassword('') - setTestConnectionResult(null) setIsModalOpen(true) }} > @@ -194,9 +156,6 @@ export function ProvidersPage({ db, actions }) { setIsModalOpen(false) setEditingId(null) setForm(emptyForm) - setApiProbeLogin('') - setApiProbePassword('') - setTestConnectionResult(null) }} size="modal-md" > @@ -275,7 +234,8 @@ export function ProvidersPage({ db, actions }) {
Интеграция API (один URL на хостера)
- Логин и пароль задаются в карточке каждого аккаунта этого хостера. + Логин и пароль API — в разделе «Аккаунты хостеров»; проверка соединения доступна там при вводе + учётных данных.
@@ -297,61 +257,16 @@ export function ProvidersPage({ db, actions }) {
{form.apiType === 'billmanager' ? ( - <> -
- - setForm((prev) => ({ ...prev, apiBaseUrl: e.target.value }))} - /> -
-
- - setApiProbeLogin(e.target.value)} - /> -
-
- - setApiProbePassword(e.target.value)} - /> -
-
- - {testConnectionResult ? ( - - {testConnectionResult.ok - ? `Соединение успешно${testConnectionResult.vdsCount != null ? `, VDS: ${testConnectionResult.vdsCount}` : ''}` - : testConnectionResult.error} - - ) : null} -
- +
+ + setForm((prev) => ({ ...prev, apiBaseUrl: e.target.value }))} + /> +
) : null}