Added congregation table and field
This commit is contained in:
@ -56,11 +56,11 @@ export const authOptions: NextAuthOptions = {
|
||||
keyId: process.env.APPLE_KEY_ID,
|
||||
}
|
||||
}),
|
||||
// AzureADProvider({
|
||||
// clientId: process.env.AZURE_AD_CLIENT_ID,
|
||||
// clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
|
||||
// tenantId: process.env.AZURE_AD_TENANT_ID,
|
||||
// }),
|
||||
AzureADProvider({
|
||||
clientId: process.env.AZURE_AD_CLIENT_ID,
|
||||
clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
|
||||
tenantId: process.env.AZURE_AD_TENANT_ID,
|
||||
}),
|
||||
CredentialsProvider({
|
||||
id: 'credentials',
|
||||
// The name to display on the sign in form (e.g. 'Sign in with...')
|
||||
|
@ -74,6 +74,13 @@ export default function SignIn({ csrfToken }) {
|
||||
src="https://authjs.dev/img/providers/apple.svg" className="mr-2" />
|
||||
Влез чрез Apple
|
||||
</button> */}
|
||||
{/* microsoft */}
|
||||
{/* <button onClick={() => signIn('azure-ad', { callbackUrl: '/' })}
|
||||
className="mt-4 flex items-center justify-center w-full py-3 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50">
|
||||
<img loading="lazy" height="24" width="24" alt="Microsoft logo"
|
||||
src="https://authjs.dev/img/providers/azure-ad.svg" className="mr-2" />
|
||||
Влез чрез Microsoft
|
||||
</button> */}
|
||||
</div>
|
||||
<div className="w-full max-w-xs mt-8 mb-8">
|
||||
<hr className="border-t border-gray-300" />
|
||||
|
@ -4,6 +4,7 @@ import Layout from "../../../components/layout";
|
||||
import LocationCard from "../../../components/location/LocationCard";
|
||||
import axiosServer from '../../../src/axiosServer';
|
||||
import ProtectedRoute from '../../../components/protectedRoute';
|
||||
import CongregationCRUD from "../publishers/congregationCRUD";
|
||||
interface IProps {
|
||||
item: Location;
|
||||
}
|
||||
@ -32,6 +33,7 @@ function LocationsPage({ items = [] }: IProps) {
|
||||
</a>
|
||||
</div>
|
||||
</ProtectedRoute>
|
||||
<CongregationCRUD />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
103
pages/cart/publishers/congregationCRUD.tsx
Normal file
103
pages/cart/publishers/congregationCRUD.tsx
Normal file
@ -0,0 +1,103 @@
|
||||
// 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 (
|
||||
<ProtectedRoute allowedRoles={[UserRole.ADMIN]}>
|
||||
<div className="h-5/6 grid place-items-start px-4 pt-8">
|
||||
<div className="flex flex-col w-full px-4">
|
||||
<h1 className="text-2xl font-bold text-center">Сборове</h1>
|
||||
<div className="flex gap-2 mb-4">
|
||||
<input
|
||||
type="text"
|
||||
value={newCongregation}
|
||||
onChange={(e) => setNewCongregation(e.target.value)}
|
||||
placeholder="Име на сбор"
|
||||
className="px-4 py-2 rounded-md border border-gray-300"
|
||||
/>
|
||||
<button
|
||||
onClick={addCongregation}
|
||||
className="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"
|
||||
>
|
||||
Добави
|
||||
</button>
|
||||
</div>
|
||||
<table className="w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Име</th>
|
||||
<th>Действия</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{congregations.map((congregation) => (
|
||||
<tr key={congregation.id}>
|
||||
<td>{congregation.name}</td>
|
||||
<td className='right'>
|
||||
{/* <button
|
||||
onClick={() => router.push(`/cart/publishers/congregation/${congregation.id}`)}
|
||||
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
|
||||
>
|
||||
Преглед
|
||||
</button> */}
|
||||
<button
|
||||
onClick={() => deleteCongregation(congregation.id)}
|
||||
className="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded"
|
||||
>
|
||||
Изтрий
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</ProtectedRoute>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user