wip permits file managment for admins
This commit is contained in:
@ -3,35 +3,57 @@ import Layout from "../components/layout";
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { url } from 'inspector';
|
||||
import ProtectedRoute, { serverSideAuth } from "/components/protectedRoute";
|
||||
|
||||
const PDFViewerPage = ({ pdfFiles }) => {
|
||||
const [files, setFiles] = useState(pdfFiles);
|
||||
|
||||
const handleFileDelete = async (fileName) => {
|
||||
try {
|
||||
await axios.delete(`/api/delete-file?name=${fileName}`);
|
||||
setFiles(files.filter(file => file.name !== fileName));
|
||||
} catch (error) {
|
||||
console.error('Error deleting file:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFileUpload = async (event) => {
|
||||
const file = event.target.files[0];
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
try {
|
||||
const response = await axios.post('/api/upload-file', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
});
|
||||
setFiles([...files, response.data]);
|
||||
} catch (error) {
|
||||
console.error('Error uploading file:', error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<h1 className="text-3xl font-bold p-4 pt-8">Разрешителни</h1>
|
||||
<div style={{ width: '100%', height: 'calc(100vh - 100px)' }}> {/* Adjust the 100px based on your header/footer size */}
|
||||
{/* <p className="p-1">
|
||||
{pdfFiles.map((file, index) => (
|
||||
<p className="p-2">
|
||||
<a href={file.url} className="text-blue-600 hover:text-blue-800 visited:text-purple-600 underline" target='_blank'>
|
||||
Свали: {file.name}
|
||||
</a>
|
||||
</p>
|
||||
))}
|
||||
</p> */}
|
||||
{pdfFiles.map((file, index) => (
|
||||
<ProtectedRoute>
|
||||
|
||||
// <React.Fragment key={file.name}>
|
||||
// {index > 0 && <div className="bg-gray-400 w-px h-6"></div>} {/* Vertical line separator */}
|
||||
// <a
|
||||
// href={file.url}
|
||||
// target="_blank"
|
||||
// className={`text-lg py-2 px-4 bg-gray-200 text-gray-800 hover:bg-blue-500 hover:text-white ${index === 0 ? 'rounded-l-full' : index === pdfFiles.length - 1 ? 'rounded-r-full' : ''}`}
|
||||
// >
|
||||
// {file.name}
|
||||
// </a>
|
||||
// </React.Fragment>
|
||||
<input type="file" onChange={handleFileUpload} className="mb-4" />
|
||||
{files.map((file, index) => (
|
||||
<div key={file.name} className="py-2">
|
||||
<a href={file.url} className="text-blue-600 hover:text-blue-800 visited:text-purple-600 underline" target='_blank'>
|
||||
{file.name}
|
||||
</a>
|
||||
<button onClick={() => handleFileDelete(file.name)} className="ml-4 bg-red-500 hover:bg-red-700 text-white font-bold py-1 px-2 rounded">
|
||||
изтрий
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</ProtectedRoute>
|
||||
|
||||
<div style={{ width: '100%', height: 'calc(100vh - 100px)' }}> {/* Adjust the 100px based on your header/footer size */}
|
||||
{pdfFiles.map((file, index) => (
|
||||
<> <p className="pt-2">
|
||||
<a href={file.url} className="text-blue-600 hover:text-blue-800 visited:text-purple-600 underline" target='_blank'>
|
||||
Свали: {file.name}
|
||||
|
Reference in New Issue
Block a user