import React, { useState } from 'react'; import { View, Modal, StyleSheet, TextInput, Alert, Pressable } from 'react-native'; import { useTheme } from '~/features/theme/ThemeProvider'; import Text from '~/components/atoms/Text'; import Button from '~/components/atoms/Button'; import colors from '~/tailwind.config.js'; interface InviteUserModalProps { visible: boolean; spaceId: string; spaceName: string; onClose: () => void; onSubmit: (email: string, role: string) => Promise; } /** * Modal for inviting a user to join a space */ export default function InviteUserModal({ visible, spaceId, spaceName, onClose, onSubmit }: InviteUserModalProps) { const { isDark, themeVariant } = useTheme(); const [email, setEmail] = useState(''); const [selectedRole, setSelectedRole] = useState('viewer'); const [isSubmitting, setIsSubmitting] = useState(false); const [emailError, setEmailError] = useState(''); // Background color from tailwind config const backgroundColor = isDark ? ((colors as any).theme?.extend?.colors?.dark)?.[themeVariant]?.modalBackground || '#1E1E1E' : ((colors as any).theme?.extend?.colors)?.[themeVariant]?.modalBackground || '#FFFFFF'; const roles = [ { id: 'viewer', label: 'Viewer', description: 'Can view content but not edit' }, { id: 'editor', label: 'Editor', description: 'Can view and edit content' }, { id: 'admin', label: 'Admin', description: 'Full access except deletion' } ]; const handleClose = () => { setEmail(''); setSelectedRole('viewer'); setEmailError(''); onClose(); }; const validateEmail = (email: string) => { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!email.trim()) { setEmailError('Email is required'); return false; } else if (!emailRegex.test(email)) { setEmailError('Please enter a valid email address'); return false; } setEmailError(''); return true; }; const handleSubmit = async () => { // Validate email if (!validateEmail(email)) { return; } setIsSubmitting(true); try { await onSubmit(email, selectedRole); handleClose(); Alert.alert('Success', `Invitation sent to ${email}`); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Failed to send invitation'; Alert.alert('Error', errorMessage); } finally { setIsSubmitting(false); } }; const Role = ({ role }: { role: typeof roles[0] }) => ( {selectedRole === role.id && ( )} {role.label} {role.description} ); return ( Invite to Space