Fixing build errors
This commit is contained in:
parent
6c68ca79e3
commit
85be86d736
@ -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,
|
merchantId: 100987998,
|
||||||
id: "bc6a8a55-13bc-4538-8255-cd0cec3bb4e9",
|
id: "bc6a8a55-13bc-4538-8255-cd0cec3bb4e9",
|
||||||
|
|||||||
@ -1,34 +1,46 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
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(
|
export async function PUT(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
const { id } = params;
|
const { id } = await params;
|
||||||
|
|
||||||
if (!id) {
|
let body: unknown;
|
||||||
return NextResponse.json({ error: "User ID is required" }, { status: 400 });
|
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 as UpdateUserBody;
|
||||||
const { firstName, lastName, email, phone, role } = body;
|
|
||||||
|
|
||||||
// Find the user by id
|
const userIndex = users.findIndex((u: User) => u.id === id);
|
||||||
const userIndex = users.findIndex((u) => u.id === id);
|
|
||||||
if (userIndex === -1) {
|
if (userIndex === -1) {
|
||||||
return NextResponse.json({ error: "User not found" }, { status: 404 });
|
return NextResponse.json({ error: "User not found" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the user fields
|
const existingUser = users[userIndex];
|
||||||
users[userIndex] = {
|
|
||||||
...users[userIndex],
|
const updatedUser: User = {
|
||||||
firstName: firstName ?? users[userIndex].firstName,
|
...existingUser,
|
||||||
lastName: lastName ?? users[userIndex].lastName,
|
firstName: firstName ?? existingUser.firstName,
|
||||||
email: email ?? users[userIndex].email,
|
lastName: lastName ?? existingUser.lastName,
|
||||||
phone: phone ?? users[userIndex].phone,
|
email: email ?? existingUser.email,
|
||||||
authorities: role ? [role] : users[userIndex].authorities,
|
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 });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { IEditUserForm, EditUserField } from "../User.interfaces";
|
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 { IUser } from "../../Pages/Admin/Users/interfaces";
|
||||||
import "./EditUser.scss";
|
import "./EditUser.scss";
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user