Skip to content

Commit

Permalink
Fix bug in ServerDialog.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
gnmyt committed Sep 3, 2024
1 parent 2121cbc commit 52ca270
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client/src/pages/Servers/components/ServerDialog/ServerDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -38,6 +40,8 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =

if (result.id) setIdentityUpdates({});

refreshIdentities();

return result;
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -75,16 +79,18 @@ export const ServerDialog = ({ open, onClose, currentFolderId, editServerId }) =

const createServer = async () => {
try {
let id = null;
let identity = null;
if (Object.keys(identityUpdates).length > 0) {
id = await updateIdentities();
identity = await updateIdentities();

if (!identity) return;

if (!id) 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();
Expand Down

0 comments on commit 52ca270

Please sign in to comment.