import { useContext, useState } from "react"; import appContext from "../stores/appContext"; import { showDialog } from "./Dialog"; import MyAccountSection from "./Settings/MyAccountSection"; import PreferencesSection from "./Settings/PreferencesSection"; import MemberSection from "./Settings/MemberSection"; import "../less/setting-dialog.less"; interface Props extends DialogProps {} type SettingSection = "my-account" | "preferences" | "member"; interface State { selectedSection: SettingSection; } const SettingDialog: React.FC = (props: Props) => { const { userState: { user }, } = useContext(appContext); const { destroy } = props; const [state, setState] = useState({ selectedSection: "my-account", }); const handleSectionSelectorItemClick = (settingSection: SettingSection) => { setState({ selectedSection: settingSection, }); }; return (
Basic handleSectionSelectorItemClick("my-account")} className={`section-item ${state.selectedSection === "my-account" ? "selected" : ""}`} > My account handleSectionSelectorItemClick("preferences")} className={`section-item ${state.selectedSection === "preferences" ? "selected" : ""}`} > Preferences {user?.role === "OWNER" ? ( <> Admin handleSectionSelectorItemClick("member")} className={`section-item ${state.selectedSection === "member" ? "selected" : ""}`} > Member ) : null}
{state.selectedSection === "my-account" ? ( ) : state.selectedSection === "preferences" ? ( ) : state.selectedSection === "member" ? ( ) : null}
); }; export default function showSettingDialog(): void { showDialog( { className: "setting-dialog", useAppContext: true, }, SettingDialog, {} ); }