mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-01 20:55:16 +09:00
fix(ui): mark required fields and show inline errors in more dialogs
Migrates to FormField + Label required + useFieldErrors: - SSL certificates: obtain (domains, email, conditional webroot / wildcard DNS credentials) and upload (domain, certificate, private key) - Queue operations: create group, create queue, send message - Monitors: new monitor (keyword only when the check type needs it) - Status pages: page, component and incident dialogs - Invite user: optional email gets an inline invalid-email error ResourcePicker now exposes aria-required/invalid/describedby inside a FormField, and Domains distinguishes an empty domain from a malformed one. New strings in all locales.
This commit is contained in:
1 parent
4183365aac
commit
0ae7790917
26 files changed
+489
-284
No files matched your search
@@ -240,7 +240,7 @@ const ADOPTION_CEILINGS = [
|
||||
},
|
||||
{
|
||||
name: 'hand-rolled form-group blocks (F2: FormField/useForm)',
|
||||
ceiling: 321,
|
||||
ceiling: 253,
|
||||
include: (file) => file.startsWith('pages/') || file.startsWith('components/'),
|
||||
pattern: /form-group/g,
|
||||
},
|
||||
|
||||
@@ -44,7 +44,7 @@ function loadBases() {
|
||||
* record at this server (a tunnel route, an edge proxy).
|
||||
*
|
||||
* `onChange` receives the normalized hostname ('' while incomplete) and
|
||||
* `{ mode, valid, base, label, dnsMode, https }` so the caller can pick the
|
||||
* `{ mode, valid, empty, base, label, dnsMode, https }` so the caller can pick the
|
||||
* right API (give-subdomain vs create-domain) without re-deriving anything.
|
||||
*/
|
||||
export default function DomainField({
|
||||
@@ -132,6 +132,7 @@ export default function DomainField({
|
||||
const info = {
|
||||
mode: activeMode,
|
||||
valid: usable,
|
||||
empty: !fqdn,
|
||||
base: activeMode === 'subdomain' ? base : null,
|
||||
label: activeMode === 'subdomain' ? label : null,
|
||||
dnsMode: activeMode === 'subdomain' ? baseRow?.dns_mode || null : null,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Button } from './ui/button';
|
||||
import {
|
||||
Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList,
|
||||
} from './ui/command';
|
||||
import { useFieldProps } from './ui/field-context';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from './ui/popover';
|
||||
import { useResourceOptions } from '../hooks/useResourceOptions';
|
||||
import { normalizeResourceRef, resourceKey } from '../utils/resourceRefs';
|
||||
@@ -34,6 +35,8 @@ export default function ResourcePicker({
|
||||
id,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
// Inside a FormField the trigger reports required/invalid and points at the error.
|
||||
const fieldProps = useFieldProps({ id });
|
||||
const [open, setOpen] = useState(false);
|
||||
const [query, setQuery] = useState('');
|
||||
const search = useResourceOptions({
|
||||
@@ -108,7 +111,10 @@ export default function ResourcePicker({
|
||||
}}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
id={id}
|
||||
id={fieldProps.id}
|
||||
aria-describedby={fieldProps['aria-describedby']}
|
||||
aria-invalid={fieldProps['aria-invalid']}
|
||||
aria-required={fieldProps['aria-required']}
|
||||
type="button"
|
||||
variant="outline"
|
||||
className={triggerClassName}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useId } from 'react';
|
||||
import api from '../../services/api';
|
||||
import PermissionEditor from './PermissionEditor';
|
||||
import Modal from '../Modal';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { FormField, FormRow } from '../FormField';
|
||||
import useFieldErrors from '../../hooks/useFieldErrors';
|
||||
import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@/components/ui/select';
|
||||
import CopyField from '../CopyField';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -20,6 +21,13 @@ const InviteModal = ({ onClose, onCreated }) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [result, setResult] = useState(null);
|
||||
const fieldId = useId();
|
||||
// Email is optional; only a value that is present must look like an address.
|
||||
const fe = useFieldErrors({
|
||||
email: !email.trim() || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim())
|
||||
? null
|
||||
: t('common.validation.emailInvalid', 'Enter a valid email address.'),
|
||||
}, fieldId);
|
||||
|
||||
useEffect(() => {
|
||||
api.getPermissionTemplates().then(data => {
|
||||
@@ -39,6 +47,7 @@ const InviteModal = ({ onClose, onCreated }) => {
|
||||
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (!fe.attempt()) return;
|
||||
setError('');
|
||||
setLoading(true);
|
||||
|
||||
@@ -59,6 +68,7 @@ const InviteModal = ({ onClose, onCreated }) => {
|
||||
}));
|
||||
if (onCreated) onCreated();
|
||||
} catch (err) {
|
||||
if (fe.fromServer(err)) return;
|
||||
setError(err.message || 'Failed to create invitation');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -98,27 +108,28 @@ const InviteModal = ({ onClose, onCreated }) => {
|
||||
|
||||
return (
|
||||
<Modal open={true} onClose={onClose} title={t('app.inviteModal.inviteUser', 'Invite user')} size="md">
|
||||
<form onSubmit={handleSubmit} data-walkthrough="invite-form">
|
||||
<form onSubmit={handleSubmit} noValidate data-walkthrough="invite-form">
|
||||
<div className="modal-body">
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
|
||||
<div className="form-group">
|
||||
<Label htmlFor="invite-email">{t('app.inviteModal.emailOptional', 'Email (optional)')}</Label>
|
||||
<FormField
|
||||
label={t('app.inviteModal.emailOptional', 'Email (optional)')}
|
||||
htmlFor={`${fieldId}-email`}
|
||||
hint={t('app.inviteModal.ifProvidedAnInvitationEmailWill', 'If provided, an invitation email will be sent. Otherwise, share the link manually.')}
|
||||
error={fe.error('email')}
|
||||
>
|
||||
<Input
|
||||
type="email"
|
||||
id="invite-email"
|
||||
id={`${fieldId}-email`}
|
||||
value={email}
|
||||
onChange={e => setEmail(e.target.value)}
|
||||
onChange={e => { fe.clear('email'); setEmail(e.target.value); }}
|
||||
onBlur={() => fe.touch('email')}
|
||||
placeholder={t('app.inviteModal.userExampleComLeaveBlankFor', 'user@example.com (leave blank for link-only)')}
|
||||
/>
|
||||
<span className="form-help">
|
||||
{t('app.inviteModal.ifProvidedAnInvitationEmailWill', 'If provided, an invitation email will be sent. Otherwise, share the link manually.')}
|
||||
</span>
|
||||
</div>
|
||||
</FormField>
|
||||
|
||||
<div className="form-row">
|
||||
<div className="form-group">
|
||||
<Label htmlFor="invite-role">{t('app.inviteModal.role', 'Role')}</Label>
|
||||
<FormRow>
|
||||
<FormField label={t('app.inviteModal.role', 'Role')} htmlFor="invite-role">
|
||||
<Select value={role} onValueChange={handleRoleChange}>
|
||||
<SelectTrigger id="invite-role">
|
||||
<SelectValue />
|
||||
@@ -129,10 +140,9 @@ const InviteModal = ({ onClose, onCreated }) => {
|
||||
<SelectItem value="viewer">{t('app.inviteModal.viewer', 'Viewer')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</FormField>
|
||||
|
||||
<div className="form-group">
|
||||
<Label htmlFor="invite-expiry">{t('app.inviteModal.expires', 'Expires')}</Label>
|
||||
<FormField label={t('app.inviteModal.expires', 'Expires')} htmlFor="invite-expiry">
|
||||
<Select
|
||||
value={String(expiryDays)}
|
||||
onValueChange={(val) => setExpiryDays(Number(val))}
|
||||
@@ -148,8 +158,8 @@ const InviteModal = ({ onClose, onCreated }) => {
|
||||
<SelectItem value="0">{t('app.inviteModal.never', 'Never')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</FormField>
|
||||
</FormRow>
|
||||
|
||||
{role !== 'admin' && (
|
||||
<div className="customize-permissions-section">
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "عبر مزود DNS الخاص بك.",
|
||||
"webrootPath": "مسار ويب روت",
|
||||
"wildcardCertificateDns01Validation": "شهادة حرف البدل (التحقق من صحة DNS-01)",
|
||||
"wildcardCertificateIssued": "تم إصدار شهادة البدل"
|
||||
"wildcardCertificateIssued": "تم إصدار شهادة البدل",
|
||||
"domainsRequired": "أدخل نطاقًا واحدًا على الأقل."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "فشلت المصادقة",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "الآن",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "أدخل نطاقًا.",
|
||||
"domainInvalid": "أدخل نطاقًا صالحًا.",
|
||||
"emailInvalid": "أدخل عنوان بريد إلكتروني صالحًا.",
|
||||
"required": "هذا الحقل مطلوب."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "আপনার DNS প্রদানকারীর মাধ্যমে।",
|
||||
"webrootPath": "ওয়েবরুট পথ",
|
||||
"wildcardCertificateDns01Validation": "ওয়াইল্ডকার্ড শংসাপত্র (DNS-01 বৈধতা)",
|
||||
"wildcardCertificateIssued": "ওয়াইল্ডকার্ড সার্টিফিকেট জারি করা হয়েছে"
|
||||
"wildcardCertificateIssued": "ওয়াইল্ডকার্ড সার্টিফিকেট জারি করা হয়েছে",
|
||||
"domainsRequired": "কমপক্ষে একটি ডোমেইন লিখুন।"
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "প্রমাণীকরণ ব্যর্থ হয়েছে৷",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "এইমাত্র",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "একটি ডোমেইন লিখুন।",
|
||||
"domainInvalid": "একটি বৈধ ডোমেইন লিখুন।",
|
||||
"emailInvalid": "একটি বৈধ ইমেইল ঠিকানা লিখুন।",
|
||||
"required": "এই ঘরটি পূরণ করা আবশ্যক।"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "über Ihren DNS-Anbieter.",
|
||||
"webrootPath": "Webroot-Pfad",
|
||||
"wildcardCertificateDns01Validation": "Wildcard-Zertifikat (DNS-01-Validierung)",
|
||||
"wildcardCertificateIssued": "Wildcard-Zertifikat ausgestellt"
|
||||
"wildcardCertificateIssued": "Wildcard-Zertifikat ausgestellt",
|
||||
"domainsRequired": "Gib mindestens eine Domain ein."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Authentifizierung fehlgeschlagen",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "gerade jetzt",
|
||||
"minutesShort": "{{count}}M"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Gib eine Domain ein.",
|
||||
"domainInvalid": "Gib eine gültige Domain ein.",
|
||||
"emailInvalid": "Gib eine gültige E-Mail-Adresse ein.",
|
||||
"required": "Dieses Feld ist erforderlich."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5235,6 +5235,7 @@
|
||||
"dnsProvider": "DNS provider",
|
||||
"documentRootForHttpValidation": "Document root for HTTP validation",
|
||||
"domainsLabel": "Domains",
|
||||
"domainsRequired": "Enter at least one domain.",
|
||||
"emailAddress": "Email address",
|
||||
"exampleComWwwExampleCom": "example.com, www.example.com",
|
||||
"expires": "Expires",
|
||||
@@ -8567,6 +8568,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "just now",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Enter a domain.",
|
||||
"domainInvalid": "Enter a valid domain.",
|
||||
"emailInvalid": "Enter a valid email address.",
|
||||
"required": "This field is required."
|
||||
}
|
||||
},
|
||||
"effectiveEnv": {
|
||||
|
||||
@@ -5102,7 +5102,8 @@
|
||||
"viaYourDnsProvider": "a través de tu proveedor de DNS.",
|
||||
"webrootPath": "Ruta del webroot",
|
||||
"wildcardCertificateDns01Validation": "Certificado comodín (validación DNS-01)",
|
||||
"wildcardCertificateIssued": "Certificado comodín emitido"
|
||||
"wildcardCertificateIssued": "Certificado comodín emitido",
|
||||
"domainsRequired": "Introduce al menos un dominio."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "La autenticación falló",
|
||||
@@ -8125,6 +8126,12 @@
|
||||
"hoursShort": "{{count}} h",
|
||||
"justNow": "ahora mismo",
|
||||
"minutesShort": "{{count}} min"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Introduce un dominio.",
|
||||
"domainInvalid": "Introduce un dominio válido.",
|
||||
"emailInvalid": "Introduce una dirección de correo válida.",
|
||||
"required": "Este campo es obligatorio."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "via votre fournisseur DNS.",
|
||||
"webrootPath": "Chemin de la racine Web",
|
||||
"wildcardCertificateDns01Validation": "Certificat générique (validation DNS-01)",
|
||||
"wildcardCertificateIssued": "Certificat Wildcard délivré"
|
||||
"wildcardCertificateIssued": "Certificat Wildcard délivré",
|
||||
"domainsRequired": "Saisissez au moins un domaine."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Échec de l'authentification",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "tout à l' heure",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Saisissez un domaine.",
|
||||
"domainInvalid": "Saisissez un domaine valide.",
|
||||
"emailInvalid": "Saisissez une adresse e-mail valide.",
|
||||
"required": "Ce champ est obligatoire."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "melalui penyedia DNS Anda.",
|
||||
"webrootPath": "Jalur Webroot",
|
||||
"wildcardCertificateDns01Validation": "Sertifikat wildcard (validasi DNS-01)",
|
||||
"wildcardCertificateIssued": "Sertifikat wildcard diterbitkan"
|
||||
"wildcardCertificateIssued": "Sertifikat wildcard diterbitkan",
|
||||
"domainsRequired": "Masukkan setidaknya satu domain."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Otentikasi Gagal",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "baru saja",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Masukkan domain.",
|
||||
"domainInvalid": "Masukkan domain yang valid.",
|
||||
"emailInvalid": "Masukkan alamat email yang valid.",
|
||||
"required": "Kolom ini wajib diisi."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "tramite il tuo fornitore DNS.",
|
||||
"webrootPath": "Percorso Webroot",
|
||||
"wildcardCertificateDns01Validation": "Certificato jolly (convalida DNS-01)",
|
||||
"wildcardCertificateIssued": "Certificato jolly rilasciato"
|
||||
"wildcardCertificateIssued": "Certificato jolly rilasciato",
|
||||
"domainsRequired": "Inserisci almeno un dominio."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Autenticazione non riuscita",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "proprio adesso",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Inserisci un dominio.",
|
||||
"domainInvalid": "Inserisci un dominio valido.",
|
||||
"emailInvalid": "Inserisci un indirizzo e-mail valido.",
|
||||
"required": "Questo campo è obbligatorio."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "DNS 공급자를 통해.",
|
||||
"webrootPath": "웹루트 경로",
|
||||
"wildcardCertificateDns01Validation": "와일드카드 인증서(DNS-01 검증)",
|
||||
"wildcardCertificateIssued": "와일드카드 인증서 발급됨"
|
||||
"wildcardCertificateIssued": "와일드카드 인증서 발급됨",
|
||||
"domainsRequired": "도메인을 하나 이상 입력하세요."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "인증 실패",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}시간",
|
||||
"justNow": "지금 막",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "도메인을 입력하세요.",
|
||||
"domainInvalid": "올바른 도메인을 입력하세요.",
|
||||
"emailInvalid": "올바른 이메일 주소를 입력하세요.",
|
||||
"required": "필수 입력 항목입니다."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "za pośrednictwem dostawcy DNS.",
|
||||
"webrootPath": "Ścieżka Webroota",
|
||||
"wildcardCertificateDns01Validation": "Certyfikat wieloznaczny (walidacja DNS-01)",
|
||||
"wildcardCertificateIssued": "Wydano certyfikat wieloznaczny"
|
||||
"wildcardCertificateIssued": "Wydano certyfikat wieloznaczny",
|
||||
"domainsRequired": "Podaj co najmniej jedną domenę."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Uwierzytelnianie nie powiodło się",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "właśnie",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Podaj domenę.",
|
||||
"domainInvalid": "Podaj prawidłową domenę.",
|
||||
"emailInvalid": "Podaj prawidłowy adres e-mail.",
|
||||
"required": "To pole jest wymagane."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "através do seu provedor de DNS.",
|
||||
"webrootPath": "Caminho Webroot",
|
||||
"wildcardCertificateDns01Validation": "Certificado curinga (validação DNS-01)",
|
||||
"wildcardCertificateIssued": "Certificado curinga emitido"
|
||||
"wildcardCertificateIssued": "Certificado curinga emitido",
|
||||
"domainsRequired": "Informe pelo menos um domínio."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Falha na autenticação",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "agora mesmo",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Informe um domínio.",
|
||||
"domainInvalid": "Informe um domínio válido.",
|
||||
"emailInvalid": "Informe um endereço de e-mail válido.",
|
||||
"required": "Este campo é obrigatório."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "через вашего DNS-провайдера.",
|
||||
"webrootPath": "Корневой веб-путь",
|
||||
"wildcardCertificateDns01Validation": "Подстановочный сертификат (проверка DNS-01)",
|
||||
"wildcardCertificateIssued": "Выдан сертификат Wildcard"
|
||||
"wildcardCertificateIssued": "Выдан сертификат Wildcard",
|
||||
"domainsRequired": "Укажите хотя бы один домен."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Аутентификация не удалась",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}} ч.",
|
||||
"justNow": "прямо сейчас",
|
||||
"minutesShort": "{{count}} м"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Укажите домен.",
|
||||
"domainInvalid": "Укажите корректный домен.",
|
||||
"emailInvalid": "Укажите корректный адрес электронной почты.",
|
||||
"required": "Это поле обязательно."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "ผ่านผู้ให้บริการ DNS ของคุณ",
|
||||
"webrootPath": "เส้นทางเว็บรูท",
|
||||
"wildcardCertificateDns01Validation": "ใบรับรองตัวแทน (การตรวจสอบ DNS-01)",
|
||||
"wildcardCertificateIssued": "ออกใบรับรองตัวแทนแล้ว"
|
||||
"wildcardCertificateIssued": "ออกใบรับรองตัวแทนแล้ว",
|
||||
"domainsRequired": "ป้อนโดเมนอย่างน้อยหนึ่งโดเมน"
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "การรับรองความถูกต้องล้มเหลว",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "แค่ตอนนี้",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "ป้อนโดเมน",
|
||||
"domainInvalid": "ป้อนโดเมนที่ถูกต้อง",
|
||||
"emailInvalid": "ป้อนที่อยู่อีเมลที่ถูกต้อง",
|
||||
"required": "จำเป็นต้องกรอกช่องนี้"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "DNS sağlayıcınız aracılığıyla.",
|
||||
"webrootPath": "Web kökü Yolu",
|
||||
"wildcardCertificateDns01Validation": "Joker karakter sertifikası (DNS-01 doğrulaması)",
|
||||
"wildcardCertificateIssued": "Joker karakter sertifikası verildi"
|
||||
"wildcardCertificateIssued": "Joker karakter sertifikası verildi",
|
||||
"domainsRequired": "En az bir alan adı girin."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Kimlik Doğrulama Başarısız",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "Şu anda",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Bir alan adı girin.",
|
||||
"domainInvalid": "Geçerli bir alan adı girin.",
|
||||
"emailInvalid": "Geçerli bir e-posta adresi girin.",
|
||||
"required": "Bu alan zorunludur."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "thông qua nhà cung cấp DNS của bạn.",
|
||||
"webrootPath": "Đường dẫn Webroot",
|
||||
"wildcardCertificateDns01Validation": "Chứng chỉ ký tự đại diện (xác thực DNS-01)",
|
||||
"wildcardCertificateIssued": "Chứng chỉ ký tự đại diện đã được cấp"
|
||||
"wildcardCertificateIssued": "Chứng chỉ ký tự đại diện đã được cấp",
|
||||
"domainsRequired": "Nhập ít nhất một tên miền."
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "Xác thực không thành công",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "ngay bây giờ",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "Nhập tên miền.",
|
||||
"domainInvalid": "Nhập tên miền hợp lệ.",
|
||||
"emailInvalid": "Nhập địa chỉ email hợp lệ.",
|
||||
"required": "Trường này là bắt buộc."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "通过您的 DNS 提供商。",
|
||||
"webrootPath": "网络根路径",
|
||||
"wildcardCertificateDns01Validation": "通配符证书(DNS-01 验证)",
|
||||
"wildcardCertificateIssued": "颁发通配符证书"
|
||||
"wildcardCertificateIssued": "颁发通配符证书",
|
||||
"domainsRequired": "请至少输入一个域名。"
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "认证失败",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}小时",
|
||||
"justNow": "现在",
|
||||
"minutesShort": "{{count}}米"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "请输入域名。",
|
||||
"domainInvalid": "请输入有效的域名。",
|
||||
"emailInvalid": "请输入有效的电子邮件地址。",
|
||||
"required": "此字段为必填项。"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -5101,7 +5101,8 @@
|
||||
"viaYourDnsProvider": "透過您的 DNS 提供者。",
|
||||
"webrootPath": "網站根目錄路徑",
|
||||
"wildcardCertificateDns01Validation": "萬用字元憑證(DNS-01 驗證)",
|
||||
"wildcardCertificateIssued": "簽發萬用字元憑證"
|
||||
"wildcardCertificateIssued": "簽發萬用字元憑證",
|
||||
"domainsRequired": "請至少輸入一個網域。"
|
||||
},
|
||||
"sSOCallback": {
|
||||
"authenticationFailed": "認證失敗",
|
||||
@@ -8124,6 +8125,12 @@
|
||||
"hoursShort": "{{count}}h",
|
||||
"justNow": "剛剛",
|
||||
"minutesShort": "{{count}}m"
|
||||
},
|
||||
"validation": {
|
||||
"domainEmpty": "請輸入網域。",
|
||||
"domainInvalid": "請輸入有效的網域。",
|
||||
"emailInvalid": "請輸入有效的電子郵件地址。",
|
||||
"required": "此欄位為必填。"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
|
||||
@@ -173,7 +173,9 @@ const Domains = () => {
|
||||
|
||||
const addErrors = useFieldErrors({
|
||||
app: selectedAppId ? null : t('app.domains.serviceRequired', 'Choose a service.'),
|
||||
domain: domainName ? null : t('app.domains.domainRequired', 'Enter a valid domain.'),
|
||||
domain: domainName ? null : (domainInfo && !domainInfo.empty
|
||||
? t('app.domains.domainRequired', 'Enter a valid domain.')
|
||||
: t('common.validation.domainEmpty', 'Enter a domain.')),
|
||||
}, fieldId);
|
||||
const closeAdd = () => { setShowAddModal(false); addErrors.reset(); };
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// rows this client never loaded), while the grid chrome's column rules narrow
|
||||
// the rows already on screen. A saved view carries both — the server pair under
|
||||
// `page.serverFilters`, the rules under `columnFilters`.
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
ChevronRight, Globe, Pause, Play, Plus, Radar, RefreshCw,
|
||||
@@ -29,7 +29,8 @@ import {
|
||||
import { Button } from '@/components/ui/button';
|
||||
import PagePrimaryButton from '@/components/PagePrimaryButton';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { FormField } from '@/components/FormField';
|
||||
import useFieldErrors from '@/hooks/useFieldErrors';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import {
|
||||
Select, SelectTrigger, SelectContent, SelectItem, SelectValue,
|
||||
@@ -254,7 +255,16 @@ export default function Monitors() {
|
||||
if (saved.serverFilters !== undefined) setFilters((f) => ({ ...f, ...saved.serverFilters }));
|
||||
}, []);
|
||||
|
||||
const openCreate = () => { setForm(emptyForm); setFormOpen(true); };
|
||||
const fieldId = useId();
|
||||
const required = t('common.validation.required', 'This field is required.');
|
||||
// The keyword only applies (and is only validated) for keyword checks.
|
||||
const fe = useFieldErrors({
|
||||
name: form.name.trim() ? null : required,
|
||||
target: form.check_target.trim() ? null : required,
|
||||
...(form.check_type === 'keyword' ? { keyword: form.keyword.trim() ? null : required } : {}),
|
||||
}, fieldId);
|
||||
|
||||
const openCreate = () => { fe.reset(); setForm(emptyForm); setFormOpen(true); };
|
||||
// Quick-create deep link: /monitoring/monitors?focus=create:monitor opens the form.
|
||||
useFocusParam('create', openCreate);
|
||||
|
||||
@@ -276,6 +286,7 @@ export default function Monitors() {
|
||||
|
||||
const onSave = async (e) => {
|
||||
e.preventDefault();
|
||||
if (!fe.attempt()) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
const payload = { ...form };
|
||||
@@ -293,6 +304,7 @@ export default function Monitors() {
|
||||
setFormOpen(false);
|
||||
load();
|
||||
} catch (err) {
|
||||
if (fe.fromServer(err)) return;
|
||||
toastError(toast, t('app.monitors.couldNotCreateTheMonitor', "Couldn't create the monitor."), err);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
@@ -568,17 +580,16 @@ export default function Monitors() {
|
||||
icon={<Radar size={18} />}
|
||||
>
|
||||
<form className="mon-form" onSubmit={onSave} data-walkthrough="monitor-form">
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-name">{t('common.labels.name', 'Name')}</Label>
|
||||
<FormField label={t('common.labels.name', 'Name')} htmlFor={`${fieldId}-name`} required error={fe.error('name')}>
|
||||
<Input
|
||||
id="mon-name" required value={form.name}
|
||||
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||
id={`${fieldId}-name`} value={form.name}
|
||||
onChange={(e) => { fe.clear('name'); setForm({ ...form, name: e.target.value }); }}
|
||||
onBlur={() => fe.touch('name')}
|
||||
placeholder={t('app.monitors.marketingSite', 'Marketing site')}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-type">{t('app.monitors.checkType', 'Check type')}</Label>
|
||||
<FormField label={t('app.monitors.checkType', 'Check type')} htmlFor="mon-type">
|
||||
<Select
|
||||
value={form.check_type}
|
||||
onValueChange={(v) => setForm({ ...form, check_type: v })}
|
||||
@@ -590,61 +601,57 @@ export default function Monitors() {
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</FormField>
|
||||
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-target">{t('common.labels.target', 'Target')}</Label>
|
||||
<FormField label={t('common.labels.target', 'Target')} htmlFor={`${fieldId}-target`} required error={fe.error('target')}>
|
||||
<Input
|
||||
id="mon-target" required value={form.check_target}
|
||||
onChange={(e) => setForm({ ...form, check_target: e.target.value })}
|
||||
id={`${fieldId}-target`} value={form.check_target}
|
||||
onChange={(e) => { fe.clear('target'); setForm({ ...form, check_target: e.target.value }); }}
|
||||
onBlur={() => fe.touch('target')}
|
||||
placeholder={TARGET_PLACEHOLDER[form.check_type]}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
|
||||
{form.check_type === 'keyword' && (
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-keyword">{t('app.monitors.keyword', 'Keyword')}</Label>
|
||||
<FormField
|
||||
label={t('app.monitors.keyword', 'Keyword')} htmlFor={`${fieldId}-keyword`} required
|
||||
hint={t('app.monitors.a200ResponseWithoutThisText', 'A 200 response without this text counts as an outage.')}
|
||||
error={fe.error('keyword')}
|
||||
>
|
||||
<Input
|
||||
id="mon-keyword" required value={form.keyword}
|
||||
onChange={(e) => setForm({ ...form, keyword: e.target.value })}
|
||||
id={`${fieldId}-keyword`} value={form.keyword}
|
||||
onChange={(e) => { fe.clear('keyword'); setForm({ ...form, keyword: e.target.value }); }}
|
||||
onBlur={() => fe.touch('keyword')}
|
||||
placeholder={t('app.monitors.proceedToCheckout', 'Proceed to checkout')}
|
||||
/>
|
||||
<span className="form-help">
|
||||
{t('app.monitors.a200ResponseWithoutThisText', 'A 200 response without this text counts as an outage.')}
|
||||
</span>
|
||||
</div>
|
||||
</FormField>
|
||||
)}
|
||||
|
||||
<div className="mon-form__row">
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-interval">{t('app.monitors.intervalS', 'Interval (s)')}</Label>
|
||||
<FormField label={t('app.monitors.intervalS', 'Interval (s)')} htmlFor="mon-interval">
|
||||
<Input
|
||||
id="mon-interval" type="number" min="30" max="86400" value={form.check_interval}
|
||||
onChange={(e) => setForm({ ...form, check_interval: Number(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-timeout">{t('app.monitors.timeoutS', 'Timeout (s)')}</Label>
|
||||
</FormField>
|
||||
<FormField label={t('app.monitors.timeoutS', 'Timeout (s)')} htmlFor="mon-timeout">
|
||||
<Input
|
||||
id="mon-timeout" type="number" min="1" max="120" value={form.check_timeout}
|
||||
onChange={(e) => setForm({ ...form, check_timeout: Number(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-retries">{t('app.monitors.retries', 'Retries')}</Label>
|
||||
</FormField>
|
||||
<FormField label={t('app.monitors.retries', 'Retries')} htmlFor="mon-retries" hint={t('app.monitors.failedChecksToleratedBeforeAnIncident', 'Failed checks tolerated before an incident opens.')}>
|
||||
<Input
|
||||
id="mon-retries" type="number" min="0" max="10" value={form.retries}
|
||||
onChange={(e) => setForm({ ...form, retries: Number(e.target.value) })}
|
||||
/>
|
||||
<span className="form-help">{t('app.monitors.failedChecksToleratedBeforeAnIncident', 'Failed checks tolerated before an incident opens.')}</span>
|
||||
</div>
|
||||
</FormField>
|
||||
</div>
|
||||
|
||||
{isHttpish && (
|
||||
<>
|
||||
<div className="mon-form__row">
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-method">{t('app.monitors.method', 'Method')}</Label>
|
||||
<FormField label={t('app.monitors.method', 'Method')} htmlFor="mon-method">
|
||||
<Select
|
||||
value={form.check_method}
|
||||
onValueChange={(v) => setForm({ ...form, check_method: v })}
|
||||
@@ -656,15 +663,14 @@ export default function Monitors() {
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="mon-expected">{t('app.monitors.expectedStatus', 'Expected status')}</Label>
|
||||
</FormField>
|
||||
<FormField label={t('app.monitors.expectedStatus', 'Expected status')} htmlFor="mon-expected">
|
||||
<Input
|
||||
id="mon-expected" value={form.expected_status}
|
||||
onChange={(e) => setForm({ ...form, expected_status: e.target.value })}
|
||||
placeholder="200-299"
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
</div>
|
||||
|
||||
<div className="mon-switch-row">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import { useState, useEffect, useCallback, useMemo, useId } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
Layers,
|
||||
@@ -24,6 +24,8 @@ import { Tip } from '@/components/ui/tooltip';
|
||||
import PageLayout from '../layouts/PageLayout';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { FormField, FormRow } from '@/components/FormField';
|
||||
import useFieldErrors from '@/hooks/useFieldErrors';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
Select, SelectTrigger, SelectContent, SelectItem, SelectValue,
|
||||
@@ -124,6 +126,28 @@ const QueueOperations = () => {
|
||||
|
||||
const [sendTarget, setSendTarget] = useState(null);
|
||||
const [sendForm, setSendForm] = useState({ payload: '{}', priority: 0, delay_ms: 0 });
|
||||
|
||||
const fieldId = useId();
|
||||
const required = t('common.validation.required', 'This field is required.');
|
||||
const jsonProblem = (text, invalid) => {
|
||||
try { JSON.parse(text); return null; } catch { return invalid; }
|
||||
};
|
||||
const groupErrors = useFieldErrors({
|
||||
name: groupForm.name.trim() ? null : required,
|
||||
}, `${fieldId}-group`);
|
||||
const queueErrors = useFieldErrors({
|
||||
group: (queueForm.groupSlug || selectedGroup) ? null : t('app.queueOperations.selectAGroupForTheQueue', 'Select a group for the queue'),
|
||||
name: queueForm.name.trim() ? null : required,
|
||||
config: jsonProblem(queueForm.config, t('app.queueOperations.configMustBeValidJson', 'Config must be valid JSON, like {"key": "value"}.')),
|
||||
}, `${fieldId}-queue`);
|
||||
const sendErrors = useFieldErrors({
|
||||
payload: sendForm.payload.trim()
|
||||
? jsonProblem(sendForm.payload, t('app.queueOperations.payloadMustBeValidJson', 'Payload must be valid JSON, like {"key": "value"}.'))
|
||||
: required,
|
||||
}, `${fieldId}-send`);
|
||||
const closeGroup = () => { setShowGroupModal(false); groupErrors.reset(); };
|
||||
const closeQueue = () => { setShowQueueModal(false); queueErrors.reset(); };
|
||||
const closeSend = () => { setSendTarget(null); sendErrors.reset(); };
|
||||
const { sorts, setSorts } = useTableSort({ storageKey: 'serverkit-table-queue-ops-sort' });
|
||||
const {
|
||||
hiddenKeys, setHiddenKeys,
|
||||
@@ -229,34 +253,27 @@ const QueueOperations = () => {
|
||||
|
||||
const handleCreateGroup = async (e) => {
|
||||
e.preventDefault();
|
||||
if (!groupErrors.attempt()) return;
|
||||
try {
|
||||
await api.createQueueGroup({
|
||||
name: groupForm.name,
|
||||
description: groupForm.description,
|
||||
});
|
||||
toast.success(t('app.queueOperations.queueGroupCreated', 'Queue group created'));
|
||||
setShowGroupModal(false);
|
||||
closeGroup();
|
||||
setGroupForm({ name: '', description: '' });
|
||||
loadData();
|
||||
} catch (err) {
|
||||
if (groupErrors.fromServer(err)) return;
|
||||
toastError(toast, t('app.queueOperations.couldntCreateGroup', "Couldn't create the group."), err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCreateQueue = async (e) => {
|
||||
e.preventDefault();
|
||||
if (!queueErrors.attempt()) return;
|
||||
const groupSlug = queueForm.groupSlug || selectedGroup;
|
||||
if (!groupSlug) {
|
||||
toast.error(t('app.queueOperations.selectAGroupForTheQueue', 'Select a group for the queue'));
|
||||
return;
|
||||
}
|
||||
let config = {};
|
||||
try {
|
||||
config = JSON.parse(queueForm.config);
|
||||
} catch (err) {
|
||||
toastError(toast, t('app.queueOperations.configMustBeValidJson', 'Config must be valid JSON, like {"key": "value"}.'), err);
|
||||
return;
|
||||
}
|
||||
const config = JSON.parse(queueForm.config);
|
||||
try {
|
||||
await api.createQueue(groupSlug, {
|
||||
name: queueForm.name,
|
||||
@@ -264,11 +281,12 @@ const QueueOperations = () => {
|
||||
config,
|
||||
});
|
||||
toast.success(t('app.queueOperations.queueCreated', 'Queue created'));
|
||||
setShowQueueModal(false);
|
||||
closeQueue();
|
||||
setQueueForm({ name: '', description: '', config: '{}' });
|
||||
loadQueues(selectedGroup);
|
||||
loadData();
|
||||
} catch (err) {
|
||||
if (queueErrors.fromServer(err)) return;
|
||||
toastError(toast, t('app.queueOperations.couldntCreateQueue', "Couldn't create the queue."), err);
|
||||
}
|
||||
};
|
||||
@@ -291,6 +309,7 @@ const QueueOperations = () => {
|
||||
};
|
||||
|
||||
const openSendModal = (queue) => {
|
||||
sendErrors.reset();
|
||||
setSendTarget(queue);
|
||||
setSendForm({ payload: '{}', priority: 0, delay_ms: 0 });
|
||||
};
|
||||
@@ -302,20 +321,15 @@ const QueueOperations = () => {
|
||||
toast.error(t('app.queueOperations.selectADestinationQueue', 'Select a destination queue'));
|
||||
return;
|
||||
}
|
||||
let payload = {};
|
||||
try {
|
||||
payload = JSON.parse(sendForm.payload);
|
||||
} catch (err) {
|
||||
toastError(toast, t('app.queueOperations.payloadMustBeValidJson', 'Payload must be valid JSON, like {"key": "value"}.'), err);
|
||||
return;
|
||||
}
|
||||
if (!sendErrors.attempt()) return;
|
||||
const payload = JSON.parse(sendForm.payload);
|
||||
try {
|
||||
await api.sendMessage(queue.group_slug, queue.slug, payload, {
|
||||
priority: parseInt(sendForm.priority, 10) || 0,
|
||||
delay_ms: parseInt(sendForm.delay_ms, 10) || 0,
|
||||
});
|
||||
toast.success(t('app.queueOperations.messageSent', 'Message sent'));
|
||||
setSendTarget(null);
|
||||
closeSend();
|
||||
loadQueues(selectedGroup);
|
||||
loadData();
|
||||
} catch (err) {
|
||||
@@ -680,64 +694,57 @@ const QueueOperations = () => {
|
||||
</div>
|
||||
|
||||
{/* Create Group Modal */}
|
||||
<Modal open={showGroupModal} onClose={() => setShowGroupModal(false)} title={t('app.queueOperations.createQueueGroup', 'Create queue group')}>
|
||||
<form onSubmit={handleCreateGroup}>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="group-name">{t('common.labels.name', 'Name')}</Label>
|
||||
<Input id="group-name" value={groupForm.name} onChange={(e) => setGroupForm({ ...groupForm, name: e.target.value })} required />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="group-description">{t('common.labels.description', 'Description')}</Label>
|
||||
<Input id="group-description" value={groupForm.description} onChange={(e) => setGroupForm({ ...groupForm, description: e.target.value })} />
|
||||
</div>
|
||||
<Modal open={showGroupModal} onClose={closeGroup} title={t('app.queueOperations.createQueueGroup', 'Create queue group')}>
|
||||
<form onSubmit={handleCreateGroup} noValidate>
|
||||
<FormField label={t('common.labels.name', 'Name')} htmlFor={`${fieldId}-group-name`} required error={groupErrors.error('name')}>
|
||||
<Input id={`${fieldId}-group-name`} value={groupForm.name} onChange={(e) => { groupErrors.clear('name'); setGroupForm({ ...groupForm, name: e.target.value }); }} onBlur={() => groupErrors.touch('name')} />
|
||||
</FormField>
|
||||
<FormField label={t('common.labels.description', 'Description')} htmlFor={`${fieldId}-group-description`}>
|
||||
<Input id={`${fieldId}-group-description`} value={groupForm.description} onChange={(e) => setGroupForm({ ...groupForm, description: e.target.value })} />
|
||||
</FormField>
|
||||
<div className="modal-actions">
|
||||
<Button type="button" variant="outline" onClick={() => setShowGroupModal(false)}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="button" variant="outline" onClick={closeGroup}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="submit">{t('app.queueOperations.createGroup', 'Create group')}</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
{/* Create Queue Modal */}
|
||||
<Modal open={showQueueModal} onClose={() => setShowQueueModal(false)} title={t('app.queueOperations.createQueue', 'Create queue')}>
|
||||
<form onSubmit={handleCreateQueue}>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="queue-group">{t('app.queueOperations.group', 'Group')}</Label>
|
||||
<Modal open={showQueueModal} onClose={closeQueue} title={t('app.queueOperations.createQueue', 'Create queue')}>
|
||||
<form onSubmit={handleCreateQueue} noValidate>
|
||||
<FormField label={t('app.queueOperations.group', 'Group')} htmlFor={`${fieldId}-queue-group`} required error={queueErrors.error('group')}>
|
||||
<Select
|
||||
value={queueForm.groupSlug || selectedGroup || ''}
|
||||
onValueChange={(v) => setQueueForm({ ...queueForm, groupSlug: v })}
|
||||
required
|
||||
>
|
||||
<SelectTrigger id="queue-group">
|
||||
<SelectTrigger id={`${fieldId}-queue-group`} onBlur={() => queueErrors.touch('group')}>
|
||||
<SelectValue placeholder={t('app.queueOperations.selectGroup', 'Select group')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{groups.map(g => <SelectItem key={g.id} value={g.slug}>{g.name}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="queue-name">{t('common.labels.name', 'Name')}</Label>
|
||||
<Input id="queue-name" value={queueForm.name} onChange={(e) => setQueueForm({ ...queueForm, name: e.target.value })} required />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="queue-description">{t('common.labels.description', 'Description')}</Label>
|
||||
<Input id="queue-description" value={queueForm.description} onChange={(e) => setQueueForm({ ...queueForm, description: e.target.value })} />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="queue-config">{t('app.queueOperations.configJson', 'Config (JSON)')}</Label>
|
||||
<Textarea id="queue-config" value={queueForm.config} onChange={(e) => setQueueForm({ ...queueForm, config: e.target.value })} rows={4} />
|
||||
</div>
|
||||
</FormField>
|
||||
<FormField label={t('common.labels.name', 'Name')} htmlFor={`${fieldId}-queue-name`} required error={queueErrors.error('name')}>
|
||||
<Input id={`${fieldId}-queue-name`} value={queueForm.name} onChange={(e) => setQueueForm({ ...queueForm, name: e.target.value })} onBlur={() => queueErrors.touch('name')} />
|
||||
</FormField>
|
||||
<FormField label={t('common.labels.description', 'Description')} htmlFor={`${fieldId}-queue-description`}>
|
||||
<Input id={`${fieldId}-queue-description`} value={queueForm.description} onChange={(e) => setQueueForm({ ...queueForm, description: e.target.value })} />
|
||||
</FormField>
|
||||
<FormField label={t('app.queueOperations.configJson', 'Config (JSON)')} htmlFor={`${fieldId}-queue-config`} error={queueErrors.error('config')}>
|
||||
<Textarea id={`${fieldId}-queue-config`} value={queueForm.config} onChange={(e) => setQueueForm({ ...queueForm, config: e.target.value })} onBlur={() => queueErrors.touch('config')} rows={4} />
|
||||
</FormField>
|
||||
<div className="modal-actions">
|
||||
<Button type="button" variant="outline" onClick={() => setShowQueueModal(false)}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="button" variant="outline" onClick={closeQueue}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="submit">{t('app.queueOperations.createQueue', 'Create queue')}</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
{/* Send Message Modal */}
|
||||
<Modal open={!!sendTarget} onClose={() => setSendTarget(null)} title={t('app.queueOperations.sendMessage2', 'Send message')}>
|
||||
<Modal open={!!sendTarget} onClose={closeSend} title={t('app.queueOperations.sendMessage2', 'Send message')}>
|
||||
{sendTarget && (
|
||||
<form onSubmit={handleSendMessage}>
|
||||
<form onSubmit={handleSendMessage} noValidate>
|
||||
<div className="queue-send-destination">
|
||||
<div>
|
||||
<Label>{t('app.queueOperations.group', 'Group')}</Label>
|
||||
@@ -748,28 +755,25 @@ const QueueOperations = () => {
|
||||
<div className="queue-send-readonly">{sendTarget.slug}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="payload">{t('app.queueOperations.payloadJson', 'Payload (JSON)')}</Label>
|
||||
<FormField label={t('app.queueOperations.payloadJson', 'Payload (JSON)')} htmlFor={`${fieldId}-send-payload`} required error={sendErrors.error('payload')}>
|
||||
<Textarea
|
||||
id="payload"
|
||||
id={`${fieldId}-send-payload`}
|
||||
value={sendForm.payload}
|
||||
onChange={(e) => setSendForm({ ...sendForm, payload: e.target.value })}
|
||||
onBlur={() => sendErrors.touch('payload')}
|
||||
rows={6}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<div className="form-group">
|
||||
<Label htmlFor="priority">{t('app.queueOperations.priority', 'Priority')}</Label>
|
||||
<Input id="priority" type="number" value={sendForm.priority} onChange={(e) => setSendForm({ ...sendForm, priority: e.target.value })} />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="delay_ms">{t('app.queueOperations.delayMs', 'Delay (ms)')}</Label>
|
||||
<Input id="delay_ms" type="number" value={sendForm.delay_ms} onChange={(e) => setSendForm({ ...sendForm, delay_ms: e.target.value })} />
|
||||
</div>
|
||||
</div>
|
||||
</FormField>
|
||||
<FormRow>
|
||||
<FormField label={t('app.queueOperations.priority', 'Priority')} htmlFor={`${fieldId}-send-priority`}>
|
||||
<Input id={`${fieldId}-send-priority`} type="number" value={sendForm.priority} onChange={(e) => setSendForm({ ...sendForm, priority: e.target.value })} />
|
||||
</FormField>
|
||||
<FormField label={t('app.queueOperations.delayMs', 'Delay (ms)')} htmlFor={`${fieldId}-send-delay`}>
|
||||
<Input id={`${fieldId}-send-delay`} type="number" value={sendForm.delay_ms} onChange={(e) => setSendForm({ ...sendForm, delay_ms: e.target.value })} />
|
||||
</FormField>
|
||||
</FormRow>
|
||||
<div className="modal-actions">
|
||||
<Button type="button" variant="outline" onClick={() => setSendTarget(null)}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="button" variant="outline" onClick={closeSend}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="submit"><Send size={14} className="queue-action-icon" /> {t('app.queueOperations.sendMessage2', 'Send message')}</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -13,7 +13,8 @@ import { useToast } from '../contexts/useToast.js';
|
||||
import { useConfirm } from '../hooks/useConfirm';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { FormField } from '@/components/FormField';
|
||||
import useFieldErrors from '@/hooks/useFieldErrors';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import {
|
||||
Select, SelectTrigger, SelectContent, SelectItem, SelectValue,
|
||||
@@ -130,6 +131,40 @@ const SSLCertificates = () => {
|
||||
const [uploadCert, setUploadCert] = useState('');
|
||||
const [uploadKey, setUploadKey] = useState('');
|
||||
const [uploadChain, setUploadChain] = useState('');
|
||||
const [domainInfo, setDomainInfo] = useState(null);
|
||||
const [uploadDomainInfo, setUploadDomainInfo] = useState(null);
|
||||
|
||||
const required = t('common.validation.required', 'This field is required.');
|
||||
const domainProblem = (value, info) => {
|
||||
if (value) return null;
|
||||
return info && !info.empty
|
||||
? t('common.validation.domainInvalid', 'Enter a valid domain.')
|
||||
: t('common.validation.domainEmpty', 'Enter a domain.');
|
||||
};
|
||||
const hasDomains = domains.split(',').some((d) => d.trim());
|
||||
// Only the fields that apply to the chosen method are validated, in DOM order.
|
||||
const obtainErrors = useFieldErrors({
|
||||
domains: wildcard
|
||||
? domainProblem(domains, domainInfo)
|
||||
: (hasDomains ? null : t('app.sSLCertificates.domainsRequired', 'Enter at least one domain.')),
|
||||
...(wildcard ? {} : {
|
||||
email: !email.trim() ? required
|
||||
: (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim()) ? null : t('common.validation.emailInvalid', 'Enter a valid email address.')),
|
||||
webroot: !useNginx && !webrootPath.trim() ? required : null,
|
||||
}),
|
||||
...(wildcard && dnsProvider === 'cloudflare' ? { cftoken: dnsToken ? null : required } : {}),
|
||||
...(wildcard && dnsProvider !== 'cloudflare' ? {
|
||||
awskey: awsAccessKey ? null : required,
|
||||
awssecret: awsSecretKey ? null : required,
|
||||
} : {}),
|
||||
}, fieldId);
|
||||
const uploadErrors = useFieldErrors({
|
||||
domain: domainProblem(uploadDomain, uploadDomainInfo),
|
||||
cert: uploadCert.trim() ? null : required,
|
||||
key: uploadKey.trim() ? null : required,
|
||||
}, `${fieldId}-up`);
|
||||
const closeObtain = () => { setShowObtainModal(false); obtainErrors.reset(); };
|
||||
const closeUpload = () => { setShowUploadModal(false); uploadErrors.reset(); };
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
@@ -150,8 +185,8 @@ const SSLCertificates = () => {
|
||||
|
||||
async function handleObtainCertificate(e) {
|
||||
e.preventDefault();
|
||||
if (!obtainErrors.attempt()) return;
|
||||
const domainList = domains.split(',').map(d => d.trim()).filter(Boolean);
|
||||
if (domainList.length === 0) return;
|
||||
|
||||
try {
|
||||
setActionLoading(true);
|
||||
@@ -163,14 +198,13 @@ const SSLCertificates = () => {
|
||||
: { aws_access_key_id: awsAccessKey, aws_secret_access_key: awsSecretKey };
|
||||
result = await api.issueWildcardCert(domainList[0], dnsProvider, credentials);
|
||||
} else {
|
||||
if (!email) return;
|
||||
const data = { domains: domainList, email, use_nginx: useNginx };
|
||||
if (!useNginx && webrootPath) data.webroot_path = webrootPath;
|
||||
result = await api.obtainCertificate(data);
|
||||
}
|
||||
if (result.success) {
|
||||
toast.success(wildcard ? t('app.sSLCertificates.wildcardCertificateIssued', 'Wildcard certificate issued') : t('app.sSLCertificates.certificateObtainedSuccessfully', 'Certificate obtained'));
|
||||
setShowObtainModal(false);
|
||||
closeObtain();
|
||||
setDomains('');
|
||||
setEmail('');
|
||||
setDnsToken('');
|
||||
@@ -190,14 +224,14 @@ const SSLCertificates = () => {
|
||||
|
||||
async function handleUploadCertificate(e) {
|
||||
e.preventDefault();
|
||||
if (!uploadDomain || !uploadCert || !uploadKey) return;
|
||||
if (!uploadErrors.attempt()) return;
|
||||
try {
|
||||
setActionLoading(true);
|
||||
const result = await api.uploadCustomCert(uploadDomain.trim(), uploadCert, uploadKey, uploadChain || null);
|
||||
// upload returns the saved cert paths (no `success` envelope).
|
||||
if (result && (result.cert_path || result.success)) {
|
||||
toast.success(t('app.sSLCertificates.certificateUploadedFor', 'Certificate uploaded for {{uploadDomain}}', { uploadDomain: uploadDomain }));
|
||||
setShowUploadModal(false);
|
||||
closeUpload();
|
||||
setUploadDomain('');
|
||||
setUploadCert('');
|
||||
setUploadKey('');
|
||||
@@ -588,8 +622,8 @@ const SSLCertificates = () => {
|
||||
/>
|
||||
|
||||
{/* Obtain Certificate Modal */}
|
||||
<Modal open={showObtainModal} onClose={() => setShowObtainModal(false)} title={t('app.sSLCertificates.obtainSslCertificate', 'Obtain SSL certificate')}>
|
||||
<form onSubmit={handleObtainCertificate}>
|
||||
<Modal open={showObtainModal} onClose={closeObtain} title={t('app.sSLCertificates.obtainSslCertificate', 'Obtain SSL certificate')}>
|
||||
<form onSubmit={handleObtainCertificate} noValidate>
|
||||
<div className="ssl-info-box">
|
||||
<ShieldCheck size={32} />
|
||||
<div>
|
||||
@@ -607,42 +641,52 @@ const SSLCertificates = () => {
|
||||
</label>
|
||||
<p className="hint">{t('app.sSLCertificates.issues', 'Issues')} <code>domain</code> + <code>*.domain</code> {t('app.sSLCertificates.viaYourDnsProvider', 'via your DNS provider.')}</p>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="ssl-domains">{wildcard ? t('app.sSLCertificates.baseDomain', 'Base domain') : t('app.sSLCertificates.domainsLabel', 'Domains')}</Label>
|
||||
<FormField
|
||||
label={wildcard ? t('app.sSLCertificates.baseDomain', 'Base domain') : t('app.sSLCertificates.domainsLabel', 'Domains')}
|
||||
htmlFor={`${fieldId}-domains`}
|
||||
required
|
||||
hint={wildcard ? t('app.sSLCertificates.singleBaseDomainHint', 'A single base domain for the wildcard certificate') : t('app.sSLCertificates.commaSeparatedDomainsHint', 'Comma-separated list of domains')}
|
||||
error={obtainErrors.error('domains')}
|
||||
>
|
||||
{/* A wildcard cert covers one base domain; HTTP-01
|
||||
takes a comma-separated list, so it keeps a plain input. */}
|
||||
{wildcard ? (
|
||||
<DomainField
|
||||
id="ssl-domains"
|
||||
modes={['custom']}
|
||||
value={domains}
|
||||
onChange={(fqdn) => setDomains(fqdn)}
|
||||
/>
|
||||
<div onBlur={() => obtainErrors.touch('domains')}>
|
||||
<DomainField
|
||||
id={`${fieldId}-domains`}
|
||||
modes={['custom']}
|
||||
value={domains}
|
||||
onChange={(fqdn, info) => { setDomains(fqdn); setDomainInfo(info); }}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<Input
|
||||
id="ssl-domains"
|
||||
id={`${fieldId}-domains`}
|
||||
type="text"
|
||||
placeholder={t('app.sSLCertificates.exampleComWwwExampleCom', 'example.com, www.example.com')}
|
||||
value={domains}
|
||||
onChange={e => setDomains(e.target.value)}
|
||||
required
|
||||
onBlur={() => obtainErrors.touch('domains')}
|
||||
/>
|
||||
)}
|
||||
<p className="hint">{wildcard ? t('app.sSLCertificates.singleBaseDomainHint', 'A single base domain for the wildcard certificate') : t('app.sSLCertificates.commaSeparatedDomainsHint', 'Comma-separated list of domains')}</p>
|
||||
</div>
|
||||
</FormField>
|
||||
{!wildcard && (
|
||||
<>
|
||||
<div className="form-group">
|
||||
<Label htmlFor={`${fieldId}-email`}>{t('app.sSLCertificates.emailAddress', 'Email address')}</Label>
|
||||
<FormField
|
||||
label={t('app.sSLCertificates.emailAddress', 'Email address')}
|
||||
htmlFor={`${fieldId}-email`}
|
||||
required
|
||||
hint={t('app.sSLCertificates.forCertificateExpirationNotifications', 'For certificate expiration notifications')}
|
||||
error={obtainErrors.error('email')}
|
||||
>
|
||||
<Input id={`${fieldId}-email`}
|
||||
type="email"
|
||||
placeholder="admin@example.com"
|
||||
value={email}
|
||||
onChange={e => setEmail(e.target.value)}
|
||||
required={!wildcard}
|
||||
onBlur={() => obtainErrors.touch('email')}
|
||||
/>
|
||||
<p className="hint">{t('app.sSLCertificates.forCertificateExpirationNotifications', 'For certificate expiration notifications')}</p>
|
||||
</div>
|
||||
</FormField>
|
||||
<div className="form-group">
|
||||
<label className="checkbox-label">
|
||||
<Checkbox
|
||||
@@ -653,63 +697,63 @@ const SSLCertificates = () => {
|
||||
</label>
|
||||
</div>
|
||||
{!useNginx && (
|
||||
<div className="form-group">
|
||||
<Label htmlFor={`${fieldId}-webroot`}>{t('app.sSLCertificates.webrootPath', 'Webroot path')}</Label>
|
||||
<FormField
|
||||
label={t('app.sSLCertificates.webrootPath', 'Webroot path')}
|
||||
htmlFor={`${fieldId}-webroot`}
|
||||
required
|
||||
hint={t('app.sSLCertificates.documentRootForHttpValidation', 'Document root for HTTP validation')}
|
||||
error={obtainErrors.error('webroot')}
|
||||
>
|
||||
<Input id={`${fieldId}-webroot`}
|
||||
type="text"
|
||||
placeholder="/var/www/html"
|
||||
value={webrootPath}
|
||||
onChange={e => setWebrootPath(e.target.value)}
|
||||
required={!useNginx}
|
||||
onBlur={() => obtainErrors.touch('webroot')}
|
||||
/>
|
||||
<p className="hint">{t('app.sSLCertificates.documentRootForHttpValidation', 'Document root for HTTP validation')}</p>
|
||||
</div>
|
||||
</FormField>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{wildcard && (
|
||||
<>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="ssl-dns-provider">{t('app.sSLCertificates.dnsProvider', 'DNS provider')}</Label>
|
||||
<FormField label={t('app.sSLCertificates.dnsProvider', 'DNS provider')} htmlFor={`${fieldId}-dns-provider`}>
|
||||
<Select value={dnsProvider} onValueChange={setDnsProvider}>
|
||||
<SelectTrigger id="ssl-dns-provider"><SelectValue /></SelectTrigger>
|
||||
<SelectTrigger id={`${fieldId}-dns-provider`}><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="cloudflare">{t('app.sSLCertificates.cloudflare', 'Cloudflare')}</SelectItem>
|
||||
<SelectItem value="route53">{t('app.sSLCertificates.awsRoute53', 'AWS Route 53')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</FormField>
|
||||
{dnsProvider === 'cloudflare' ? (
|
||||
<div className="form-group">
|
||||
<Label htmlFor={`${fieldId}-cf-token`}>{t('app.sSLCertificates.cloudflareApiToken', 'Cloudflare API token')}</Label>
|
||||
<Input id={`${fieldId}-cf-token`}
|
||||
<FormField label={t('app.sSLCertificates.cloudflareApiToken', 'Cloudflare API token')} htmlFor={`${fieldId}-cftoken`} required error={obtainErrors.error('cftoken')}>
|
||||
<Input id={`${fieldId}-cftoken`}
|
||||
type="password"
|
||||
placeholder={t('app.sSLCertificates.apiTokenWithDnsEditRights', 'API token with DNS edit rights')}
|
||||
value={dnsToken}
|
||||
onChange={e => setDnsToken(e.target.value)}
|
||||
required={wildcard}
|
||||
onBlur={() => obtainErrors.touch('cftoken')}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
) : (
|
||||
<>
|
||||
<div className="form-group">
|
||||
<Label htmlFor={`${fieldId}-aws-access-key`}>{t('app.sSLCertificates.awsAccessKeyId', 'AWS access key ID')}</Label>
|
||||
<Input id={`${fieldId}-aws-access-key`}
|
||||
<FormField label={t('app.sSLCertificates.awsAccessKeyId', 'AWS access key ID')} htmlFor={`${fieldId}-awskey`} required error={obtainErrors.error('awskey')}>
|
||||
<Input id={`${fieldId}-awskey`}
|
||||
type="text"
|
||||
value={awsAccessKey}
|
||||
onChange={e => setAwsAccessKey(e.target.value)}
|
||||
required={wildcard}
|
||||
onBlur={() => obtainErrors.touch('awskey')}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor={`${fieldId}-aws-secret-key`}>{t('app.sSLCertificates.awsSecretAccessKey', 'AWS secret access key')}</Label>
|
||||
<Input id={`${fieldId}-aws-secret-key`}
|
||||
</FormField>
|
||||
<FormField label={t('app.sSLCertificates.awsSecretAccessKey', 'AWS secret access key')} htmlFor={`${fieldId}-awssecret`} required error={obtainErrors.error('awssecret')}>
|
||||
<Input id={`${fieldId}-awssecret`}
|
||||
type="password"
|
||||
value={awsSecretKey}
|
||||
onChange={e => setAwsSecretKey(e.target.value)}
|
||||
required={wildcard}
|
||||
onBlur={() => obtainErrors.touch('awssecret')}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
@@ -718,13 +762,13 @@ const SSLCertificates = () => {
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => setShowObtainModal(false)}
|
||||
onClick={closeObtain}
|
||||
>
|
||||
{t('common.actions.cancel', 'Cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={actionLoading || (wildcard && !domains)}
|
||||
disabled={actionLoading}
|
||||
>
|
||||
{actionLoading ? t('app.sSLCertificates.obtaining', 'Obtaining…') : t('app.sSLCertificates.obtainCertificateAction', 'Obtain certificate')}
|
||||
</Button>
|
||||
@@ -733,8 +777,8 @@ const SSLCertificates = () => {
|
||||
</Modal>
|
||||
|
||||
{/* Upload Custom Certificate Modal */}
|
||||
<Modal open={showUploadModal} onClose={() => setShowUploadModal(false)} title={t('app.sSLCertificates.uploadCustomCertificate', 'Upload custom certificate')}>
|
||||
<form onSubmit={handleUploadCertificate}>
|
||||
<Modal open={showUploadModal} onClose={closeUpload} title={t('app.sSLCertificates.uploadCustomCertificate', 'Upload custom certificate')}>
|
||||
<form onSubmit={handleUploadCertificate} noValidate>
|
||||
<div className="ssl-info-box">
|
||||
<Upload size={32} />
|
||||
<div>
|
||||
@@ -742,39 +786,37 @@ const SSLCertificates = () => {
|
||||
<p>{t('app.sSLCertificates.pasteAPemCertificatePrivateKey', 'Paste a PEM certificate, private key, and (optional) chain issued elsewhere.')}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor="ssl-upload-domain">{t('common.labels.domain', 'Domain')}</Label>
|
||||
<DomainField
|
||||
id="ssl-upload-domain"
|
||||
modes={['custom']}
|
||||
value={uploadDomain}
|
||||
onChange={(fqdn) => setUploadDomain(fqdn)}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor={`${fieldId}-cert-pem`}>{t('app.sSLCertificates.certificatePem', 'Certificate (PEM)')}</Label>
|
||||
<textarea id={`${fieldId}-cert-pem`}
|
||||
<FormField label={t('common.labels.domain', 'Domain')} htmlFor={`${fieldId}-up-domain`} required error={uploadErrors.error('domain')}>
|
||||
<div onBlur={() => uploadErrors.touch('domain')}>
|
||||
<DomainField
|
||||
id={`${fieldId}-up-domain`}
|
||||
modes={['custom']}
|
||||
value={uploadDomain}
|
||||
onChange={(fqdn, info) => { setUploadDomain(fqdn); setUploadDomainInfo(info); }}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
<FormField label={t('app.sSLCertificates.certificatePem', 'Certificate (PEM)')} htmlFor={`${fieldId}-up-cert`} required error={uploadErrors.error('cert')}>
|
||||
<textarea id={`${fieldId}-up-cert`}
|
||||
className="ui-textarea ssl-pem-input"
|
||||
rows={5}
|
||||
placeholder={t('app.sSLCertificates.beginCertificate', '-----BEGIN CERTIFICATE-----')}
|
||||
value={uploadCert}
|
||||
onChange={e => setUploadCert(e.target.value)}
|
||||
required
|
||||
onBlur={() => uploadErrors.touch('cert')}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor={`${fieldId}-key-pem`}>{t('app.sSLCertificates.privateKeyPem', 'Private key (PEM)')}</Label>
|
||||
<textarea id={`${fieldId}-key-pem`}
|
||||
</FormField>
|
||||
<FormField label={t('app.sSLCertificates.privateKeyPem', 'Private key (PEM)')} htmlFor={`${fieldId}-up-key`} required error={uploadErrors.error('key')}>
|
||||
<textarea id={`${fieldId}-up-key`}
|
||||
className="ui-textarea ssl-pem-input"
|
||||
rows={5}
|
||||
placeholder={t('app.sSLCertificates.beginPrivateKey', '-----BEGIN PRIVATE KEY-----')}
|
||||
value={uploadKey}
|
||||
onChange={e => setUploadKey(e.target.value)}
|
||||
required
|
||||
onBlur={() => uploadErrors.touch('key')}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<Label htmlFor={`${fieldId}-chain-pem`}>{t('app.sSLCertificates.chainPemOptional', 'Chain (PEM, optional)')}</Label>
|
||||
</FormField>
|
||||
<FormField label={t('app.sSLCertificates.chainPemOptional', 'Chain (PEM, optional)')} htmlFor={`${fieldId}-chain-pem`}>
|
||||
<textarea id={`${fieldId}-chain-pem`}
|
||||
className="ui-textarea ssl-pem-input"
|
||||
rows={4}
|
||||
@@ -782,12 +824,12 @@ const SSLCertificates = () => {
|
||||
value={uploadChain}
|
||||
onChange={e => setUploadChain(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
<div className="modal-actions">
|
||||
<Button type="button" variant="outline" onClick={() => setShowUploadModal(false)}>
|
||||
<Button type="button" variant="outline" onClick={closeUpload}>
|
||||
{t('common.actions.cancel', 'Cancel')}
|
||||
</Button>
|
||||
<Button type="submit" disabled={actionLoading || !uploadDomain}>
|
||||
<Button type="submit" disabled={actionLoading}>
|
||||
{actionLoading ? t('app.sSLCertificates.uploading', 'Uploading…') : t('app.sSLCertificates.uploadCertificateAction', 'Upload certificate')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,8 @@ import { Button } from '@/components/ui/button';
|
||||
import PagePrimaryButton from '@/components/PagePrimaryButton';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { FormField } from '@/components/FormField';
|
||||
import useFieldErrors from '@/hooks/useFieldErrors';
|
||||
import {
|
||||
Select, SelectTrigger, SelectContent, SelectItem, SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
@@ -128,6 +130,22 @@ const StatusPages = () => {
|
||||
const [compForm, setCompForm] = useState(defaultCompForm);
|
||||
const [incidentForm, setIncidentForm] = useState(defaultIncidentForm);
|
||||
|
||||
const required = t('common.validation.required', 'This field is required.');
|
||||
const pageErrors = useFieldErrors({
|
||||
name: pageForm.name.trim() ? null : required,
|
||||
slug: pageForm.slug.trim() ? null : required,
|
||||
}, `${fieldId}-page`);
|
||||
const compErrors = useFieldErrors({
|
||||
name: compForm.name.trim() ? null : required,
|
||||
target: compForm.check_target.trim() ? null : required,
|
||||
}, `${fieldId}-comp`);
|
||||
const incidentErrors = useFieldErrors({
|
||||
title: incidentForm.title.trim() ? null : required,
|
||||
}, `${fieldId}-incident`);
|
||||
const closePage = () => { setShowCreatePage(false); pageErrors.reset(); };
|
||||
const closeComponent = () => { setShowCreateComponent(false); compErrors.reset(); };
|
||||
const closeIncident = () => { setShowCreateIncident(false); incidentErrors.reset(); };
|
||||
|
||||
const isAdmin = Boolean(user?.is_admin);
|
||||
|
||||
const groupedComponents = useMemo(() => {
|
||||
@@ -233,31 +251,35 @@ const StatusPages = () => {
|
||||
};
|
||||
|
||||
const handleCreatePage = async () => {
|
||||
if (!pageErrors.attempt()) return;
|
||||
try {
|
||||
const page = await api.createStatusPage({
|
||||
...pageForm,
|
||||
slug: normalizeSlug(pageForm.slug),
|
||||
});
|
||||
toast.success(t('app.statusPages.statusPageCreated', 'Status page created'));
|
||||
setShowCreatePage(false);
|
||||
closePage();
|
||||
setPageForm(defaultPageForm);
|
||||
setPages((current) => [...current, page].sort((a, b) => a.name.localeCompare(b.name)));
|
||||
await loadPageDetails(page);
|
||||
} catch (err) {
|
||||
if (pageErrors.fromServer(err)) return;
|
||||
toastError(toast, t('app.statusPages.failedToCreateStatusPage', "Couldn't create the status page."), err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCreateComponent = async () => {
|
||||
if (!selectedPage) return;
|
||||
if (!compErrors.attempt()) return;
|
||||
try {
|
||||
await api.createStatusComponent(selectedPage.id, compForm);
|
||||
toast.success(t('app.statusPages.componentAdded', 'Component added'));
|
||||
setShowCreateComponent(false);
|
||||
closeComponent();
|
||||
setCompForm(defaultCompForm);
|
||||
await loadPageDetails(selectedPage);
|
||||
await loadPages();
|
||||
} catch (err) {
|
||||
if (compErrors.fromServer(err)) return;
|
||||
toastError(toast, t('app.statusPages.failedToAddComponent', "Couldn't add the component."), err);
|
||||
}
|
||||
};
|
||||
@@ -274,13 +296,15 @@ const StatusPages = () => {
|
||||
|
||||
const handleCreateIncident = async () => {
|
||||
if (!selectedPage) return;
|
||||
if (!incidentErrors.attempt()) return;
|
||||
try {
|
||||
await api.createStatusIncident(selectedPage.id, incidentForm);
|
||||
toast.success(t('app.statusPages.incidentCreated', 'Incident created'));
|
||||
setShowCreateIncident(false);
|
||||
closeIncident();
|
||||
setIncidentForm(defaultIncidentForm);
|
||||
await loadPageDetails(selectedPage);
|
||||
} catch (err) {
|
||||
if (incidentErrors.fromServer(err)) return;
|
||||
toastError(toast, t('app.statusPages.failedToCreateIncident', "Couldn't create the incident."), err);
|
||||
}
|
||||
};
|
||||
@@ -622,40 +646,38 @@ const StatusPages = () => {
|
||||
|
||||
<Modal
|
||||
open={showCreatePage}
|
||||
onClose={() => setShowCreatePage(false)}
|
||||
onClose={closePage}
|
||||
onSubmit={handleCreatePage}
|
||||
title={t('app.statusPages.createStatusPage', 'Create status page')}
|
||||
size="lg"
|
||||
className="status-modal"
|
||||
footer={(
|
||||
<>
|
||||
<Button variant="outline" onClick={() => setShowCreatePage(false)}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button onClick={handleCreatePage} disabled={!pageForm.name.trim() || !pageForm.slug.trim()}>
|
||||
<Button type="button" variant="outline" onClick={closePage}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="submit">
|
||||
{t('common.actions.create', 'Create')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-page-name`}>{t('common.labels.name', 'Name')}</label>
|
||||
<Input id={`${fieldId}-page-name`} value={pageForm.name} onChange={(e) => handlePageNameChange(e.target.value)} autoFocus />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-page-slug`}>{t('app.statusPages.slug', 'Slug')}</label>
|
||||
<FormField label={t('common.labels.name', 'Name')} htmlFor={`${fieldId}-page-name`} required error={pageErrors.error('name')}>
|
||||
<Input id={`${fieldId}-page-name`} value={pageForm.name} onChange={(e) => { pageErrors.clear('name'); handlePageNameChange(e.target.value); }} onBlur={() => pageErrors.touch('name')} autoFocus />
|
||||
</FormField>
|
||||
<FormField label={t('app.statusPages.slug', 'Slug')} htmlFor={`${fieldId}-page-slug`} required hint={`/status/${pageForm.slug || 'my-services'}`} error={pageErrors.error('slug')}>
|
||||
<Input id={`${fieldId}-page-slug`}
|
||||
value={pageForm.slug}
|
||||
onChange={(e) => setPageForm({ ...pageForm, slug: normalizeSlug(e.target.value) })}
|
||||
onChange={(e) => { pageErrors.clear('slug'); setPageForm({ ...pageForm, slug: normalizeSlug(e.target.value) }); }}
|
||||
onBlur={() => pageErrors.touch('slug')}
|
||||
placeholder="my-services"
|
||||
/>
|
||||
<span className="form-help">/status/{pageForm.slug || 'my-services'}</span>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-page-description`}>{t('common.labels.description', 'Description')}</label>
|
||||
</FormField>
|
||||
<FormField label={t('common.labels.description', 'Description')} htmlFor={`${fieldId}-page-description`}>
|
||||
<Textarea id={`${fieldId}-page-description`}
|
||||
value={pageForm.description}
|
||||
onChange={(e) => setPageForm({ ...pageForm, description: e.target.value })}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
@@ -694,30 +716,28 @@ const StatusPages = () => {
|
||||
|
||||
<Modal
|
||||
open={showCreateComponent}
|
||||
onClose={() => setShowCreateComponent(false)}
|
||||
onClose={closeComponent}
|
||||
onSubmit={handleCreateComponent}
|
||||
title={t('app.statusPages.addComponent', 'New component')}
|
||||
size="lg"
|
||||
className="status-modal"
|
||||
footer={(
|
||||
<>
|
||||
<Button variant="outline" onClick={() => setShowCreateComponent(false)}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button onClick={handleCreateComponent} disabled={!compForm.name.trim() || !compForm.check_target.trim()}>
|
||||
<Button type="button" variant="outline" onClick={closeComponent}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="submit">
|
||||
{t('app.statusPages.createComponent', 'Create component')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
>
|
||||
<div className="status-modal-grid">
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-comp-name`}>{t('common.labels.name', 'Name')}</label>
|
||||
<Input id={`${fieldId}-comp-name`} value={compForm.name} onChange={(e) => setCompForm({ ...compForm, name: e.target.value })} autoFocus />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-comp-group`}>{t('app.statusPages.group', 'Group')}</label>
|
||||
<FormField label={t('common.labels.name', 'Name')} htmlFor={`${fieldId}-comp-name`} required error={compErrors.error('name')}>
|
||||
<Input id={`${fieldId}-comp-name`} value={compForm.name} onChange={(e) => { compErrors.clear('name'); setCompForm({ ...compForm, name: e.target.value }); }} onBlur={() => compErrors.touch('name')} autoFocus />
|
||||
</FormField>
|
||||
<FormField label={t('app.statusPages.group', 'Group')} htmlFor={`${fieldId}-comp-group`}>
|
||||
<Input id={`${fieldId}-comp-group`} value={compForm.group} onChange={(e) => setCompForm({ ...compForm, group: e.target.value })} />
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor="status-comp-check-type">{t('app.statusPages.checkType', 'Check type')}</label>
|
||||
</FormField>
|
||||
<FormField label={t('app.statusPages.checkType', 'Check type')} htmlFor="status-comp-check-type">
|
||||
<Select
|
||||
value={compForm.check_type}
|
||||
onValueChange={(v) => setCompForm({ ...compForm, check_type: v })}
|
||||
@@ -730,58 +750,55 @@ const StatusPages = () => {
|
||||
<SelectItem value="ping">{t('app.statusPages.ping', 'Ping')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-comp-target`}>{t('common.labels.target', 'Target')}</label>
|
||||
</FormField>
|
||||
<FormField label={t('common.labels.target', 'Target')} htmlFor={`${fieldId}-comp-target`} required error={compErrors.error('target')}>
|
||||
<Input id={`${fieldId}-comp-target`}
|
||||
value={compForm.check_target}
|
||||
onChange={(e) => setCompForm({ ...compForm, check_target: e.target.value })}
|
||||
onChange={(e) => { compErrors.clear('target'); setCompForm({ ...compForm, check_target: e.target.value }); }}
|
||||
onBlur={() => compErrors.touch('target')}
|
||||
placeholder={CHECK_TARGET_PLACEHOLDERS[compForm.check_type]}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-comp-interval`}>{t('app.statusPages.interval', 'Interval')}</label>
|
||||
</FormField>
|
||||
<FormField label={t('app.statusPages.interval', 'Interval')} htmlFor={`${fieldId}-comp-interval`}>
|
||||
<Input id={`${fieldId}-comp-interval`}
|
||||
type="number"
|
||||
min="30"
|
||||
value={compForm.check_interval}
|
||||
onChange={(e) => setCompForm({ ...compForm, check_interval: parseInt(e.target.value, 10) || 60 })}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-comp-timeout`}>{t('app.statusPages.timeout', 'Timeout')}</label>
|
||||
</FormField>
|
||||
<FormField label={t('app.statusPages.timeout', 'Timeout')} htmlFor={`${fieldId}-comp-timeout`}>
|
||||
<Input id={`${fieldId}-comp-timeout`}
|
||||
type="number"
|
||||
min="1"
|
||||
value={compForm.check_timeout}
|
||||
onChange={(e) => setCompForm({ ...compForm, check_timeout: parseInt(e.target.value, 10) || 10 })}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
open={showCreateIncident}
|
||||
onClose={() => setShowCreateIncident(false)}
|
||||
onClose={closeIncident}
|
||||
onSubmit={handleCreateIncident}
|
||||
title={t('app.statusPages.createIncident', 'Create incident')}
|
||||
size="lg"
|
||||
className="status-modal"
|
||||
footer={(
|
||||
<>
|
||||
<Button variant="outline" onClick={() => setShowCreateIncident(false)}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button onClick={handleCreateIncident} disabled={!incidentForm.title.trim()}>
|
||||
<Button type="button" variant="outline" onClick={closeIncident}>{t('common.actions.cancel', 'Cancel')}</Button>
|
||||
<Button type="submit">
|
||||
{t('app.statusPages.createIncident', 'Create incident')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-incident-title`}>{t('common.labels.title', 'Title')}</label>
|
||||
<Input id={`${fieldId}-incident-title`} value={incidentForm.title} onChange={(e) => setIncidentForm({ ...incidentForm, title: e.target.value })} autoFocus />
|
||||
</div>
|
||||
<FormField label={t('common.labels.title', 'Title')} htmlFor={`${fieldId}-incident-title`} required error={incidentErrors.error('title')}>
|
||||
<Input id={`${fieldId}-incident-title`} value={incidentForm.title} onChange={(e) => { incidentErrors.clear('title'); setIncidentForm({ ...incidentForm, title: e.target.value }); }} onBlur={() => incidentErrors.touch('title')} autoFocus />
|
||||
</FormField>
|
||||
<div className="status-modal-grid">
|
||||
<div className="form-group">
|
||||
<label htmlFor="status-incident-status">{t('common.labels.status', 'Status')}</label>
|
||||
<FormField label={t('common.labels.status', 'Status')} htmlFor="status-incident-status">
|
||||
<Select
|
||||
value={incidentForm.status}
|
||||
onValueChange={(v) => setIncidentForm({ ...incidentForm, status: v })}
|
||||
@@ -793,9 +810,8 @@ const StatusPages = () => {
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor="status-incident-impact">{t('app.statusPages.impact', 'Impact')}</label>
|
||||
</FormField>
|
||||
<FormField label={t('app.statusPages.impact', 'Impact')} htmlFor="status-incident-impact">
|
||||
<Select
|
||||
value={incidentForm.impact}
|
||||
onValueChange={(v) => setIncidentForm({ ...incidentForm, impact: v })}
|
||||
@@ -807,16 +823,15 @@ const StatusPages = () => {
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</FormField>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label htmlFor={`${fieldId}-incident-body`}>{t('common.labels.description', 'Description')}</label>
|
||||
<FormField label={t('common.labels.description', 'Description')} htmlFor={`${fieldId}-incident-body`}>
|
||||
<Textarea id={`${fieldId}-incident-body`}
|
||||
value={incidentForm.body}
|
||||
onChange={(e) => setIncidentForm({ ...incidentForm, body: e.target.value })}
|
||||
rows={4}
|
||||
/>
|
||||
</div>
|
||||
</FormField>
|
||||
</Modal>
|
||||
|
||||
<ConfirmDialog
|
||||
|
||||
Reference in new issue
Block a user