mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 10:51:12 -05:00
feat: Centralize Auth Modal and require auth for actions
This commit is contained in:
@@ -14,11 +14,13 @@ import { RideModelForm } from '@/components/admin/RideModelForm';
|
||||
import { AutocompleteSearch } from '@/components/search/AutocompleteSearch';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { useAuthModal } from '@/hooks/useAuthModal';
|
||||
|
||||
export default function ManufacturerModels() {
|
||||
const { manufacturerSlug } = useParams<{ manufacturerSlug: string }>();
|
||||
const navigate = useNavigate();
|
||||
const { user } = useAuth();
|
||||
const { requireAuth } = useAuthModal();
|
||||
const [manufacturer, setManufacturer] = useState<Company | null>(null);
|
||||
const [models, setModels] = useState<RideModel[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -93,8 +95,7 @@ export default function ManufacturerModels() {
|
||||
|
||||
const handleCreateSubmit = async (data: any) => {
|
||||
try {
|
||||
if (!user) {
|
||||
navigate('/auth');
|
||||
if (!user || !manufacturer) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -194,12 +195,12 @@ export default function ManufacturerModels() {
|
||||
<FerrisWheel className="w-8 h-8 text-primary" />
|
||||
<h1 className="text-4xl font-bold">Models by {manufacturer.name}</h1>
|
||||
</div>
|
||||
{user && (
|
||||
<Button onClick={() => setIsCreateModalOpen(true)}>
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
Add Ride Model
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => requireAuth(() => setIsCreateModalOpen(true), "Sign in to add a ride model")}
|
||||
>
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
Add Ride Model
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-lg text-muted-foreground mb-4">
|
||||
Explore all ride models manufactured by {manufacturer.name}
|
||||
|
||||
Reference in New Issue
Block a user