diff --git a/frontend/src/AutoUrlManager.jsx b/frontend/src/AutoUrlManager.jsx index 993041a..4ceb5db 100644 --- a/frontend/src/AutoUrlManager.jsx +++ b/frontend/src/AutoUrlManager.jsx @@ -6,7 +6,10 @@ import { IconDownload, IconAlertCircle, IconCheck, - IconLoader + IconLoader, + IconUpload, + IconDeviceFloppy, + IconInfoCircle } from '@tabler/icons-react'; function AutoUrlManager() { @@ -16,6 +19,7 @@ function AutoUrlManager() { const [processing, setProcessing] = useState(false); const [message, setMessage] = useState(''); const [messageType, setMessageType] = useState(''); + const [touched, setTouched] = useState({}); useEffect(() => { fetchUrls(); @@ -47,17 +51,40 @@ function AutoUrlManager() { const newUrls = [...urls]; newUrls[index][field] = value; setUrls(newUrls); + setTouched(prev => ({ ...prev, [index]: true })); }; + const isValidHttpUrl = (value) => { + try { + const u = new URL(value); + return u.protocol === 'http:' || u.protocol === 'https:'; + } catch { + return false; + } + }; + + const isValidCommunity = (value) => { + return /^[0-9]+$/.test(String(value).trim()); + }; + + const getRowValidity = (row) => ({ + url: row.url ? isValidHttpUrl(row.url) : false, + community: row.community ? isValidCommunity(row.community) : false + }); + + const hasAtLeastOneValidRow = urls.some(u => isValidHttpUrl(u.url) && isValidCommunity(u.community)); + const saveUrls = async () => { try { setSaving(true); setMessage(''); // Validate URLs - const validUrls = urls.filter(u => u.url.trim() && u.community.trim()); + const validUrls = urls + .filter(u => isValidHttpUrl(u.url) && isValidCommunity(u.community)) + .map(u => ({ url: u.url.trim(), community: String(u.community).trim() })); if (validUrls.length === 0) { - setMessage('Добавьте хотя бы один URL с community'); + setMessage('Добавьте хотя бы одну корректную запись (валидный URL и числовой community)'); setMessageType('error'); return; } @@ -95,7 +122,7 @@ function AutoUrlManager() { if (loading) { return (
| URL | Community | -Действия | +Действия |
|---|---|---|---|
|
- updateUrl(index, 'url', e.target.value)}
- disabled={saving || processing}
- />
+ {(() => {
+ const v = getRowValidity(url);
+ const invalid = touched[index] && !v.url;
+ return (
+ <>
+ updateUrl(index, 'url', e.target.value)}
+ disabled={saving || processing}
+ />
+ {invalid && (
+ Укажите корректный http/https URL
+ )}
+ >
+ );
+ })()}
|
- updateUrl(index, 'community', e.target.value)}
- disabled={saving || processing}
- />
+ {(() => {
+ const v = getRowValidity(url);
+ const invalid = touched[index] && !v.community;
+ return (
+ <>
+ updateUrl(index, 'community', e.target.value)}
+ disabled={saving || processing}
+ />
+ {invalid && (
+ Только цифры, например 555
+ )}
+ >
+ );
+ })()}
|
- + |