mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-07-29 02:04:48 +08:00
chore: add request flag to create connection modal
This commit is contained in:
@ -22,6 +22,7 @@ const CreateConnectionModal = (props: Props) => {
|
|||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
});
|
});
|
||||||
|
const [isRequesting, setIsRequesting] = useState(false);
|
||||||
const showDatabaseField = connection.engineType === Engine.PostgreSQL;
|
const showDatabaseField = connection.engineType === Engine.PostgreSQL;
|
||||||
|
|
||||||
const setPartialConnection = (state: Partial<Connection>) => {
|
const setPartialConnection = (state: Partial<Connection>) => {
|
||||||
@ -32,11 +33,17 @@ const CreateConnectionModal = (props: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleCreateConnection = async () => {
|
const handleCreateConnection = async () => {
|
||||||
|
if (isRequesting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsRequesting(true);
|
||||||
const connectionCreate = cloneDeep(connection);
|
const connectionCreate = cloneDeep(connection);
|
||||||
if (!showDatabaseField) {
|
if (!showDatabaseField) {
|
||||||
connectionCreate.database = undefined;
|
connectionCreate.database = undefined;
|
||||||
}
|
}
|
||||||
const result = await testConnection(connectionCreate);
|
const result = await testConnection(connectionCreate);
|
||||||
|
setIsRequesting(false);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
toast.error("Failed to connect");
|
toast.error("Failed to connect");
|
||||||
return;
|
return;
|
||||||
@ -122,7 +129,7 @@ const CreateConnectionModal = (props: Props) => {
|
|||||||
<button className="btn btn-outline" onClick={close}>
|
<button className="btn btn-outline" onClick={close}>
|
||||||
Close
|
Close
|
||||||
</button>
|
</button>
|
||||||
<button className="btn" onClick={handleCreateConnection}>
|
<button className="btn" disabled={isRequesting} onClick={handleCreateConnection}>
|
||||||
Save
|
Save
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user