import PropTypes from 'prop-types'; import { CssVarsProvider } from '@mui/joy/styles'; import { Modal, Button, FormControl, FormLabel, Input, Stack, DialogTitle, DialogContent, ModalDialog, IconButton, Select, Option, } from '@mui/joy'; import theme from '/src/theme'; import { useState } from 'react'; import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; const NoAuthenticationModal = ({ isHidden, form, setForm, setIsNoAuthHidden, handleAuthSubmit }) => { const [showPassword, setShowPassword] = useState(false); const isFormValid = () => { if (form.authMethod === 'Select Auth') return false; if (form.authMethod === 'rsaKey' && !form.rsaKey) return false; if (form.authMethod === 'password' && !form.password) return false; return true; }; const handleSubmit = (event) => { event.preventDefault(); if (isFormValid()) { handleAuthSubmit(form); setForm({ authMethod: 'Select Auth', password: '', rsaKey: '' }); } }; return ( { if (reason !== 'backdropClick') { setIsNoAuthHidden(true); } }} disableBackdropClic > Authentication Required
Authentication Method {form.authMethod === 'password' && ( Password
setForm({ ...form, password: e.target.value })} required sx={{ backgroundColor: theme.palette.general.primary, color: theme.palette.text.primary, flex: 1, }} /> setShowPassword(!showPassword)} sx={{ color: theme.palette.text.primary, marginLeft: 1, }} > {showPassword ? : }
)} {form.authMethod === 'rsaKey' && ( RSA Key { const file = e.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = (event) => { setForm({ ...form, rsaKey: event.target.result }); }; reader.readAsText(file); } }} required sx={{ backgroundColor: theme.palette.general.primary, color: theme.palette.text.primary, padding: 1, textAlign: 'center', width: '100%', minWidth: 'auto', minHeight: 'auto', }} /> )}
); }; NoAuthenticationModal.propTypes = { isHidden: PropTypes.bool.isRequired, form: PropTypes.object.isRequired, setForm: PropTypes.func.isRequired, setIsNoAuthHidden: PropTypes.func.isRequired, handleAuthSubmit: PropTypes.func.isRequired, }; export default NoAuthenticationModal;