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);
|
setTimeout(() => setSuccess(''), 3000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const gateways = Array.isArray(localServer.gateways) ? localServer.gateways : [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{error && (
|
{error && (
|
||||||
@@ -1538,11 +1540,11 @@ function EditServerModal({ show, server, onChange, onSave, onClose }) {
|
|||||||
<label className="form-label">Тип туннеля</label>
|
<label className="form-label">Тип туннеля</label>
|
||||||
<input type="text" className="form-control" value={localServer.tunnel || ''} onChange={e => handleChange('tunnel', e.target.value)} />
|
<input type="text" className="form-control" value={localServer.tunnel || ''} onChange={e => handleChange('tunnel', e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
{NEEDS_GATEWAYS(localServer.type) && (
|
{NEEDS_GATEWAYS(localServer.type) && (
|
||||||
<>
|
<>
|
||||||
<div className="form-label">Шлюзы</div>
|
<div className="form-label">Шлюзы</div>
|
||||||
<div className="list-group list-group-flush border rounded mb-2">
|
<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 key={gw.id || idx} className="list-group-item">
|
||||||
<div className="row g-2 align-items-end">
|
<div className="row g-2 align-items-end">
|
||||||
<div className="col-12 col-md-4">
|
<div className="col-12 col-md-4">
|
||||||
@@ -1634,14 +1636,18 @@ function EditServerModal({ show, server, onChange, onSave, onClose }) {
|
|||||||
type="button"
|
type="button"
|
||||||
className="btn btn-outline-primary btn-sm"
|
className="btn btn-outline-primary btn-sm"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLocalServer((prev) => {
|
try {
|
||||||
const list = Array.isArray(prev?.gateways) ? prev.gateways : [];
|
setLocalServer((prev) => {
|
||||||
const nextList = [...list, makeGateway({ primary: list.length === 0 })];
|
const list = Array.isArray(prev?.gateways) ? prev.gateways : [];
|
||||||
const next = { ...(prev || {}), gateways: nextList };
|
const nextList = [...list, makeGateway({ primary: list.length === 0 })];
|
||||||
onChange && onChange(next);
|
const next = { ...(prev || {}), gateways: nextList };
|
||||||
return next;
|
onChange && onChange(next);
|
||||||
});
|
return next;
|
||||||
}}
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Ошибка при добавлении шлюза в модалке редактирования', e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<IconPlus className="icon" />
|
<IconPlus className="icon" />
|
||||||
Добавить шлюз
|
Добавить шлюз
|
||||||
|
|||||||
Reference in New Issue
Block a user