naim-firebase-auth-wrapper
Version:
React components and hooks for Firebase Authentication and Firestore with Mantine UI
51 lines • 2.71 kB
JavaScript
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { TextInput, Button, Paper, Title, Select, Stack, Text, Group } from '@mantine/core';
import { useAuth } from '../hooks/useAuth';
import { createInvitation } from '../services/firestore';
export const InviteUserForm = ({ orgId, onSuccess, onError, onInvitationCreated }) => {
const { user } = useAuth();
const [email, setEmail] = useState('');
const [role, setRole] = useState('member');
const [loading, setLoading] = useState(false);
const [successMessage, setSuccessMessage] = useState('');
const handleInvite = async () => {
if (!user || !email || !role)
return;
setLoading(true);
setSuccessMessage('');
try {
await createInvitation({
email,
orgId,
role: role,
invitedBy: user.uid,
status: 'pending',
token: '', // Will be generated by the service
createdAt: new Date(),
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000) // 7 days from now
}, {
onInvitationCreated: (invitation) => {
onInvitationCreated?.(invitation);
onSuccess?.(invitation.token, email, invitation.orgName, invitation.inviterName || '');
}
});
setEmail('');
setSuccessMessage(`Invitation sent to ${email}`);
}
catch (error) {
console.error('Error sending invitation:', error);
onError?.(error);
}
finally {
setLoading(false);
}
};
return (_jsxs(Paper, { radius: "md", p: "xl", withBorder: true, children: [_jsx(Title, { order: 2, mb: "md", children: "Invite User" }), _jsxs(Stack, { gap: "md", children: [_jsx(TextInput, { label: "Email Address", placeholder: "user@example.com", value: email, onChange: (e) => setEmail(e.target.value), required: true }), _jsx(Select, { label: "Role", placeholder: "Select a role", value: role, onChange: (value) => setRole(value || 'member'), data: [
{ value: 'admin', label: 'Admin' },
{ value: 'member', label: 'Member' },
{ value: 'guest', label: 'Guest' }
], required: true }), successMessage && (_jsx(Text, { color: "green", fw: 500, children: successMessage })), _jsx(Group, { justify: "flex-end", children: _jsx(Button, { onClick: handleInvite, loading: loading, children: "Send Invitation" }) })] })] }));
};
//# sourceMappingURL=InviteUserForm.js.map