Fixing build errors

This commit is contained in:
Mitchell Magro 2025-08-06 12:04:47 +02:00
parent 6c68ca79e3
commit 85be86d736
3 changed files with 60 additions and 20 deletions

View File

@ -1,4 +1,32 @@
export const users = [
// mockData.ts
export type User = {
merchantId: number;
id: string;
name?: string;
username?: string;
firstName?: string;
lastName?: string;
email?: string;
phone?: string;
jobTitle?: string;
enabled?: boolean;
authorities?: string[];
allowedMerchantIds?: number[];
created?: string;
disabledBy?: string | null;
disabledDate?: string | null;
disabledReason?: string | null;
incidentNotes?: boolean;
lastLogin?: string;
lastMandatoryUpdated?: string;
marketingNewsletter?: boolean;
releaseNotes?: boolean;
requiredActions?: string[];
twoFactorCondition?: string;
twoFactorCredentials?: unknown[]; // narrow if you know the shape
};
export const users: User[] = [
{
merchantId: 100987998,
id: "bc6a8a55-13bc-4538-8255-cd0cec3bb4e9",

View File

@ -1,34 +1,46 @@
import { NextRequest, NextResponse } from "next/server";
import { users } from "../../mockData";
import { users, type User } from "../../mockData"; // adjust relative path
type UpdateUserBody = Partial<{
firstName: string;
lastName: string;
email: string;
phone: string;
role: string;
}>;
export async function PUT(
request: NextRequest,
{ params }: { params: { id: string } }
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = params;
const { id } = await params;
if (!id) {
return NextResponse.json({ error: "User ID is required" }, { status: 400 });
let body: unknown;
try {
body = await request.json();
} catch {
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
}
const body = await request.json();
const { firstName, lastName, email, phone, role } = body;
const { firstName, lastName, email, phone, role } = body as UpdateUserBody;
// Find the user by id
const userIndex = users.findIndex((u) => u.id === id);
const userIndex = users.findIndex((u: User) => u.id === id);
if (userIndex === -1) {
return NextResponse.json({ error: "User not found" }, { status: 404 });
}
// Update the user fields
users[userIndex] = {
...users[userIndex],
firstName: firstName ?? users[userIndex].firstName,
lastName: lastName ?? users[userIndex].lastName,
email: email ?? users[userIndex].email,
phone: phone ?? users[userIndex].phone,
authorities: role ? [role] : users[userIndex].authorities,
const existingUser = users[userIndex];
const updatedUser: User = {
...existingUser,
firstName: firstName ?? existingUser.firstName,
lastName: lastName ?? existingUser.lastName,
email: email ?? existingUser.email,
phone: phone ?? existingUser.phone,
authorities: role ? [role] : existingUser.authorities ?? [],
};
return NextResponse.json(users[userIndex], { status: 200 });
users[userIndex] = updatedUser;
return NextResponse.json(updatedUser, { status: 200 });
}

View File

@ -1,7 +1,7 @@
import React from "react";
import { useRouter } from "next/navigation";
import { IEditUserForm, EditUserField } from "../User.interfaces";
import { addUser, editUser } from "@/services/roles.services";
import { editUser } from "@/services/roles.services";
import { IUser } from "../../Pages/Admin/Users/interfaces";
import "./EditUser.scss";