import React, { useState, useCallback, type JSX } from 'react'; import { useTranslation } from 'next-i18next'; import { Modal, ModalHeader, ModalBody, ModalFooter, Nav, NavLink, TabContent, TabPane, } from 'reactstrap'; import { toastSuccess, toastError } from '~/client/util/toastr'; import { useAssociateLdapAccount, useSWRxPersonalExternalAccounts } from '~/stores/personal-settings'; import { LdapAuthTest } from '../Admin/Security/LdapAuthTest'; type Props = { isOpen: boolean, onClose: () => void, } /** * AssociateModalSubstance - Presentation component (heavy logic, rendered only when isOpen) */ type AssociateModalSubstanceProps = { onClose: () => void; }; const AssociateModalSubstance = (props: AssociateModalSubstanceProps): JSX.Element => { const { onClose } = props; const { t } = useTranslation(); const { mutate: mutatePersonalExternalAccounts } = useSWRxPersonalExternalAccounts(); const { trigger: associateLdapAccount } = useAssociateLdapAccount(); const [activeTab, setActiveTab] = useState(1); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const closeModalHandler = useCallback(() => { onClose(); setUsername(''); setPassword(''); }, [onClose]); const clickAddLdapAccountHandler = useCallback(async() => { try { await associateLdapAccount({ username, password }); mutatePersonalExternalAccounts(); closeModalHandler(); toastSuccess(t('security_settings.updated_general_security_setting')); } catch (err) { toastError(err); } }, [associateLdapAccount, closeModalHandler, mutatePersonalExternalAccounts, password, t, username]); const setTabToLdap = useCallback(() => setActiveTab(1), []); const setTabToGithub = useCallback(() => setActiveTab(2), []); const setTabToGoogle = useCallback(() => setActiveTab(3), []); const handleUsernameChange = useCallback((username: string) => setUsername(username), []); const handlePasswordChange = useCallback((password: string) => setPassword(password), []); return ( <> { t('admin:user_management.create_external_account') } network_node LDAP github (TBD) GitHub google (TBD) Google OAuth TBD TBD TBD TBD add_circle {t('add')} > ); }; /** * AssociateModal - Container component (lightweight, always rendered) */ const AssociateModal = (props: Props): JSX.Element => { const { isOpen, onClose } = props; return ( {isOpen && } ); }; export default AssociateModal;