import { useForm } from '@inertiajs/react'; import classNames from 'classnames'; import React, { useRef, useState } from 'react'; import useRoute from '@/Hooks/useRoute'; import ActionMessage from '@/Components/ActionMessage'; import ActionSection from '@/Components/ActionSection'; import DialogModal from '@/Components/DialogModal'; import InputError from '@/Components/InputError'; import PrimaryButton from '@/Components/PrimaryButton'; import TextInput from '@/Components/TextInput'; import SecondaryButton from '@/Components/SecondaryButton'; import { Session } from '@/types'; interface Props { sessions: Session[]; } export default function LogoutOtherBrowserSessions({ sessions }: Props) { const [confirmingLogout, setConfirmingLogout] = useState(false); const route = useRoute(); const passwordRef = useRef(null); const form = useForm({ password: '', }); function confirmLogout() { setConfirmingLogout(true); setTimeout(() => passwordRef.current?.focus(), 250); } function logoutOtherBrowserSessions() { form.delete(route('other-browser-sessions.destroy'), { preserveScroll: true, onSuccess: () => closeModal(), onError: () => passwordRef.current?.focus(), onFinish: () => form.reset(), }); } function closeModal() { setConfirmingLogout(false); form.reset(); } return (
If necessary, you may log out of all of your other browser sessions across all of your devices. Some of your recent sessions are listed below; however, this list may not be exhaustive. If you feel your account has been compromised, you should also update your password.
{/* */} {sessions.length > 0 ? (
{sessions.map((session, i) => (
{session.agent.is_desktop ? ( ) : ( )}
{session.agent.platform} - {session.agent.browser}
{session.ip_address}, {session.is_current_device ? ( This device ) : ( Last active {session.last_active} )}
))}
) : null}
Log Out Other Browser Sessions Done.
{/* */} Please enter your password to confirm you would like to log out of your other browser sessions across all of your devices.
form.setData('password', e.currentTarget.value)} />
Cancel Log Out Other Browser Sessions
); }