budget-view-finance/src/components/whatsappGroups/CreateGroupForm.tsx
gpt-engineer-app[bot] a9769b76db Fix: Inconsistent WhatsApp instance detection
Unifies instance verification logic using `useExistingInstanceCheck` across components, corrects the Supabase query, and adds re-verification after instance creation to resolve inconsistencies in WhatsApp instance detection and group creation.
2025-06-21 16:19:14 +00:00

53 lines
1.5 KiB
TypeScript

import { useExistingInstanceCheck } from '@/hooks/whatsapp/useExistingInstanceCheck'; // <--- Hook UNIFICADO!
import { useGroupCreation } from '@/hooks/whatsappGroups/useGroupCreation';
import LoadingState from './LoadingState';
import NoInstanceState from './NoInstanceState';
import GroupCreationForm from './GroupCreationForm';
import { useEffect } from 'react';
interface CreateGroupFormProps {
userEmail: string;
onSuccess: () => void;
}
const CreateGroupForm = ({ userEmail, onSuccess }: CreateGroupFormProps) => {
// Use o hook UNIFICADO E CORRETO
const {
hasExistingInstance,
checkingExistingInstance,
existingInstanceData,
recheckInstance
} = useExistingInstanceCheck(userEmail);
const { cadastrando, handleCadastrarGrupo } = useGroupCreation(userEmail, onSuccess);
useEffect(() => {
recheckInstance();
}, [userEmail]); // Re-verifica quando o email muda
if (checkingExistingInstance) {
return <LoadingState message="Verificando instância WhatsApp..." />;
}
// A lógica agora é a mesma da outra página: `hasExistingInstance`
if (!hasExistingInstance) {
return <NoInstanceState userInstance={existingInstanceData} />;
}
const handleSubmit = (nomeGrupo: string) => {
handleCadastrarGrupo(nomeGrupo, existingInstanceData);
};
return (
<GroupCreationForm
userInstance={existingInstanceData!}
userEmail={userEmail}
cadastrando={cadastrando}
onSubmit={handleSubmit}
/>
);
};
export default CreateGroupForm;