Refactor Telegram API and enhance TelegramPanel form handling
ci / build-backend (push) Successful in 1m56s
ci / build-frontend (push) Successful in 59s
ci / tests (push) Successful in 2m39s
ci / sonar (push) Successful in 8m58s

Updated the TelegramApi class to improve URL construction for API calls by introducing a new MethodUrl method, ensuring proper handling of bot tokens. Refactored the TelegramPanel component to use a form for input fields, allowing for better user experience and submission handling. Adjusted password input fields to use 'new-password' for improved security. These changes aim to enhance the functionality and usability of the Telegram integration.
This commit is contained in:
Leonid Pershin
2026-07-31 08:07:49 +03:00
parent ec957fe55c
commit 54cc4862b2
3 changed files with 44 additions and 7 deletions
@@ -101,7 +101,15 @@ export function TelegramPanel() {
</p>
)}
<div className="crt-panel flex flex-col gap-4 rounded-md p-4 text-sm">
{/* Форма, а не просто панель: поле пароля вне <form> браузер считает ошибкой разметки —
менеджеру паролей не к чему его привязать. Заодно работает отправка по Enter. */}
<form
className="crt-panel flex flex-col gap-4 rounded-md p-4 text-sm"
onSubmit={(e) => {
e.preventDefault()
save.mutate()
}}
>
<label className="flex items-center gap-2">
<input
type="checkbox"
@@ -116,7 +124,7 @@ export function TelegramPanel() {
<Label>{t('admin.telegram.token')}</Label>
<Input
type="password"
autoComplete="off"
autoComplete="new-password"
placeholder={settings?.hasToken ? t('admin.telegram.tokenKept') : '123456:ABC...'}
value={form.botToken ?? ''}
onChange={(e) => patch({ botToken: trimmed(e.target.value) })}
@@ -212,7 +220,7 @@ export function TelegramPanel() {
<Label>{t('admin.telegram.proxyPassword')}</Label>
<Input
type="password"
autoComplete="off"
autoComplete="new-password"
placeholder={settings?.hasProxyPassword ? t('admin.telegram.tokenKept') : undefined}
value={form.proxyPassword ?? ''}
onChange={(e) => patch({ proxyPassword: trimmed(e.target.value) })}
@@ -222,7 +230,7 @@ export function TelegramPanel() {
)}
<div className="flex flex-wrap items-center gap-3">
<Button size="sm" disabled={save.isPending} onClick={() => save.mutate()}>
<Button size="sm" type="submit" disabled={save.isPending}>
{t('common.save')}
</Button>
{settings?.lastContactAt && (
@@ -231,7 +239,7 @@ export function TelegramPanel() {
</span>
)}
</div>
</div>
</form>
<div className="flex flex-col gap-2">
<h3 className="text-sm font-semibold uppercase tracking-wide text-muted-foreground">