diff --git a/client/src/common/components/IconInput/IconInput.jsx b/client/src/common/components/IconInput/IconInput.jsx
index 0727ec4..62b6d36 100644
--- a/client/src/common/components/IconInput/IconInput.jsx
+++ b/client/src/common/components/IconInput/IconInput.jsx
@@ -8,7 +8,7 @@ export const IconInput = ({ type, id, name, required, icon, placeholder, customC
setValue(event.target.value)} />
+ onBlur={onBlur} value={value} onChange={(event) => setValue ? setValue(event.target.value) : null} />
);
};
diff --git a/client/src/pages/Servers/components/ProxmoxDialog/ProxmoxDialog.jsx b/client/src/pages/Servers/components/ProxmoxDialog/ProxmoxDialog.jsx
index 18deb54..a179694 100644
--- a/client/src/pages/Servers/components/ProxmoxDialog/ProxmoxDialog.jsx
+++ b/client/src/pages/Servers/components/ProxmoxDialog/ProxmoxDialog.jsx
@@ -37,7 +37,7 @@ export const ProxmoxDialog = ({ open, onClose, currentFolderId, editServerId })
}
useEffect(() => {
- if (editServerId) {
+ if (editServerId && open) {
getRequest(`pve-servers/${editServerId.split("-")[1]}`).then(server => {
setName(server.name);
setIp(server.ip);
diff --git a/client/src/pages/Servers/components/ServerDialog/ServerDialog.jsx b/client/src/pages/Servers/components/ServerDialog/ServerDialog.jsx
index 7702674..1b145bc 100644
--- a/client/src/pages/Servers/components/ServerDialog/ServerDialog.jsx
+++ b/client/src/pages/Servers/components/ServerDialog/ServerDialog.jsx
@@ -6,12 +6,14 @@ import Button from "@/common/components/Button";
import { getRequest, patchRequest, putRequest } from "@/common/utils/RequestUtil.js";
import { ServerContext } from "@/common/contexts/ServerContext.jsx";
import IdentityPage from "@/pages/Servers/components/ServerDialog/pages/IdentityPage.jsx";
+import { IdentityContext } from "@/common/contexts/IdentityContext.jsx";
const tabs = ["Details", "Identities", "Settings"];
export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) => {
const { loadServers } = useContext(ServerContext);
+ const { loadIdentities } = useContext(IdentityContext);
const [name, setName] = useState("");
const [icon, setIcon] = useState(null);
@@ -26,7 +28,11 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =
const postIdentity = async (identity) => {
try {
- console.log(identity);
+ if (identity.username === "") identity.username = undefined;
+ if (identity.passphrase === "") identity.passphrase = undefined;
+ if (identity.password === "") identity.password = undefined;
+ if (identity.sshKey === null) identity.sshKey = undefined;
+
const result = await putRequest("identities", {
name: identity.name, username: identity.username, type: identity.authType,
password: identity.password, sshKey: identity.sshKey, passphrase: identity.passphrase,
@@ -34,6 +40,8 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =
if (result.id) setIdentityUpdates({});
+ refreshIdentities();
+
return result;
} catch (error) {
console.error(error);
@@ -42,6 +50,11 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =
const patchIdentity = async (identity) => {
try {
+ if (identity.username === "") identity.username = undefined;
+ if (identity.passphrase === "") identity.passphrase = undefined;
+ if (identity.password === "") identity.password = undefined;
+ if (identity.sshKey === null) identity.sshKey = undefined;
+
await patchRequest("identities/" + identity.id, {
name: identity.name, username: identity.username, type: identity.authType,
password: identity.password, sshKey: identity.sshKey, passphrase: identity.passphrase,
@@ -66,11 +79,18 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =
const createServer = async () => {
try {
- const { id } = await updateIdentities();
+ let identity = null;
+ if (Object.keys(identityUpdates).length > 0) {
+ identity = await updateIdentities();
+
+ if (!identity) return;
+
+ loadIdentities();
+ }
const result = await putRequest("servers", {
name, icon: icon, ip, port, protocol: protocol,
- folderId: currentFolderId, identities: id ? [id] : [],
+ folderId: currentFolderId, identities: identity?.id ? [identity?.id] : [],
});
loadServers();
@@ -82,9 +102,10 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =
const patchServer = async () => {
try {
- await updateIdentities();
+ const identity = await updateIdentities();
- await patchRequest("servers/" + editServerId, { name, icon: icon, ip, port, protocol: protocol });
+ await patchRequest("servers/" + editServerId, { name, icon: icon, ip, port, protocol: protocol,
+ identities: identity?.id ? [identity?.id] : undefined });
loadServers();
onClose();
diff --git a/server/models/Identity.js b/server/models/Identity.js
index 901d5c9..c2766d4 100644
--- a/server/models/Identity.js
+++ b/server/models/Identity.js
@@ -12,7 +12,7 @@ module.exports = db.define("identities", {
},
username: {
type: Sequelize.STRING,
- allowNull: false,
+ allowNull: true,
},
type: {
type: Sequelize.STRING,
diff --git a/server/validations/identity.js b/server/validations/identity.js
index e234398..a89844f 100644
--- a/server/validations/identity.js
+++ b/server/validations/identity.js
@@ -1,7 +1,7 @@
const Joi = require("joi");
module.exports.createIdentityValidation = Joi.object({
name: Joi.string().min(3).max(255).required(),
- username: Joi.string().max(255).required(),
+ username: Joi.string().max(255).optional(),
type: Joi.string().valid("password", "ssh").required(),
password: Joi.string().optional(),
sshKey: Joi.string().optional(),