import Box from '@mui/material/Box'
import Button from '@mui/material/Button'
import Modal from '@mui/material/Modal'
import { Field, Form, Formik } from 'formik'
import React, { useState } from 'react'
import { sendRSVPInfo } from '../../api'
import { isBrowser } from '../../utils'
import { combineValidators, emailValidator, requiredValidator } from '../../validators'
import { CustomField, Loader } from '../common/index'
interface IRsvpContainerPage {
showSection?: boolean;
eventId: number;
}
interface IRSVPValuesTypes {
email: string;
}
const style: React.CSSProperties = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
minWidth: 480,
backgroundColor: '#e3e3e3',
border: '1px solid white',
outline: 'none',
padding: '14px',
maxHeight: '85vh',
overflow: 'auto',
}
export const RsvpContainer = ({ showSection = false, eventId }: IRsvpContainerPage) => {
const userDataEncoded = isBrowser ? window.localStorage.getItem('user_data') : ''
const parsedData = JSON.parse(userDataEncoded || '{}')
const [loading, setLoading] = useState(false)
const [modal, setModal] = useState({ isOpen: false, text: '' })
const handleModalClose = () => {
setModal({ isOpen: false, text: '' })
}
const handleSubmit = async (values: IRSVPValuesTypes) => {
try {
setLoading(true)
const requestData = { data: { email: values.email } }
const response = await sendRSVPInfo(eventId, requestData)
setModal({ isOpen: true, text: response.message })
} catch (error) {
if (error.response.status === 403) {
setModal({ isOpen: true, text: error.response.data?.message })
}
} finally {
setLoading(false)
}
}
if (!showSection) {
return null
}
return (
<>