import Button from "@components/button" import Input from "@components/input" import Note from "@components/note" import * as Dialog from "@radix-ui/react-dialog" import { useState } from "react" import styles from "./modal.module.css" type Props = { creating: boolean isOpen: boolean onClose: () => void onSubmit: (password: string) => void } const PasswordModal = ({ isOpen, onClose, onSubmit: onSubmitAfterVerify, creating }: Props) => { const [password, setPassword] = useState() const [confirmPassword, setConfirmPassword] = useState() const [error, setError] = useState() const onSubmit = () => { if (!password || (creating && !confirmPassword)) { setError("Please enter a password") return } if (password !== confirmPassword && creating) { setError("Passwords do not match") return } onSubmitAfterVerify(password) } return ( <> { { if (!open) onClose() }} > {/* Enter a password */} {creating ? "Add a password" : "Enter password"} {creating ? "Enter a password to protect your post" : "Enter the password to access the post"}
{error && {error}} setPassword(e.currentTarget.value)} /> {creating && ( setConfirmPassword(e.currentTarget.value)} /> )} {!error && creating && ( This doesn't protect your post from the server administrator. )}
} ) } export default PasswordModal