mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-07-31 03:01:42 +08:00
chore: update clear data modal in setting
This commit is contained in:
20
components/ClearDataButton.tsx
Normal file
20
components/ClearDataButton.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
import ClearDataConfirmModal from "./ClearDataConfirmModal";
|
||||||
|
|
||||||
|
const ClearDataButton = () => {
|
||||||
|
const [showClearDataConfirmModal, setShowClearDataConfirmModal] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button className="btn btn-sm btn-error" onClick={() => setShowClearDataConfirmModal(true)}>
|
||||||
|
Clear
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{showClearDataConfirmModal &&
|
||||||
|
createPortal(<ClearDataConfirmModal close={() => setShowClearDataConfirmModal(false)} />, document.body)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ClearDataButton;
|
@ -1,33 +1,16 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { createPortal } from "react-dom";
|
|
||||||
import Icon from "./Icon";
|
import Icon from "./Icon";
|
||||||
import WeChatQRCodeView from "./WeChatQRCodeView";
|
import WeChatQRCodeView from "./WeChatQRCodeView";
|
||||||
import ClearDataConfirmModal from "./ClearDataConfirmModal";
|
import ClearDataButton from "./ClearDataButton";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
close: () => void;
|
close: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
|
||||||
showClearDataConfirmModal: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SettingModal = (props: Props) => {
|
const SettingModal = (props: Props) => {
|
||||||
const { show, close } = props;
|
const { show, close } = props;
|
||||||
const [state, setState] = useState<State>({
|
|
||||||
showClearDataConfirmModal: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const toggleClearDataConfirmModal = (show = true) => {
|
|
||||||
setState({
|
|
||||||
...state,
|
|
||||||
showClearDataConfirmModal: show,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<div className={`modal modal-middle ${show && "modal-open"}`}>
|
<div className={`modal modal-middle ${show && "modal-open"}`}>
|
||||||
<div className="modal-box relative">
|
<div className="modal-box relative">
|
||||||
<h3 className="font-bold text-lg">Setting</h3>
|
<h3 className="font-bold text-lg">Setting</h3>
|
||||||
@ -51,18 +34,12 @@ const SettingModal = (props: Props) => {
|
|||||||
<div className="w-full border border-red-200 p-4 rounded-lg">
|
<div className="w-full border border-red-200 p-4 rounded-lg">
|
||||||
<div className="w-full flex flex-row justify-between items-center gap-2">
|
<div className="w-full flex flex-row justify-between items-center gap-2">
|
||||||
<span>Clear all data</span>
|
<span>Clear all data</span>
|
||||||
<button className="btn btn-sm btn-error" onClick={() => toggleClearDataConfirmModal(true)}>
|
<ClearDataButton />
|
||||||
Clear
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{state.showClearDataConfirmModal &&
|
|
||||||
createPortal(<ClearDataConfirmModal close={() => toggleClearDataConfirmModal(false)} />, document.body)}
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user