feat: Centralize Auth Modal and require auth for actions

This commit is contained in:
gpt-engineer-app[bot]
2025-10-16 12:59:20 +00:00
parent e340f1c489
commit 6819682ace
14 changed files with 138 additions and 125 deletions

View File

@@ -15,11 +15,13 @@ import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
import { toast } from '@/hooks/use-toast';
import { submitCompanyCreation } from '@/lib/companyHelpers';
import { useAuthModal } from '@/hooks/useAuthModal';
export default function Manufacturers() {
const navigate = useNavigate();
const { user } = useAuth();
const { isModerator } = useUserRole();
const { requireAuth } = useAuthModal();
const [companies, setCompanies] = useState<Company[]>([]);
const [loading, setLoading] = useState(true);
const [searchQuery, setSearchQuery] = useState('');
@@ -66,10 +68,7 @@ export default function Manufacturers() {
const handleCreateSubmit = async (data: any) => {
try {
if (!user) {
navigate('/auth');
return;
}
if (!user) return;
await submitCompanyCreation(
data,
@@ -136,13 +135,7 @@ export default function Manufacturers() {
<div className="flex items-center gap-2">
<Button
onClick={() => {
if (!user) {
navigate('/auth');
} else {
setIsCreateModalOpen(true);
}
}}
onClick={() => requireAuth(() => setIsCreateModalOpen(true), "Sign in to add a manufacturer")}
className="gap-2"
>
<Plus className="w-4 h-4" />