Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb298cb846 | |||
| 9c44c66b22 | |||
| 29d2ed6b96 | |||
| 661bf7a77f | |||
| 7bce00800b | |||
| 427775a038 | |||
| 8004a7a21c | |||
| 57f95661cc | |||
| 9d149e6abe | |||
| 2ed1bee149 | |||
| 24a8bc4113 | |||
| f35eab14e6 |
@@ -0,0 +1,15 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "NewsMedia" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"headline" TEXT NOT NULL,
|
||||
"content" TEXT,
|
||||
"firstPara" TEXT,
|
||||
"secondPara" TEXT,
|
||||
"author" TEXT,
|
||||
"date" TIMESTAMP(3),
|
||||
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "NewsMedia_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
@@ -186,3 +186,19 @@ model EmailConfig {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model NewsMedia {
|
||||
id Int @id @default(autoincrement())
|
||||
|
||||
headline String
|
||||
content String?
|
||||
firstPara String?
|
||||
secondPara String?
|
||||
author String?
|
||||
date DateTime?
|
||||
|
||||
isActive Boolean @default(true)
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import appointmentRoutes from "./routes/appointment.routes.js";
|
||||
import inquiryRoutes from "./routes/inquiry.routes.js";
|
||||
import academicsResearchRoutes from "./routes/academicsResearch.routes.js";
|
||||
import emailConfigRoutes from "./routes/emailConfig.routes.js";
|
||||
import newsMediaRoutes from "./routes/newsMedia.routes.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
@@ -49,6 +50,7 @@ app.use("/api/appointments", appointmentRoutes);
|
||||
app.use("/api/inquiry", inquiryRoutes);
|
||||
app.use("/api/academics", academicsResearchRoutes);
|
||||
app.use("/api/email", emailConfigRoutes);
|
||||
app.use("/api/newsMedia", newsMediaRoutes);
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
|
||||
@@ -29,6 +29,53 @@ export const getAllDepartments = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getDepartmentByName = async (req, res) => {
|
||||
try {
|
||||
const {name} = req.query;
|
||||
|
||||
if (!name) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Department name is required",
|
||||
});
|
||||
}
|
||||
|
||||
const department = await prisma.department.findFirst({
|
||||
where: {
|
||||
name: name,
|
||||
},
|
||||
});
|
||||
|
||||
if (!department) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Department not found",
|
||||
});
|
||||
}
|
||||
|
||||
const response = {
|
||||
departmentId: department.departmentId,
|
||||
name: department.name,
|
||||
para1: department.para1 ?? "",
|
||||
para2: department.para2 ?? "",
|
||||
para3: department.para3 ?? "",
|
||||
facilities: department.facilities ?? "",
|
||||
services: department.services ?? "",
|
||||
};
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
data: [response],
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch department",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export async function createDepartment(req, res) {
|
||||
try {
|
||||
const {departmentId, name, para1, para2, para3, facilities, services} =
|
||||
|
||||
@@ -16,8 +16,7 @@ export const getAllDoctors = async (req, res) => {
|
||||
orderBy: {name: "asc"},
|
||||
});
|
||||
|
||||
const formatted = doctors.map((doc, index) => {
|
||||
return {
|
||||
const formatted = doctors.map((doc, index) => ({
|
||||
SL_NO: String(index + 1),
|
||||
doctorId: doc.doctorId,
|
||||
name: doc.name,
|
||||
@@ -42,12 +41,10 @@ export const getAllDoctors = async (req, res) => {
|
||||
return {
|
||||
departmentId: d.department.departmentId,
|
||||
departmentName: d.department.name,
|
||||
|
||||
timing: timingArray.join(" & "),
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
@@ -113,6 +110,54 @@ export const getDoctorByDoctorId = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// get doctors by department
|
||||
export const getDoctorsByDepartmentId = async (req, res) => {
|
||||
try {
|
||||
const {Department_ID} = req.query;
|
||||
|
||||
if (!Department_ID) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Department_ID is required",
|
||||
});
|
||||
}
|
||||
|
||||
const department = await prisma.department.findUnique({
|
||||
where: {departmentId: Department_ID},
|
||||
});
|
||||
|
||||
if (!department) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Department not found",
|
||||
});
|
||||
}
|
||||
|
||||
const doctors = await prisma.doctorDepartment.findMany({
|
||||
where: {departmentId: department.id},
|
||||
include: {
|
||||
doctor: true,
|
||||
},
|
||||
});
|
||||
|
||||
const result = doctors.map((d) => ({
|
||||
GG_ID: d.doctor.doctorId,
|
||||
Name: d.doctor.name,
|
||||
}));
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: result,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch doctors",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// add doctors
|
||||
export const createDoctor = async (req, res) => {
|
||||
try {
|
||||
@@ -184,20 +229,14 @@ export const updateDoctor = async (req, res) => {
|
||||
});
|
||||
|
||||
if (!doctor) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Doctor not found",
|
||||
});
|
||||
return res
|
||||
.status(404)
|
||||
.json({success: false, message: "Doctor not found"});
|
||||
}
|
||||
|
||||
await prisma.doctor.update({
|
||||
where: {id: doctor.id},
|
||||
data: {
|
||||
name,
|
||||
designation,
|
||||
workingStatus,
|
||||
qualification,
|
||||
},
|
||||
data: {name, designation, workingStatus, qualification},
|
||||
});
|
||||
|
||||
const oldRelations = await prisma.doctorDepartment.findMany({
|
||||
@@ -229,25 +268,24 @@ export const updateDoctor = async (req, res) => {
|
||||
});
|
||||
|
||||
if (dep.timing) {
|
||||
const {id, doctorDepartmentId, createdAt, updatedAt, ...cleanTiming} =
|
||||
dep.timing;
|
||||
|
||||
await prisma.doctorTiming.create({
|
||||
data: {
|
||||
doctorDepartmentId: doctorDepartment.id,
|
||||
...dep.timing,
|
||||
...cleanTiming,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Doctor updated successfully",
|
||||
});
|
||||
res
|
||||
.status(200)
|
||||
.json({success: true, message: "Doctor updated successfully"});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to update doctor",
|
||||
});
|
||||
console.error("Update Error:", error);
|
||||
res.status(500).json({success: false, message: "Failed to update doctor"});
|
||||
}
|
||||
};
|
||||
//delete doctor
|
||||
@@ -256,13 +294,6 @@ export const deleteDoctor = async (req, res) => {
|
||||
try {
|
||||
const {doctorId} = req.params;
|
||||
|
||||
if (!doctorId) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Doctor ID is required",
|
||||
});
|
||||
}
|
||||
|
||||
const doctor = await prisma.doctor.findUnique({
|
||||
where: {doctorId},
|
||||
});
|
||||
@@ -270,7 +301,7 @@ export const deleteDoctor = async (req, res) => {
|
||||
if (!doctor) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: `Doctor with ID ${doctorId} not found`,
|
||||
message: "Doctor not found",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -294,7 +325,7 @@ export const deleteDoctor = async (req, res) => {
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: `Doctor ${doctorId} deleted successfully`,
|
||||
message: "Doctor deleted successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -320,23 +351,19 @@ export const getDoctorTimings = async (req, res) => {
|
||||
});
|
||||
|
||||
const result = doctors.map((doc) => {
|
||||
let timing = {};
|
||||
|
||||
if (doc.departments.length > 0) {
|
||||
timing = doc.departments[0].timing ?? {};
|
||||
}
|
||||
const timing = doc.departments[0]?.timing || {};
|
||||
|
||||
return {
|
||||
Doctor_ID: doc.doctorId,
|
||||
Doctor: doc.name,
|
||||
Monday: timing?.monday ?? "",
|
||||
Tuesday: timing?.tuesday ?? "",
|
||||
Wednesday: timing?.wednesday ?? "",
|
||||
Thursday: timing?.thursday ?? "",
|
||||
Friday: timing?.friday ?? "",
|
||||
Saturday: timing?.saturday ?? "",
|
||||
Sunday: timing?.sunday ?? "",
|
||||
Additional: timing?.additional ?? "",
|
||||
Monday: timing.monday || "",
|
||||
Tuesday: timing.tuesday || "",
|
||||
Wednesday: timing.wednesday || "",
|
||||
Thursday: timing.thursday || "",
|
||||
Friday: timing.friday || "",
|
||||
Saturday: timing.saturday || "",
|
||||
Sunday: timing.sunday || "",
|
||||
Additional: timing.additional || "",
|
||||
};
|
||||
});
|
||||
|
||||
@@ -380,26 +407,11 @@ export const getDoctorTimingById = async (req, res) => {
|
||||
const result = {
|
||||
doctorId: doctor.doctorId,
|
||||
doctorName: doctor.name,
|
||||
|
||||
departments: doctor.departments.map((d) => {
|
||||
const t = d.timing || {};
|
||||
|
||||
return {
|
||||
departments: doctor.departments.map((d) => ({
|
||||
departmentId: d.department.departmentId,
|
||||
departmentName: d.department.name,
|
||||
|
||||
timing: {
|
||||
monday: t.monday || "",
|
||||
tuesday: t.tuesday || "",
|
||||
wednesday: t.wednesday || "",
|
||||
thursday: t.thursday || "",
|
||||
friday: t.friday || "",
|
||||
saturday: t.saturday || "",
|
||||
sunday: t.sunday || "",
|
||||
additional: t.additional || "",
|
||||
},
|
||||
};
|
||||
}),
|
||||
timing: d.timing || {},
|
||||
})),
|
||||
};
|
||||
|
||||
res.status(200).json({
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
import prisma from "../prisma/client.js";
|
||||
|
||||
// GET ALL NEWS
|
||||
|
||||
export const getAllNews = async (req, res) => {
|
||||
try {
|
||||
const page = parseInt(req.query.page);
|
||||
const limit = parseInt(req.query.limit);
|
||||
|
||||
if (!page && !limit) {
|
||||
const news = await prisma.newsMedia.findMany({
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
const response = news.map((n) => ({
|
||||
Id: n.id.toString(),
|
||||
Headline: n.headline,
|
||||
Content: n.content,
|
||||
FirstPara: n.firstPara,
|
||||
SecondPara: n.secondPara,
|
||||
Date: n.date,
|
||||
Author: n.author,
|
||||
}));
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
data: response,
|
||||
meta: null,
|
||||
});
|
||||
}
|
||||
|
||||
const currentPage = page || 1;
|
||||
const currentLimit = limit || 10;
|
||||
|
||||
const skip = (currentPage - 1) * currentLimit;
|
||||
|
||||
const [news, total] = await Promise.all([
|
||||
prisma.newsMedia.findMany({
|
||||
orderBy: { createdAt: "desc" },
|
||||
skip,
|
||||
take: currentLimit,
|
||||
}),
|
||||
prisma.newsMedia.count(),
|
||||
]);
|
||||
|
||||
const response = news.map((n) => ({
|
||||
Id: n.id.toString(),
|
||||
Headline: n.headline,
|
||||
Content: n.content,
|
||||
FirstPara: n.firstPara,
|
||||
SecondPara: n.secondPara,
|
||||
Date: n.date,
|
||||
Author: n.author,
|
||||
}));
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
data: response,
|
||||
meta: {
|
||||
total,
|
||||
page: currentPage,
|
||||
limit: currentLimit,
|
||||
totalPages: Math.ceil(total / currentLimit),
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch news",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// GET NEWS BY ID
|
||||
|
||||
export const getNewsById = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
const n = await prisma.newsMedia.findUnique({
|
||||
where: { id: Number(id) },
|
||||
});
|
||||
|
||||
if (!n) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "News not found",
|
||||
});
|
||||
}
|
||||
|
||||
const response = {
|
||||
Id: n.id.toString(),
|
||||
Headline: n.headline,
|
||||
Content: n.content,
|
||||
FirstPara: n.firstPara,
|
||||
SecondPara: n.secondPara,
|
||||
Date: n.date,
|
||||
Author: n.author,
|
||||
};
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
data: response,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to fetch news",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// CREATE NEWS
|
||||
|
||||
export const createNews = async (req, res) => {
|
||||
try {
|
||||
const { headline, content, firstPara, secondPara, date, author } = req.body;
|
||||
|
||||
if (!headline) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Headline is required",
|
||||
});
|
||||
}
|
||||
|
||||
const news = await prisma.newsMedia.create({
|
||||
data: {
|
||||
headline,
|
||||
content,
|
||||
firstPara,
|
||||
secondPara,
|
||||
date: date ? new Date(date) : null,
|
||||
author,
|
||||
},
|
||||
});
|
||||
|
||||
return res.status(201).json({
|
||||
success: true,
|
||||
message: "News created successfully",
|
||||
data: news,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to create news",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// UPDATE NEWS
|
||||
|
||||
export const updateNews = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
const news = await prisma.newsMedia.update({
|
||||
where: { id: Number(id) },
|
||||
data: {
|
||||
...req.body,
|
||||
date: req.body.date ? new Date(req.body.date) : undefined,
|
||||
},
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: "News updated successfully",
|
||||
data: news,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to update news",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// DELETE NEWS
|
||||
|
||||
export const deleteNews = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
await prisma.newsMedia.delete({
|
||||
where: { id: Number(id) },
|
||||
});
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: "News deleted successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Failed to delete news",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -11,8 +11,8 @@ import jwtAuthMiddleware from "../middleware/auth.js";
|
||||
const router = express.Router();
|
||||
|
||||
router.post("/", createAcademicsResearch);
|
||||
router.get("/getAll", getAcademicsResearch);
|
||||
router.get("/:id", getSingleAcademicsResearch);
|
||||
router.get("/getAll", jwtAuthMiddleware, getAcademicsResearch);
|
||||
router.get("/:id", jwtAuthMiddleware, getSingleAcademicsResearch);
|
||||
router.delete("/:id", jwtAuthMiddleware, deleteAcademicsResearch);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -13,11 +13,11 @@ const router = express.Router();
|
||||
|
||||
/* PUBLIC */
|
||||
|
||||
router.get("/getall", getAppointments);
|
||||
router.get("/getall", jwtAuthMiddleware, getAppointments);
|
||||
router.post("/", createAppointment);
|
||||
|
||||
router.get("/:id", getAppointment);
|
||||
router.patch("/:id", updateAppointment);
|
||||
router.get("/:id", jwtAuthMiddleware, getAppointment);
|
||||
router.patch("/:id", jwtAuthMiddleware, updateAppointment);
|
||||
router.delete("/:id", jwtAuthMiddleware, deleteAppointment);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -13,13 +13,13 @@ import jwtAuthMiddleware from "../middleware/auth.js";
|
||||
const router = express.Router();
|
||||
|
||||
/* PUBLIC */
|
||||
|
||||
router.get("/getAll", getCandidates);
|
||||
router.get("/:id", getCandidate);
|
||||
router.get("/career/:careerId", getCandidatesByCareer);
|
||||
|
||||
router.post("/", createCandidate);
|
||||
router.patch("/:id", updateCandidate);
|
||||
|
||||
router.get("/getAll", jwtAuthMiddleware, getCandidates);
|
||||
router.get("/:id", jwtAuthMiddleware, getCandidate);
|
||||
router.get("/career/:careerId", jwtAuthMiddleware, getCandidatesByCareer);
|
||||
|
||||
router.patch("/:id", jwtAuthMiddleware, updateCandidate);
|
||||
router.delete("/:id", jwtAuthMiddleware, deleteCandidate);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -10,8 +10,8 @@ const router = express.Router();
|
||||
|
||||
router.get("/getAll", getAllCareers);
|
||||
|
||||
router.post("/", createCareer);
|
||||
router.patch("/:id", updateCareer);
|
||||
router.delete("/:id", deleteCareer);
|
||||
router.post("/", jwtAuthMiddleware, createCareer);
|
||||
router.patch("/:id", jwtAuthMiddleware, updateCareer);
|
||||
router.delete("/:id", jwtAuthMiddleware, deleteCareer);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import express from "express";
|
||||
import {
|
||||
getAllDepartments,
|
||||
getDepartmentByName,
|
||||
createDepartment,
|
||||
updateDepartment,
|
||||
deleteDepartment,
|
||||
@@ -11,6 +12,7 @@ const router = express.Router();
|
||||
|
||||
// Public
|
||||
router.get("/getAll", getAllDepartments);
|
||||
router.get("/search", getDepartmentByName);
|
||||
|
||||
// Protected
|
||||
router.post("/", jwtAuthMiddleware, createDepartment);
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
getDoctorTimings,
|
||||
getDoctorTimingById,
|
||||
getDoctorByDoctorId,
|
||||
getDoctorsByDepartmentId,
|
||||
} from "../controllers/doctor.controller.js";
|
||||
|
||||
import jwtAuthMiddleware from "../middleware/auth.js";
|
||||
@@ -14,9 +15,10 @@ import jwtAuthMiddleware from "../middleware/auth.js";
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/getAll", getAllDoctors);
|
||||
router.get("/:doctorId", getDoctorByDoctorId);
|
||||
router.get("/search", getDoctorsByDepartmentId);
|
||||
router.get("/getTimings", getDoctorTimings);
|
||||
router.get("/getTimings/:doctorId", getDoctorTimingById);
|
||||
router.get("/:doctorId", getDoctorByDoctorId);
|
||||
|
||||
router.post("/", jwtAuthMiddleware, createDoctor);
|
||||
router.patch("/:doctorId", jwtAuthMiddleware, updateDoctor);
|
||||
|
||||
@@ -12,8 +12,8 @@ const router = express.Router();
|
||||
|
||||
router.post("/", createInquiry);
|
||||
|
||||
router.get("/getAll", getInquiries);
|
||||
router.get("/:id", getInquiry);
|
||||
router.get("/getAll", jwtAuthMiddleware, getInquiries);
|
||||
router.get("/:id", jwtAuthMiddleware, getInquiry);
|
||||
router.delete("/:id", jwtAuthMiddleware, deleteInquiry);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import express from "express";
|
||||
import {
|
||||
createNews,
|
||||
getAllNews,
|
||||
getNewsById,
|
||||
updateNews,
|
||||
deleteNews,
|
||||
} from "../controllers/newsMedia.controller.js";
|
||||
|
||||
import jwtAuthMiddleware from "../middleware/auth.js";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// PUBLIC ROUTES
|
||||
router.get("/getAll", getAllNews);
|
||||
router.get("/:id", getNewsById);
|
||||
|
||||
// PROTECTED ROUTES
|
||||
router.post("/", jwtAuthMiddleware, createNews);
|
||||
router.patch("/:id", jwtAuthMiddleware, updateNews);
|
||||
router.delete("/:id", jwtAuthMiddleware, deleteNews);
|
||||
|
||||
export default router;
|
||||
@@ -19,6 +19,7 @@ import CareerPage from "./pages/Career";
|
||||
import CandidatePage from "./pages/candidates";
|
||||
import InquiryPage from "./pages/inquiry";
|
||||
import AcademicsPage from "./pages/Academics";
|
||||
import NewsPage from "./pages/newsMedia";
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
@@ -42,6 +43,7 @@ export default function App() {
|
||||
<Route path="/candidate" element={<CandidatePage />} />
|
||||
<Route path="/inquiry" element={<InquiryPage />} />
|
||||
<Route path="/academics" element={<AcademicsPage />} />
|
||||
<Route path="/news" element={<NewsPage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import apiClient from "@/api/client";
|
||||
|
||||
export const getNewsApi = async (page = 1, limit = 10) => {
|
||||
const res = await apiClient.get(
|
||||
`/newsMedia/getAll?page=${page}&limit=${limit}`,
|
||||
);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const createNewsApi = async (data: any) => {
|
||||
const res = await apiClient.post("/newsMedia", data);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const updateNewsApi = async (id: number, data: any) => {
|
||||
const res = await apiClient.patch(`/newsMedia/${id}`, data);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const deleteNewsApi = async (id: number) => {
|
||||
const res = await apiClient.delete(`/newsMedia/${id}`);
|
||||
return res.data;
|
||||
};
|
||||
@@ -35,6 +35,10 @@ export default function Sidebar() {
|
||||
name: "Academics & Research",
|
||||
path: "/academics",
|
||||
},
|
||||
{
|
||||
name: "News & Media",
|
||||
path: "/news",
|
||||
},
|
||||
{
|
||||
name: "Email",
|
||||
path: "/email",
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
|
||||
import {Loader2, RefreshCw, Plus, Pencil, Trash} from "lucide-react";
|
||||
import { Loader2, RefreshCw, Plus, Pencil, Trash, Eye } from "lucide-react";
|
||||
|
||||
interface Department {
|
||||
departmentId: string;
|
||||
@@ -51,6 +51,9 @@ export default function DepartmentPage() {
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
const [editing, setEditing] = useState<Department | null>(null);
|
||||
|
||||
const [viewOpen, setViewOpen] = useState(false);
|
||||
const [viewData, setViewData] = useState<Department | null>(null);
|
||||
|
||||
const [searchText, setSearchText] = useState("");
|
||||
|
||||
const [form, setForm] = useState<Department>({
|
||||
@@ -85,32 +88,21 @@ export default function DepartmentPage() {
|
||||
fetchDepartments();
|
||||
}, [fetchDepartments]);
|
||||
|
||||
const filteredDepartments = departments.filter((dep) => {
|
||||
const text = searchText.toLowerCase();
|
||||
|
||||
return (
|
||||
dep.name.toLowerCase().includes(text) ||
|
||||
dep.departmentId.toLowerCase().includes(text) ||
|
||||
dep.para1.toLowerCase().includes(text) ||
|
||||
dep.para2.toLowerCase().includes(text) ||
|
||||
dep.para3.toLowerCase().includes(text) ||
|
||||
dep.facilities.toLowerCase().includes(text) ||
|
||||
dep.services.toLowerCase().includes(text)
|
||||
const filteredDepartments = departments.filter((dep) =>
|
||||
dep.name.toLowerCase().includes(searchText.toLowerCase()),
|
||||
);
|
||||
});
|
||||
|
||||
function handleChange(
|
||||
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
|
||||
) {
|
||||
setForm({
|
||||
...form,
|
||||
[e.target.name]: e.target.value,
|
||||
});
|
||||
function handleChange(e: any) {
|
||||
setForm({ ...form, [e.target.name]: e.target.value });
|
||||
}
|
||||
|
||||
function truncate(text: string, limit = 60) {
|
||||
if (!text) return "-";
|
||||
return text.length > limit ? text.substring(0, limit) + "..." : text;
|
||||
}
|
||||
|
||||
function openAdd() {
|
||||
setEditing(null);
|
||||
|
||||
setForm({
|
||||
departmentId: "",
|
||||
name: "",
|
||||
@@ -120,7 +112,6 @@ export default function DepartmentPage() {
|
||||
facilities: "",
|
||||
services: "",
|
||||
});
|
||||
|
||||
setOpenModal(true);
|
||||
}
|
||||
|
||||
@@ -130,6 +121,11 @@ export default function DepartmentPage() {
|
||||
setOpenModal(true);
|
||||
}
|
||||
|
||||
function openView(dep: Department) {
|
||||
setViewData(dep);
|
||||
setViewOpen(true);
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
if (editing) {
|
||||
@@ -146,12 +142,11 @@ export default function DepartmentPage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(departmentId: string) {
|
||||
const confirmDelete = confirm("Delete this department?");
|
||||
if (!confirmDelete) return;
|
||||
async function handleDelete(id: string) {
|
||||
if (!confirm("Delete this department?")) return;
|
||||
|
||||
try {
|
||||
await deleteDepartmentApi(departmentId);
|
||||
await deleteDepartmentApi(id);
|
||||
fetchDepartments();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -160,7 +155,6 @@ export default function DepartmentPage() {
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
{/* HEADER */}
|
||||
<div className="flex flex-col md:flex-row md:justify-between md:items-center gap-3">
|
||||
<h1 className="text-2xl font-bold">Departments</h1>
|
||||
|
||||
@@ -175,8 +169,7 @@ export default function DepartmentPage() {
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={fetchDepartments}
|
||||
disabled={loading}
|
||||
>
|
||||
disabled={loading}>
|
||||
<RefreshCw className="mr-2 h-4 w-4" />
|
||||
Refresh
|
||||
</Button>
|
||||
@@ -200,31 +193,29 @@ export default function DepartmentPage() {
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<div className="border rounded-md overflow-x-auto max-w-full">
|
||||
<Table>
|
||||
<div className="border rounded-md max-h-[500px] overflow-y-auto">
|
||||
<Table className="w-full table-fixed">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>ID</TableHead>
|
||||
<TableHead>Name</TableHead>
|
||||
<TableHead>Para1</TableHead>
|
||||
<TableHead>Para2</TableHead>
|
||||
<TableHead>Para3</TableHead>
|
||||
<TableHead>Facilities</TableHead>
|
||||
<TableHead>Services</TableHead>
|
||||
<TableHead>Actions</TableHead>
|
||||
<TableHead className="w-[80px]">ID</TableHead>
|
||||
<TableHead className="w-[180px]">Name</TableHead>
|
||||
<TableHead className="w-[250px]">Para1</TableHead>
|
||||
<TableHead className="w-[220px]">Facilities</TableHead>
|
||||
<TableHead className="w-[220px]">Services</TableHead>
|
||||
<TableHead className="w-[120px]">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{loading ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={8} className="text-center">
|
||||
<TableCell colSpan={6} className="text-center">
|
||||
<Loader2 className="h-6 w-6 animate-spin mx-auto" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : filteredDepartments.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={8} className="text-center">
|
||||
<TableCell colSpan={6} className="text-center">
|
||||
No departments found
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -233,42 +224,47 @@ export default function DepartmentPage() {
|
||||
<TableRow key={dep.departmentId}>
|
||||
<TableCell>{dep.departmentId}</TableCell>
|
||||
|
||||
<TableCell>{dep.name}</TableCell>
|
||||
|
||||
<TableCell className="max-w-[300px] whitespace-normal break-words">
|
||||
{dep.para1}
|
||||
<TableCell>
|
||||
<div className="break-words">{dep.name}</div>
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="max-w-[300px] whitespace-normal break-words">
|
||||
{dep.para2}
|
||||
<TableCell>
|
||||
<div className="break-words whitespace-normal">
|
||||
{truncate(dep.para1)}
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="max-w-[300px] whitespace-normal break-words">
|
||||
{dep.para3}
|
||||
<TableCell>
|
||||
<div className="break-words whitespace-normal">
|
||||
{truncate(dep.facilities)}
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="max-w-[300px] whitespace-normal break-words">
|
||||
{dep.facilities}
|
||||
<TableCell>
|
||||
<div className="break-words whitespace-normal">
|
||||
{truncate(dep.services)}
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="max-w-[300px] whitespace-normal break-words">
|
||||
{dep.services}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="flex gap-2">
|
||||
<TableCell className="flex gap-2 whitespace-nowrap">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => openEdit(dep)}
|
||||
>
|
||||
onClick={() => openView(dep)}>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => openEdit(dep)}>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() => handleDelete(dep.departmentId)}
|
||||
>
|
||||
onClick={() => handleDelete(dep.departmentId)}>
|
||||
<Trash className="h-4 w-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
@@ -281,64 +277,59 @@ export default function DepartmentPage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* MODAL */}
|
||||
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
||||
<DialogContent className="max-w-4xl">
|
||||
<DialogContent className="w-full !max-w-5xl max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{editing ? "Edit Department" : "Add Department"}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4 max-h-[70vh] overflow-y-auto pr-2">
|
||||
<div className="space-y-4">
|
||||
<Input
|
||||
name="departmentId"
|
||||
placeholder="Department ID"
|
||||
value={form.departmentId}
|
||||
onChange={handleChange}
|
||||
disabled={!!editing}
|
||||
placeholder="Department ID"
|
||||
/>
|
||||
|
||||
<Input
|
||||
name="name"
|
||||
placeholder="Department Name"
|
||||
value={form.name}
|
||||
onChange={handleChange}
|
||||
placeholder="Department Name"
|
||||
/>
|
||||
|
||||
<Textarea
|
||||
name="para1"
|
||||
placeholder="Paragraph 1"
|
||||
value={form.para1}
|
||||
onChange={handleChange}
|
||||
placeholder="Para1"
|
||||
/>
|
||||
|
||||
<Textarea
|
||||
name="para2"
|
||||
placeholder="Paragraph 2"
|
||||
value={form.para2}
|
||||
onChange={handleChange}
|
||||
placeholder="Para2"
|
||||
/>
|
||||
|
||||
<Textarea
|
||||
name="para3"
|
||||
placeholder="Paragraph 3"
|
||||
value={form.para3}
|
||||
onChange={handleChange}
|
||||
placeholder="Para3"
|
||||
/>
|
||||
|
||||
<Textarea
|
||||
name="facilities"
|
||||
placeholder="Facilities"
|
||||
value={form.facilities}
|
||||
onChange={handleChange}
|
||||
placeholder="Facilities"
|
||||
/>
|
||||
|
||||
<Textarea
|
||||
name="services"
|
||||
placeholder="Services"
|
||||
value={form.services}
|
||||
onChange={handleChange}
|
||||
placeholder="Services"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -346,13 +337,65 @@ export default function DepartmentPage() {
|
||||
<Button variant="outline" onClick={() => setOpenModal(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
|
||||
<Button onClick={handleSubmit}>
|
||||
{editing ? "Update" : "Create"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
||||
<DialogContent className="w-full !max-w-5xl max-h-[90vh] overflow-y-auto">
|
||||
{" "}
|
||||
<DialogHeader>
|
||||
<DialogTitle>Department Details</DialogTitle>
|
||||
</DialogHeader>
|
||||
{viewData && (
|
||||
<div className="space-y-4 text-sm">
|
||||
<p>
|
||||
<b>ID:</b> {viewData.departmentId}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Name:</b> {viewData.name}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Para1:</b>
|
||||
<br />
|
||||
{viewData.para1}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Para2:</b>
|
||||
<br />
|
||||
{viewData.para2}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Para3:</b>
|
||||
<br />
|
||||
{viewData.para3}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Facilities:</b>
|
||||
<br />
|
||||
{viewData.facilities}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Services:</b>
|
||||
<br />
|
||||
{viewData.services}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<DialogFooter>
|
||||
<Button onClick={() => setViewOpen(false)}>Close</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
|
||||
import {
|
||||
getNewsApi,
|
||||
createNewsApi,
|
||||
updateNewsApi,
|
||||
deleteNewsApi,
|
||||
} from "@/api/newsMedia";
|
||||
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
} from "@/components/ui/dialog";
|
||||
|
||||
import {
|
||||
Loader2,
|
||||
Plus,
|
||||
Pencil,
|
||||
Trash,
|
||||
RefreshCw,
|
||||
Eye,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
} from "lucide-react";
|
||||
|
||||
export default function NewsPage() {
|
||||
const [news, setNews] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const [searchText, setSearchText] = useState("");
|
||||
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
const [editing, setEditing] = useState<any>(null);
|
||||
|
||||
const [viewOpen, setViewOpen] = useState(false);
|
||||
const [viewData, setViewData] = useState<any>(null);
|
||||
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [itemsPerPage, setItemsPerPage] = useState(10);
|
||||
|
||||
const [form, setForm] = useState({
|
||||
headline: "",
|
||||
content: "",
|
||||
firstPara: "",
|
||||
secondPara: "",
|
||||
date: "",
|
||||
author: "",
|
||||
});
|
||||
|
||||
const fetchAll = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await getNewsApi();
|
||||
setNews(res?.data || []);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchAll();
|
||||
}, [fetchAll]);
|
||||
|
||||
const filteredNews = news.filter((item) =>
|
||||
item.Headline?.toLowerCase().includes(searchText.toLowerCase()),
|
||||
);
|
||||
|
||||
const totalPages = Math.ceil(filteredNews.length / itemsPerPage);
|
||||
const startIndex = (currentPage - 1) * itemsPerPage;
|
||||
const paginatedData = filteredNews.slice(
|
||||
startIndex,
|
||||
startIndex + itemsPerPage,
|
||||
);
|
||||
|
||||
function handleChange(e: any) {
|
||||
setForm({ ...form, [e.target.name]: e.target.value });
|
||||
}
|
||||
|
||||
function openAdd() {
|
||||
setEditing(null);
|
||||
setForm({
|
||||
headline: "",
|
||||
content: "",
|
||||
firstPara: "",
|
||||
secondPara: "",
|
||||
date: "",
|
||||
author: "",
|
||||
});
|
||||
setOpenModal(true);
|
||||
}
|
||||
|
||||
function openEdit(item: any) {
|
||||
setEditing(item);
|
||||
|
||||
setForm({
|
||||
headline: item.Headline || "",
|
||||
content: item.Content || "",
|
||||
firstPara: item.FirstPara || "",
|
||||
secondPara: item.SecondPara || "",
|
||||
date: item.Date ? item.Date.split("T")[0] : "",
|
||||
author: item.Author || "",
|
||||
});
|
||||
|
||||
setOpenModal(true);
|
||||
}
|
||||
|
||||
function openView(item: any) {
|
||||
setViewData(item);
|
||||
setViewOpen(true);
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
if (editing) {
|
||||
await updateNewsApi(editing.Id, form);
|
||||
} else {
|
||||
await createNewsApi(form);
|
||||
}
|
||||
setOpenModal(false);
|
||||
fetchAll();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(id: number) {
|
||||
if (!confirm("Delete news?")) return;
|
||||
await deleteNewsApi(id);
|
||||
fetchAll();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
<div className="flex justify-between items-center flex-wrap gap-3">
|
||||
<h1 className="text-2xl font-bold">News Media</h1>
|
||||
|
||||
<div className="flex gap-2 flex-wrap items-center">
|
||||
<Input
|
||||
placeholder="Search headline..."
|
||||
value={searchText}
|
||||
onChange={(e) => {
|
||||
setSearchText(e.target.value);
|
||||
setCurrentPage(1);
|
||||
}}
|
||||
className="w-[250px]"
|
||||
/>
|
||||
|
||||
<select
|
||||
value={itemsPerPage}
|
||||
onChange={(e) => {
|
||||
setItemsPerPage(Number(e.target.value));
|
||||
setCurrentPage(1);
|
||||
}}
|
||||
className="border px-2 py-1 rounded">
|
||||
<option value={5}>5 / page</option>
|
||||
<option value={10}>10 / page</option>
|
||||
<option value={20}>20 / page</option>
|
||||
</select>
|
||||
|
||||
<Button variant="outline" onClick={fetchAll} disabled={loading}>
|
||||
<RefreshCw className="mr-2 h-4 w-4" />
|
||||
Refresh
|
||||
</Button>
|
||||
|
||||
<Button onClick={openAdd}>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Add News
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>News List</CardTitle>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto">
|
||||
<Table className="min-w-[900px] table-fixed">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[60px]">ID</TableHead>
|
||||
<TableHead className="w-[220px]">Headline</TableHead>
|
||||
<TableHead className="w-[120px]">Author</TableHead>
|
||||
<TableHead className="w-[120px]">Date</TableHead>
|
||||
<TableHead className="w-[260px]">Content</TableHead>
|
||||
<TableHead className="w-[150px]">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{loading ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center">
|
||||
<Loader2 className="animate-spin mx-auto" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : paginatedData.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center">
|
||||
No news found
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
paginatedData.map((item) => (
|
||||
<TableRow key={item.Id}>
|
||||
<TableCell>{item.Id}</TableCell>
|
||||
|
||||
<TableCell className="break-words whitespace-normal">
|
||||
{item.Headline}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>{item.Author}</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{item.Date
|
||||
? new Date(item.Date).toLocaleDateString()
|
||||
: "-"}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="break-words whitespace-normal">
|
||||
{item.Content}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="flex gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => openView(item)}>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => openEdit(item)}>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() => handleDelete(Number(item.Id))}>
|
||||
<Trash className="h-4 w-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
{/* PAGINATION */}
|
||||
<div className="flex justify-between items-center mt-4">
|
||||
<p className="text-sm">
|
||||
Page {currentPage} of {totalPages}
|
||||
</p>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={currentPage === 1}
|
||||
onClick={() => setCurrentPage((p) => p - 1)}>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={currentPage === totalPages}
|
||||
onClick={() => setCurrentPage((p) => p + 1)}>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* CREATE / EDIT MODAL */}
|
||||
<Dialog open={openModal} onOpenChange={setOpenModal}>
|
||||
<DialogContent className="w-[95vw] max-w-none max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editing ? "Edit News" : "Add News"}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
name="headline"
|
||||
placeholder="Headline"
|
||||
value={form.headline}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
<Input
|
||||
name="author"
|
||||
placeholder="Author"
|
||||
value={form.author}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
<Input
|
||||
type="date"
|
||||
name="date"
|
||||
value={form.date}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
|
||||
<textarea
|
||||
name="firstPara"
|
||||
placeholder="First Paragraph"
|
||||
value={form.firstPara}
|
||||
onChange={handleChange}
|
||||
className="border rounded p-2 w-full min-h-[100px]"
|
||||
/>
|
||||
<textarea
|
||||
name="secondPara"
|
||||
placeholder="Second Paragraph"
|
||||
value={form.secondPara}
|
||||
onChange={handleChange}
|
||||
className="border rounded p-2 w-full min-h-[100px]"
|
||||
/>
|
||||
<textarea
|
||||
name="content"
|
||||
placeholder="Content"
|
||||
value={form.content}
|
||||
onChange={handleChange}
|
||||
className="border rounded p-2 w-full min-h-[150px]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setOpenModal(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleSubmit}>
|
||||
{editing ? "Update" : "Create"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* VIEW MODAL */}
|
||||
<Dialog open={viewOpen} onOpenChange={setViewOpen}>
|
||||
<DialogContent className="w-[95vw] max-w-none max-h-[90vh] overflow-y-auto p-6">
|
||||
<DialogHeader>
|
||||
<DialogTitle>News Details</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{viewData && (
|
||||
<div className="space-y-4 text-sm">
|
||||
<b>Headline:</b>
|
||||
<p>{viewData.Headline}</p>
|
||||
|
||||
<b>Author:</b>
|
||||
<p>{viewData.Author}</p>
|
||||
|
||||
<b>Date:</b>
|
||||
<p>
|
||||
{viewData.Date
|
||||
? new Date(viewData.Date).toLocaleDateString()
|
||||
: "-"}
|
||||
</p>
|
||||
|
||||
<b>First Para:</b>
|
||||
<p className="whitespace-pre-line">{viewData.FirstPara}</p>
|
||||
|
||||
<b>Second Para:</b>
|
||||
<p className="whitespace-pre-line">{viewData.SecondPara}</p>
|
||||
|
||||
<b>Content:</b>
|
||||
<p className="whitespace-pre-line">{viewData.Content}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<DialogFooter>
|
||||
<Button onClick={() => setViewOpen(false)}>Close</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user