import React, { FC, memo, useCallback } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import { ApiSession } from '../../../api/types'; import { formatDateTimeToString } from '../../../util/dateFormat'; import useLang from '../../../hooks/useLang'; import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev'; import getSessionIcon from './helpers/getSessionIcon'; import buildClassName from '../../../util/buildClassName'; import ListItem from '../../ui/ListItem'; import Modal from '../../ui/Modal'; import Switcher from '../../ui/Switcher'; import Button from '../../ui/Button'; import styles from './SettingsActiveSession.module.scss'; type OwnProps = { isOpen: boolean; hash?: string; onClose: () => void; }; type StateProps = { session?: ApiSession; }; const SettingsActiveSession: FC = ({ isOpen, session, onClose, }) => { const { changeSessionSettings, terminateAuthorization } = getActions(); const lang = useLang(); const renderingSession = useCurrentOrPrev(session, true); const handleCallsStateChange = useCallback(() => { changeSessionSettings({ hash: session!.hash, areCallsEnabled: !session?.areCallsEnabled, }); }, [changeSessionSettings, session]); const handleTerminateSessionClick = useCallback(() => { terminateAuthorization({ hash: session!.hash }); onClose(); }, [onClose, session, terminateAuthorization]); if (!renderingSession) { return undefined; } return (

{renderingSession?.deviceModel}

{formatDateTimeToString(renderingSession.dateActive * 1000, lang.code)}
{lang('SessionPreview.App')}
{renderingSession?.appName} {renderingSession?.appVersion}, {renderingSession?.platform} {renderingSession?.systemVersion}
{lang('SessionPreview.Ip')}
{renderingSession?.ip}
{lang('SessionPreview.Location')}
{renderingSession && getLocation(renderingSession)}

{lang('SessionPreview.IpDesc')}

{lang('SessionPreview.AcceptHeader')}

{lang('SessionPreview.Accept.Calls')} ); }; function getLocation(session: ApiSession) { return [session.region, session.country].filter(Boolean).join(', '); } export default memo(withGlobal((global, { hash }) => { return { session: hash ? global.activeSessions.byHash[hash] : undefined, }; })(SettingsActiveSession));