// a simple CRUD componenet for congregations for admins import { useEffect, useState } from 'react'; import axiosInstance from '../../../src/axiosSecure'; import toast from 'react-hot-toast'; import Layout from '../../../components/layout'; import ProtectedRoute from '../../../components/protectedRoute'; import { UserRole } from '@prisma/client'; import { useRouter } from 'next/router'; export default function CongregationCRUD() { const [congregations, setCongregations] = useState([]); const [newCongregation, setNewCongregation] = useState(''); const router = useRouter(); const fetchCongregations = async () => { try { const { data: congregationsData } = await axiosInstance.get(`/api/data/congregations`); setCongregations(congregationsData); } catch (error) { console.error(error); } }; const addCongregation = async () => { try { await axiosInstance.post(`/api/data/congregations`, { name: newCongregation, address: "" }); toast.success('Успешно добавен сбор'); setNewCongregation(''); fetchCongregations(); } catch (error) { console.error(error); } }; const deleteCongregation = async (id) => { try { await axiosInstance.delete(`/api/data/congregations/${id}`); toast.success('Успешно изтрит сбор'); fetchCongregations(); } catch (error) { console.error(error); } }; useEffect(() => { fetchCongregations(); }, []); return (

Сборове

setNewCongregation(e.target.value)} placeholder="Име на сбор" className="px-4 py-2 rounded-md border border-gray-300" />
{congregations.map((congregation) => ( ))}
Име Действия
{congregation.name} {/* */}
); }