Hello, I was adding some custom action components to a record, namely "approve" and "reject" to approve or reject a member.
My issues are:
- Issues in the upload components:
Error: Component "UploadShowComponent" has not been bundled, ensure it was added to your ComponentLoader instance (the one included in AdminJS options).
(and errors like this in the edit and list as well)
But when I remove the action components, i.e. not add the custom action components, then upload components work fine without any error.
- Issues in the action components:
The error says:
You have to implement action component for your Action
But I have implemented action component exactly like what is shown in the documents.
( I used path.resolve because without using it it was showing 'file doesn't exist' in windows due to extra slashes at the beginning so I had to convert the path to absolute )
No errors were shown during bundling files.
Here's the admin options:
import News from "./resources/news.resource.js";
import Notice from "./resources/notice.resource.js";
import Download from "./resources/download.resource.js";
import About from "./resources/about.resource.js";
import Team from "./resources/team.resource.js";
import Member from "./resources/member.resource.js";
import { componentLoader } from "./component-loader.js";
const adminOptions = {
resources: [News, Notice, Download, About, Team, Member],
componentLoader: componentLoader,
logoutPath: "/admin/logout",
rootPath: "/admin",
};
export default adminOptions;
Here's the index.js:
import express from "express";
import mongoose from "mongoose";
import dotenv from "dotenv";
import authRoutes from "./routes/auth.route.js";
import newsRoutes from "./routes/news.route.js";
import noticeRoutes from "./routes/notice.route.js";
import downloadRoutes from "./routes/download.route.js";
import aboutRoutes from "./routes/about.route.js";
import teamRoutes from "./routes/team.route.js";
import memberRoutes from "./routes/member.route.js";
import AdminJS from "adminjs";
import AdminJSExpress from "@adminjs/express";
import * as AdminJSMongoose from "@adminjs/mongoose";
import Connect from "connect-mongodb-session";
import session from "express-session";
import User from "./models/user.model.js";
import path from "path";
import bcryptjs from "bcryptjs";
import adminOptions from "./admin.options.js";
import * as url from "url";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
dotenv.config();
var database;
mongoose
.connect(process.env.MONGO_URI)
.then((x) => {
database = x;
console.log("Connected to MongoDB");
})
.catch((error) => {
console.error("Error connecting to MongoDB: ", error);
});
const ADMIN_USER = await User.findOne({ type: "admin" });
const authenticate = async (email, password) => {
if (
email === ADMIN_USER.username &&
bcryptjs.compareSync(password, ADMIN_USER.password)
) {
return Promise.resolve(ADMIN_USER);
}
return null;
};
AdminJS.registerAdapter({
Resource: AdminJSMongoose.Resource,
Database: AdminJSMongoose.Database,
});
const start = async () => {
const app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, "../client/public")));
app.use(express.static(path.join(__dirname, "../members")));
const admin = new AdminJS(adminOptions);
const ConnectSession = Connect(session);
const sessionStore = new ConnectSession({
uri: process.env.MONGO_URI,
collection: "sessions",
});
const adminRouter = AdminJSExpress.buildAuthenticatedRouter(
admin,
{
authenticate,
cookieName: "adminjs",
cookiePassword: process.env.SESSION_SECRET,
},
null,
{
store: sessionStore,
resave: true,
saveUninitialized: true,
secret: process.env.SESSION_SECRET,
cookie: {
httpOnly: process.env.NODE_ENV === "production",
secure: process.env.NODE_ENV === "production",
},
name: "adminjs",
}
);
app.use(admin.options.rootPath, adminRouter);
admin.watch();
app.listen(3000, () => {
console.log("Server is running on http://localhost:3000");
console.log(
`AdminJS started on http://localhost:3000${admin.options.rootPath}`
);
});
app.use("/api/auth", authRoutes);
app.use("/api/news", newsRoutes);
app.use("/api/notices", noticeRoutes);
app.use("/api/downloads", downloadRoutes);
app.use("/api/abouts", aboutRoutes);
app.use("/api/teams", teamRoutes);
app.use("/api/members", memberRoutes);
app.get("/", (req, res) => {
res.send("Go to /admin for adminpanel");
});
app.use((err, req, res, next) => {
const statusCode = err.statusCode || 500;
const message = err.message || "Internal Server Error";
res.status(statusCode).json({
success: false,
statusCode,
message,
});
});
};
start();
below is the code for member.resource where I tried to implement custom actions:
I solved it, just by writing the components in tsx instead of jsx. However, the documentation said that it also supports .jsx components but it didn't work out for me.
Hello, I was adding some custom action components to a record, namely "approve" and "reject" to approve or reject a member.
My issues are: - Issues in the upload components: Error: Component "UploadShowComponent" has not been bundled, ensure it was added to your ComponentLoader instance (the one included in AdminJS options).
(and errors like this in the edit and list as well)
But when I remove the action components, i.e. not add the custom action components, then upload components work fine without any error.
- Issues in the action components: The error says: You have to implement action component for your Action But I have implemented action component exactly like what is shown in the documents.
Given below are my code blocks:
Here's the component loader:
( I used path.resolve because without using it it was showing 'file doesn't exist' in windows due to extra slashes at the beginning so I had to convert the path to absolute )
No errors were shown during bundling files.
Here's the admin options:
Here's the index.js:
below is the code for member.resource where I tried to implement custom actions:
below is the code for ApproveMember:
and given below is the code for RejectMember:
Any help would be highly appreciated.