Files
5chan/src/components/CaptchaModal.jsx
T

100 lines
2.1 KiB
React
Raw Normal View History

2023-03-13 14:29:34 +01:00
import React from 'react';
import useBoardStore from '../useBoardStore';
2023-03-09 17:51:56 +01:00
import Modal from 'react-modal';
import styled from 'styled-components';
const StyledModal = styled(Modal)`
.modal-content {
2023-03-14 11:23:59 +01:00
width: 400px;
height: 300px;
2023-03-09 17:51:56 +01:00
display: flex;
align-self: center;
flex-direction: column;
align-items: center;
justify-content: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0, 0, 0, 0.75);
padding: 0;
z-index: 9999;
border: 1px solid #aaa;
}
button.x {
position: absolute;
top: 10px;
right: 10px;
}
img {
2023-03-14 11:23:59 +01:00
width: 300px;
2023-03-09 17:51:56 +01:00
height: 100px;
object-fit: contain;
}
.challenge {
font-size: 12pt;
2023-03-14 11:23:59 +01:00
margin-bottom: 40px;
2023-03-09 17:51:56 +01:00
font-weight: 700;
color: #fff;
}
input {
2023-03-12 22:07:15 +01:00
margin-top: 30px;
2023-03-14 11:23:59 +01:00
width: 300px;
2023-03-09 17:51:56 +01:00
padding: 2px;
border: 1px solid #ccc;
font-family: monospace;
border: 1px solid #777;
outline: none;
}
`;
const customOverlayStyles = {
overlay: {
backgroundColor: 'rgba(0,0,0,.4)'
}
};
2023-03-12 22:07:15 +01:00
const CaptchaModal = ({ isOpen, closeModal, captchaImage }) => {
2023-03-13 14:29:34 +01:00
const { captchaResponse, setCaptchaResponse } = useBoardStore(state => state);
2023-03-12 22:07:15 +01:00
2023-03-09 17:51:56 +01:00
const handleCloseModal = () => {
closeModal();
};
2023-03-12 22:07:15 +01:00
const handleChallengeResponse = (event) => {
setCaptchaResponse(event.target.value);
};
2023-03-09 17:51:56 +01:00
return (
<StyledModal
isOpen={isOpen}
onRequestClose={closeModal}
shouldCloseOnOverlayClick={false}
contentLabel="Captcha Modal"
style={customOverlayStyles}
>
<div className="modal-content">
<button className='x' onClick={handleCloseModal}>X</button>
<div className="challenge">Verification</div>
2023-03-12 22:07:15 +01:00
<img src={captchaImage} alt="captcha" />
<input
type="text"
autoComplete='off'
placeholder="TYPE THE CAPTCHA HERE AND PRESS ENTER"
value={captchaResponse}
2023-03-13 14:29:34 +01:00
onChange={handleChallengeResponse}
autoFocus />
2023-03-09 17:51:56 +01:00
</div>
</StyledModal>
);
};
Modal.setAppElement('#root');
export default CaptchaModal;