import Modal from '@app/components/Common/Modal'; import useSettings from '@app/hooks/useSettings'; import defineMessages from '@app/utils/defineMessages'; import { Transition } from '@headlessui/react'; import axios from 'axios'; import { Field, Formik } from 'formik'; import { useIntl } from 'react-intl'; import * as Yup from 'yup'; const messages = defineMessages('components.Login', { title: 'Add Email', description: 'Since this is your first time logging into {applicationName}, you are required to add a valid email address.', email: 'Email address', validationEmailRequired: 'You must provide an email', validationEmailFormat: 'Invalid email', saving: 'Adding…', save: 'Add', }); interface AddEmailModalProps { username: string; password: string; onClose: () => void; onSave: () => void; } const AddEmailModal: React.FC = ({ onClose, username, password, onSave, }) => { const intl = useIntl(); const settings = useSettings(); const EmailSettingsSchema = Yup.object().shape({ email: Yup.string() .email(intl.formatMessage(messages.validationEmailFormat)) .required(intl.formatMessage(messages.validationEmailRequired)), }); return ( { try { await axios.post('/api/v1/auth/jellyfin', { username: username, password: password, email: values.email, }); onSave(); } catch (e) { // set error here } }} > {({ errors, touched, handleSubmit, isSubmitting, isValid }) => { return ( handleSubmit()} title={intl.formatMessage(messages.title)} > {intl.formatMessage(messages.description, { applicationName: settings.currentSettings.applicationTitle, })}
{errors.email && touched.email && (
{errors.email}
)}
); }}
); }; export default AddEmailModal;