import { useRef, useState } from 'react' import { useLocation } from 'react-router-dom' import { Card, Flex, Modal, Space } from 'antd' import { LoadingOutlined } from '@ant-design/icons' import useCollapseState from '../../hooks/useCollapseState' import NotesPanel from '../../common/NotesPanel' import InfoCollapse from '../../common/InfoCollapse' import ObjectInfo from '../../common/ObjectInfo' import ViewButton from '../../common/ViewButton' import InfoCircleIcon from '../../../Icons/InfoCircleIcon.jsx' import NoteIcon from '../../../Icons/NoteIcon.jsx' import AuditLogIcon from '../../../Icons/AuditLogIcon.jsx' import AppPasswordIcon from '../../../Icons/AppPasswordIcon.jsx' import ObjectForm from '../../common/ObjectForm' import EditButtons from '../../common/EditButtons' import ActivityIndicator from '../../common/ActivityIndicator.jsx' import ActionHandler from '../../common/ActionHandler' import ObjectActions from '../../common/ObjectActions.jsx' import ObjectTable from '../../common/ObjectTable.jsx' import InfoCollapsePlaceholder from '../../common/InfoCollapsePlaceholder.jsx' import DocumentPrintButton from '../../common/DocumentPrintButton.jsx' import UserNotifierToggle from '../../common/UserNotifierToggle.jsx' import ScrollBox from '../../common/ScrollBox.jsx' import NewAppPassword from '../AppPasswords/NewAppPassword.jsx' import ObjectProperty from '../../common/ObjectProperty.jsx' import { getModelProperty } from '../../../../database/ObjectModels.js' import { useMediaQuery } from 'react-responsive' const UserInfo = () => { const location = useLocation() const objectFormRef = useRef(null) const appPasswordsTableRef = useRef(null) const actionHandlerRef = useRef(null) const userId = new URLSearchParams(location.search).get('userId') const [newAppPasswordOpen, setNewAppPasswordOpen] = useState(false) const [collapseState, updateCollapseState] = useCollapseState('UserInfo', { info: true, appPasswords: true, notes: true, auditLogs: false }) const [objectFormState, setEditFormState] = useState({ isEditing: false, editLoading: false, formValid: false, lock: null, loading: false, objectData: {} }) const isMobile = useMediaQuery({ maxWidth: 768 }) const actions = { newAppPassword: () => { setNewAppPasswordOpen(true) return false }, edit: () => { objectFormRef?.current?.startEditing?.() return false }, cancelEdit: () => { objectFormRef?.current?.cancelEditing?.() return true }, finishEdit: () => { objectFormRef?.current?.handleUpdate?.() return true } } return ( <> { actionHandlerRef.current.callAction('finishEdit') }} cancelEditing={() => { actionHandlerRef.current.callAction('cancelEdit') }} startEditing={() => { actionHandlerRef.current.callAction('edit') }} editLoading={objectFormState.editLoading} formValid={objectFormState.formValid} disabled={objectFormState.beingEditedByOther || objectFormState.loading} loading={objectFormState.editLoading} /> } active={collapseState.info} onToggle={(expanded) => updateCollapseState('info', expanded)} collapseKey='info' > { setEditFormState((prev) => ({ ...prev, ...state })) }} > {({ loading, isEditing, objectData }) => (
} isEditing={isEditing} type='user' objectData={objectData} visibleProperties={{ profileImage: false }} />
)}
} active={collapseState.appPasswords} onToggle={(expanded) => updateCollapseState('appPasswords', expanded) } collapseKey='appPasswords' > {!userId ? ( ) : ( )} } active={collapseState.notes} onToggle={(expanded) => updateCollapseState('notes', expanded)} collapseKey='notes' > } active={collapseState.auditLogs} onToggle={(expanded) => updateCollapseState('auditLogs', expanded) } collapseKey='auditLogs' > {objectFormState.loading ? ( ) : ( )}
{ actionHandlerRef.current?.clearAction?.() setNewAppPasswordOpen(false) }} footer={null} > { setNewAppPasswordOpen(false) appPasswordsTableRef.current?.reload?.() }} reset={newAppPasswordOpen} defaultValues={{ user: { ...objectFormState.objectData } }} /> ) } export default UserInfo