mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-07-29 18:23:25 +08:00
chore: clear create connection modal state
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import { cloneDeep, head } from "lodash-es";
|
import { cloneDeep, head } from "lodash-es";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
import { testConnection, useConnectionStore } from "@/store";
|
import { testConnection, useConnectionStore } from "@/store";
|
||||||
import { Connection, Engine } from "@/types";
|
import { Connection, Engine } from "@/types";
|
||||||
@ -10,21 +10,29 @@ interface Props {
|
|||||||
close: () => void;
|
close: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultConnection: Connection = {
|
||||||
|
id: "",
|
||||||
|
title: "",
|
||||||
|
engineType: Engine.MySQL,
|
||||||
|
host: "",
|
||||||
|
port: "",
|
||||||
|
username: "",
|
||||||
|
password: "",
|
||||||
|
};
|
||||||
|
|
||||||
const CreateConnectionModal = (props: Props) => {
|
const CreateConnectionModal = (props: Props) => {
|
||||||
const { show, close } = props;
|
const { show, close } = props;
|
||||||
const connectionStore = useConnectionStore();
|
const connectionStore = useConnectionStore();
|
||||||
const [connection, setConnection] = useState<Connection>({
|
const [connection, setConnection] = useState<Connection>(defaultConnection);
|
||||||
id: "",
|
|
||||||
title: "",
|
|
||||||
engineType: Engine.MySQL,
|
|
||||||
host: "",
|
|
||||||
port: "",
|
|
||||||
username: "",
|
|
||||||
password: "",
|
|
||||||
});
|
|
||||||
const [isRequesting, setIsRequesting] = useState(false);
|
const [isRequesting, setIsRequesting] = useState(false);
|
||||||
const showDatabaseField = connection.engineType === Engine.PostgreSQL;
|
const showDatabaseField = connection.engineType === Engine.PostgreSQL;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (show) {
|
||||||
|
setConnection(defaultConnection);
|
||||||
|
}
|
||||||
|
}, [show]);
|
||||||
|
|
||||||
const setPartialConnection = (state: Partial<Connection>) => {
|
const setPartialConnection = (state: Partial<Connection>) => {
|
||||||
setConnection({
|
setConnection({
|
||||||
...connection,
|
...connection,
|
||||||
@ -83,6 +91,7 @@ const CreateConnectionModal = (props: Props) => {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Connect host"
|
placeholder="Connect host"
|
||||||
className="input input-bordered w-full"
|
className="input input-bordered w-full"
|
||||||
|
value={connection.host}
|
||||||
onChange={(e) => setPartialConnection({ host: e.target.value })}
|
onChange={(e) => setPartialConnection({ host: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -92,6 +101,7 @@ const CreateConnectionModal = (props: Props) => {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Connect port"
|
placeholder="Connect port"
|
||||||
className="input input-bordered w-full"
|
className="input input-bordered w-full"
|
||||||
|
value={connection.port}
|
||||||
onChange={(e) => setPartialConnection({ port: e.target.value })}
|
onChange={(e) => setPartialConnection({ port: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -101,6 +111,7 @@ const CreateConnectionModal = (props: Props) => {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Connect username"
|
placeholder="Connect username"
|
||||||
className="input input-bordered w-full"
|
className="input input-bordered w-full"
|
||||||
|
value={connection.username}
|
||||||
onChange={(e) => setPartialConnection({ username: e.target.value })}
|
onChange={(e) => setPartialConnection({ username: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -110,6 +121,7 @@ const CreateConnectionModal = (props: Props) => {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Connect password"
|
placeholder="Connect password"
|
||||||
className="input input-bordered w-full"
|
className="input input-bordered w-full"
|
||||||
|
value={connection.password}
|
||||||
onChange={(e) => setPartialConnection({ password: e.target.value })}
|
onChange={(e) => setPartialConnection({ password: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -118,8 +130,9 @@ const CreateConnectionModal = (props: Props) => {
|
|||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Database Name</label>
|
<label className="block text-sm font-medium text-gray-700 mb-1">Database Name</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Type here"
|
placeholder="Connect database"
|
||||||
className="input input-bordered w-full"
|
className="input input-bordered w-full"
|
||||||
|
value={connection.database}
|
||||||
onChange={(e) => setPartialConnection({ database: e.target.value })}
|
onChange={(e) => setPartialConnection({ database: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user