Skip to content

Commit 8e7c74e

Browse files
committed
feat: add a button to generate panel url inside webhook url input
1 parent 60c1ad2 commit 8e7c74e

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

dashboard/public/statics/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@
248248
"webhookUrl": "Webhook URL",
249249
"webhookUrlPlaceholder": "https://your-domain.com/webhook",
250250
"webhookUrlDescription": "URL where Telegram will send updates",
251+
"usePanelUrl": "Use Current Panel URL",
252+
"usePanelUrlDescription": "Automatically insert your current panel URL into the webhook field for easy setup",
253+
"panelUrlApplied": "Panel URL applied to webhook field",
251254
"webhookSecret": "Webhook Secret",
252255
"webhookSecretPlaceholder": "Enter webhook secret",
253256
"webhookSecretDescription": "Secret token for webhook security",

dashboard/public/statics/locales/fa.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@
155155
"webhookUrl": "آدرس Webhook",
156156
"webhookUrlPlaceholder": "https://your-domain.com/webhook",
157157
"webhookUrlDescription": "آدرسی که تلگرام به‌روزرسانی‌ها را ارسال می‌کند",
158+
"usePanelUrl": "استفاده از آدرس پنل فعلی",
159+
"usePanelUrlDescription": "آدرس پنل فعلی خود را به طور خودکار در فیلد webhook وارد کنید",
160+
"panelUrlApplied": "آدرس پنل در فیلد webhook اعمال شد",
158161
"webhookSecret": "رمز Webhook",
159162
"webhookSecretPlaceholder": "رمز webhook را وارد کنید",
160163
"webhookSecretDescription": "توکن مخفی برای امنیت webhook",

dashboard/public/statics/locales/ru.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@
248248
"webhookUrl": "URL Webhook",
249249
"webhookUrlPlaceholder": "https://your-domain.com/webhook",
250250
"webhookUrlDescription": "URL, на который Telegram будет отправлять обновления",
251+
"usePanelUrl": "Использовать текущий URL панели",
252+
"usePanelUrlDescription": "Автоматически вставить текущий URL панели в поле webhook для удобной настройки",
253+
"panelUrlApplied": "URL панели применен к полю webhook",
251254
"webhookSecret": "Секрет Webhook",
252255
"webhookSecretPlaceholder": "Введите секрет webhook",
253256
"webhookSecretDescription": "Секретный токен для безопасности webhook",

dashboard/public/statics/locales/zh.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@
226226
"webhookUrl": "Webhook URL",
227227
"webhookUrlPlaceholder": "https://your-domain.com/webhook",
228228
"webhookUrlDescription": "Telegram 发送更新的 URL",
229+
"usePanelUrl": "使用当前面板 URL",
230+
"usePanelUrlDescription": "自动将当前面板 URL 插入到 webhook 字段中以便轻松设置",
231+
"panelUrlApplied": "面板 URL 已应用到 webhook 字段",
229232
"webhookSecret": "Webhook 密钥",
230233
"webhookSecretPlaceholder": "输入 webhook 密钥",
231234
"webhookSecretDescription": "用于 webhook 安全的秘密令牌",

dashboard/src/pages/_dashboard.settings.telegram.tsx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import { PasswordInput } from '@/components/ui/password-input'
1010
import { Switch } from '@/components/ui/switch'
1111
import { Separator } from '@/components/ui/separator'
1212
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
13-
import { Bot, Webhook, Shield, Globe, Smartphone, Send, Users, Settings } from 'lucide-react'
13+
import { Bot, Webhook, Shield, Globe, Smartphone, Send, Users, Settings, RefreshCcw } from 'lucide-react'
1414
import { useSettingsContext } from './_dashboard.settings'
1515
import { toast } from 'sonner'
16+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
17+
import { useState } from 'react'
1618

1719
// Telegram settings validation schema
1820
const telegramSettingsSchema = z.object({
@@ -58,6 +60,13 @@ const telegramSettingsSchema = z.object({
5860

5961
type TelegramSettingsForm = z.infer<typeof telegramSettingsSchema>
6062

63+
// Helper function to get current panel URL
64+
const getCurrentPanelUrl = () => {
65+
const protocol = window.location.protocol
66+
const host = window.location.host
67+
return `${protocol}//${host}`
68+
}
69+
6170
// Helper to map frontend Telegram form data to backend payload
6271
function mapTelegramFormToPayload(data: TelegramSettingsForm) {
6372
const mapped = {
@@ -76,6 +85,7 @@ function mapTelegramFormToPayload(data: TelegramSettingsForm) {
7685
export default function TelegramSettings() {
7786
const { t } = useTranslation()
7887
const { settings, isLoading, error, updateSettings, isSaving } = useSettingsContext()
88+
const [popoverOpen, setPopoverOpen] = useState(false)
7989

8090
const form = useForm<TelegramSettingsForm>({
8191
resolver: zodResolver(telegramSettingsSchema),
@@ -295,9 +305,38 @@ export default function TelegramSettings() {
295305
<Webhook className="h-4 w-4" />
296306
{t('settings.telegram.general.webhookUrl')}
297307
</FormLabel>
298-
<FormControl>
299-
<Input type="url" placeholder={t('settings.telegram.general.webhookUrlPlaceholder')} {...field} className="font-mono" />
300-
</FormControl>
308+
<div className="relative">
309+
<FormControl>
310+
<Input type="url" placeholder={t('settings.telegram.general.webhookUrlPlaceholder')} {...field} className="font-mono pr-10" />
311+
</FormControl>
312+
<Popover open={popoverOpen} onOpenChange={setPopoverOpen}>
313+
<PopoverTrigger asChild>
314+
<Button
315+
type="button"
316+
variant="ghost"
317+
size="icon"
318+
className="absolute right-1 top-1/2 h-8 w-8 -translate-y-1/2 hover:bg-accent"
319+
onClick={(e) => {
320+
e.preventDefault()
321+
const currentUrl = getCurrentPanelUrl()
322+
field.onChange(currentUrl)
323+
toast.success(t('settings.telegram.general.panelUrlApplied'))
324+
setPopoverOpen(false)
325+
}}
326+
onMouseEnter={() => setPopoverOpen(true)}
327+
onMouseLeave={() => setPopoverOpen(false)}
328+
>
329+
<RefreshCcw className="h-3 w-3" />
330+
</Button>
331+
</PopoverTrigger>
332+
<PopoverContent className="w-80" side="top" align="end">
333+
<div className="space-y-2">
334+
<p className="text-sm font-medium">{t('settings.telegram.general.usePanelUrl')}</p>
335+
<p className="text-xs text-muted-foreground">{t('settings.telegram.general.usePanelUrlDescription')}</p>
336+
</div>
337+
</PopoverContent>
338+
</Popover>
339+
</div>
301340
<FormDescription className="text-sm text-muted-foreground">
302341
{t('settings.telegram.general.webhookUrlDescription')}
303342
<br />

0 commit comments

Comments
 (0)