feat: Safeguard gateway addition in EditServerModal by implementing error handling during state updates, ensuring robust server configuration management.
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m8s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m8s
This commit is contained in:
@@ -630,6 +630,8 @@ function ServerManager() {
|
||||
setTimeout(() => setSuccess(''), 3000);
|
||||
};
|
||||
|
||||
const gateways = Array.isArray(localServer.gateways) ? localServer.gateways : [];
|
||||
|
||||
return (
|
||||
<>
|
||||
{error && (
|
||||
@@ -1538,11 +1540,11 @@ function EditServerModal({ show, server, onChange, onSave, onClose }) {
|
||||
<label className="form-label">Тип туннеля</label>
|
||||
<input type="text" className="form-control" value={localServer.tunnel || ''} onChange={e => handleChange('tunnel', e.target.value)} />
|
||||
</div>
|
||||
{NEEDS_GATEWAYS(localServer.type) && (
|
||||
{NEEDS_GATEWAYS(localServer.type) && (
|
||||
<>
|
||||
<div className="form-label">Шлюзы</div>
|
||||
<div className="list-group list-group-flush border rounded mb-2">
|
||||
{(localServer.gateways || []).map((gw, idx) => (
|
||||
{gateways.map((gw, idx) => (
|
||||
<div key={gw.id || idx} className="list-group-item">
|
||||
<div className="row g-2 align-items-end">
|
||||
<div className="col-12 col-md-4">
|
||||
@@ -1634,14 +1636,18 @@ function EditServerModal({ show, server, onChange, onSave, onClose }) {
|
||||
type="button"
|
||||
className="btn btn-outline-primary btn-sm"
|
||||
onClick={() => {
|
||||
setLocalServer((prev) => {
|
||||
const list = Array.isArray(prev?.gateways) ? prev.gateways : [];
|
||||
const nextList = [...list, makeGateway({ primary: list.length === 0 })];
|
||||
const next = { ...(prev || {}), gateways: nextList };
|
||||
onChange && onChange(next);
|
||||
return next;
|
||||
});
|
||||
}}
|
||||
try {
|
||||
setLocalServer((prev) => {
|
||||
const list = Array.isArray(prev?.gateways) ? prev.gateways : [];
|
||||
const nextList = [...list, makeGateway({ primary: list.length === 0 })];
|
||||
const next = { ...(prev || {}), gateways: nextList };
|
||||
onChange && onChange(next);
|
||||
return next;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Ошибка при добавлении шлюза в модалке редактирования', e);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<IconPlus className="icon" />
|
||||
Добавить шлюз
|
||||
|
||||
Reference in New Issue
Block a user