import PropTypes from 'prop-types'; import { CssVarsProvider } from '@mui/joy/styles'; import { Modal, Button, FormControl, FormLabel, Input, Stack, DialogTitle, DialogContent, ModalDialog, IconButton } from '@mui/joy'; import theme from '/src/theme'; import { useEffect, useState } from 'react'; import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; const CreateUserModal = ({ isHidden, form, setForm, handleCreateUser, setIsCreateUserHidden, setIsLoginUserHidden }) => { const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [isLoading, setIsLoading] = useState(false); const isFormValid = () => { if (!form.username || !form.password || form.password !== confirmPassword) return false; return true; }; const handleCreate = async () => { setIsLoading(true); try { await handleCreateUser({ ...form, onSuccess: () => setIsLoading(false), onFailure: () => setIsLoading(false) }); } catch (error) { setIsLoading(false); } }; useEffect(() => { if (isHidden) { setForm({ username: '', password: '' }); setConfirmPassword(''); setIsLoading(false); } }, [isHidden]); return ( {}}> Create
{ event.preventDefault(); if (isFormValid() && !isLoading) handleCreate(); }} > Username setForm({ ...form, username: event.target.value })} sx={{ backgroundColor: theme.palette.general.primary, color: theme.palette.text.primary, '&:disabled': { opacity: 0.5, backgroundColor: theme.palette.general.primary, }, }} /> Password
setForm({ ...form, password: event.target.value })} sx={{ backgroundColor: theme.palette.general.primary, color: theme.palette.text.primary, flex: 1, '&:disabled': { opacity: 0.5, backgroundColor: theme.palette.general.primary, }, }} /> setShowPassword(!showPassword)} sx={{ color: theme.palette.text.primary, marginLeft: 1, '&:disabled': { opacity: 0.5, }, }} > {showPassword ? : }
Confirm Password
setConfirmPassword(event.target.value)} sx={{ backgroundColor: theme.palette.general.primary, color: theme.palette.text.primary, flex: 1, '&:disabled': { opacity: 0.5, backgroundColor: theme.palette.general.primary, }, }} /> setShowConfirmPassword(!showConfirmPassword)} sx={{ color: theme.palette.text.primary, marginLeft: 1, '&:disabled': { opacity: 0.5, }, }} > {showConfirmPassword ? : }
); }; CreateUserModal.propTypes = { isHidden: PropTypes.bool.isRequired, form: PropTypes.object.isRequired, setForm: PropTypes.func.isRequired, handleCreateUser: PropTypes.func.isRequired, setIsCreateUserHidden: PropTypes.func.isRequired, setIsLoginUserHidden: PropTypes.func.isRequired, }; export default CreateUserModal;