import React, { useState } from 'react' import { useAccess } from './useAccess.hook' import classes from './Access.module.css' import { Select, Space, Title, Image, Button, Modal, PasswordInput, TextInput, PinInput } from '@mantine/core' import { useDisclosure } from '@mantine/hooks' import left from '../images/login.png' import { IconLock, IconUser, IconUsers, IconSettings, IconServer, IconKey } from '@tabler/icons-react' import { modals } from '@mantine/modals' export function Access() { const { state, actions } = useAccess() const [urlOpened, { open: urlOpen, close: urlClose }] = useDisclosure(false) const [otpOpened, { open: otpOpen, close: otpClose }] = useDisclosure(false) const [disabled, setDisabled] = useState(false) const login = async () => { if (!state.loading) { actions.setLoading(true) try { if (state.mode === 'account') { await actions.accountLogin() } else if (state.mode === 'create') { await actions.accountCreate() } else if (state.mode === 'reset') { await actions.accountAccess() } else if (state.mode === 'admin') { await actions.adminLogin() } otpClose() } catch (err) { const { message } = err as { message: string } console.log(message) if (message === '405' || message === '403' || message === '429') { if (message === '429') { setDisabled(true) } else { setDisabled(false) } otpOpen() } else { modals.openConfirmModal({ title: state.strings.operationFailed, withCloseButton: true, overlayProps: { backgroundOpacity: 0.55, blur: 3, }, children: