Skip to content

Commit

Permalink
fix page router form parse
Browse files Browse the repository at this point in the history
  • Loading branch information
foyarash committed Feb 5, 2025
1 parent b1fe397 commit 69a1607
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/next-admin/src/pageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const createHandler = <P extends string = "nextadmin">({
});

if (!deleted) {
throw new Error("Deletion failed")
throw new Error("Deletion failed");
}

return res.json({ ok: true });
Expand Down
12 changes: 11 additions & 1 deletion packages/next-admin/src/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,18 @@ export const getFormDataValues = async (req: IncomingMessage) => {
if (err) {
reject(err);
}

resolve({
...(fields as Record<string, any>),
...Object.entries(fields).reduce(
(acc, [key, value]) => {
if (Array.isArray(value)) {
acc[key] = value[0];
}

return acc;
},
{} as Record<string, string>
),
...Object.entries(files).reduce((acc, [key, value]) => {
if (key in fields && Array.isArray(fields[key])) {
acc[key] = [...fields[key], ...value];
Expand Down

0 comments on commit 69a1607

Please sign in to comment.