Message 8
Message 8
try {
const response = await fetch('http://localhost:8000/tenant/create/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: formData.name,
description: formData.description,
email: formData.email
}),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || 'Failed to create tenant');
}
const newTenant = {
id: data.id || Date.now(),
name: formData.name,
email: formData.email,
description: formData.description,
createdAt: new Date().toISOString(),
imageUrl: null,
path: data.path || `/${formData.name}`,
subGroups: data.subGroups || []
};
onTenantCreated(newTenant);
onClose();
} catch (error) {
console.error("Error creating tenant:", error);
setError(error.message || 'Failed to create tenant');
} finally {
setIsSubmitting(false);
}
};
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-
center z-50 p-4">
<div className="bg-white rounded-lg shadow-lg w-full max-w-md">
<div className="p-6">
<div className="flex justify-between items-center mb-4">
<h2 className="text-xl font-bold text-gray-800">Create New Tenant</h2>
<button
onClick={onClose}
className="text-gray-500 hover:text-gray-700"
>
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0
0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div>
<label htmlFor="email" className="block text-sm font-medium text-
gray-700 mb-1">
Contact Email *
</label>
<input
type="email"
id="email"
name="email"
value={formData.email}
onChange={handleChange}
required
className="w-full px-3 py-2 border border-gray-300 rounded-md
focus:outline-none focus:ring-2 focus:ring-green-500"
placeholder="Enter contact email"
/>
</div>
<div>
<label htmlFor="description" className="block text-sm font-medium
text-gray-700 mb-1">
Description
</label>
<textarea
id="description"
name="description"
value={formData.description}
onChange={handleChange}
rows={3}
className="w-full px-3 py-2 border border-gray-300 rounded-md
focus:outline-none focus:ring-2 focus:ring-green-500"
placeholder="Enter tenant description"
/>
</div>
{error && (
<div className="text-red-500 text-sm mt-2">
Error: {error}
</div>
)}