import React, { useState, useRef } from "react"; import { useAuth } from "../hooks/useAuth"; export const CreateOrganizationForm = () => { const [organizationName, setOrganizationName] = useState(""); const [logo, setLogo] = useState(null); const [logoPreview, setLogoPreview] = useState(""); const fileInputRef = useRef(null); const { createOrganization, isLoading, error } = useAuth(); const handleLogoChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { setLogo(file); const reader = new FileReader(); reader.onloadend = () => { setLogoPreview(reader.result as string); }; reader.readAsDataURL(file); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (organizationName.trim()) { await createOrganization({ name: organizationName, logo: logo || undefined, }); } }; return (
fileInputRef.current?.click()} > {logoPreview ? ( Organization logo ) : (
Загрузить лого
)}
setOrganizationName(e.target.value)} className="w-full px-4 py-2 rounded-lg border transition-all focus:outline-none focus:ring-2" style={{ backgroundColor: "var(--input-bg)", color: "var(--text-primary)", borderColor: "var(--border)", "--tw-ring-color": "var(--accent)", }} required disabled={isLoading} placeholder="Введите название организации" />
{error && (
{error}
)}
); };