chore: update create connection handler

This commit is contained in:
steven
2023-03-28 14:05:56 +08:00
parent 82ecdf750b
commit 2fb70e11ff

View File

@ -50,19 +50,28 @@ const CreateConnectionModal = (props: Props) => {
if (!showDatabaseField) { if (!showDatabaseField) {
connectionCreate.database = undefined; connectionCreate.database = undefined;
} }
const result = await testConnection(connectionCreate); try {
setIsRequesting(false); const result = await testConnection(connectionCreate);
if (!result) { if (!result) {
toast.error("Failed to connect"); setIsRequesting(false);
toast.error("Failed to test connection");
return;
}
const createdConnection = connectionStore.createConnection(connectionCreate);
// Set the created connection as the current connection.
const databaseList = await connectionStore.getOrFetchDatabaseList(createdConnection);
connectionStore.setCurrentConnectionCtx({
connection: createdConnection,
database: head(databaseList),
});
} catch (error) {
console.error(error);
setIsRequesting(false);
toast.error("Failed to create connection");
return; return;
} }
const createdConnection = connectionStore.createConnection(connectionCreate);
// Set the created connection as the current connection. setIsRequesting(false);
const databaseList = await connectionStore.getOrFetchDatabaseList(createdConnection);
connectionStore.setCurrentConnectionCtx({
connection: createdConnection,
database: head(databaseList),
});
close(); close();
}; };