sarlink-portal/actions/user-actions.ts
i701 0a63e4337e Enhance user management and payment processing features
- Updated `package.json` to include a new script for launching Prisma Studio.
- Modified `signup` function in `auth-actions.ts` to include account number in user data.
- Refactored `createPayment` function in `payment.ts` to improve error handling and return structured responses.
- Updated UI components in the dashboard to improve layout and responsiveness, including changes to `UserDevices` and `UserPayments` pages.
- Introduced new `AdminDevicesTable` and `UsersPaymentsTable` components for better admin functionalities.
- Enhanced `DeviceCartDrawer` to provide user feedback during payment processing.
- Added account number input to the signup form and updated validation schema accordingly.
- Updated Prisma schema to include a new `ninja_user_id` field for user management.

These changes improve the overall functionality, maintainability, and user experience of the application, particularly in user management and payment processing.
2025-01-06 12:49:13 +05:00

115 lines
2.3 KiB
TypeScript

"use server";
import prisma from "@/lib/db";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { CreateClient } from "./ninja/client";
export async function VerifyUser(userId: string) {
const user = await prisma.user.findUnique({
where: {
id: userId,
},
include: {
atoll: true,
island: true,
},
});
if (!user) {
throw new Error("User not found");
}
await prisma.user.update({
where: {
id: userId,
},
data: {
verified: true,
},
});
const ninjaClient = await CreateClient({
group_settings_id: "",
address1: "",
city: user.atoll?.name || "",
state: user.island?.name || "",
postal_code: "",
country_id: "462",
address2: user.address || "",
contacts: {
first_name: user.name?.split(" ")[0] || "",
last_name: user.name?.split(" ")[1] || "",
email: user.email || "",
phone: user.phoneNumber || "",
send_email: false,
custom_value1: user.dob?.toISOString().split("T")[0] || "",
custom_value2: user.id_card || "",
custom_value3: "",
},
});
revalidatePath("/users");
}
export async function Rejectuser({
userId,
reason,
}: { userId: string; reason: string }) {
const user = await prisma.user.findUnique({
where: {
id: userId,
},
});
if (!user) {
throw new Error("User not found");
}
await prisma.user.delete({
where: {
id: userId,
},
});
await SendUserRejectionDetailSMS({
details: reason,
phoneNumber: user.phoneNumber,
});
revalidatePath("/users");
redirect("/users");
}
export const SendUserRejectionDetailSMS = async ({
details,
phoneNumber,
}: {
details: string;
phoneNumber: string;
}) => {
const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.SMS_API_KEY}`,
},
body: JSON.stringify({
check_delivery: false,
number: phoneNumber,
message: details,
}),
});
const data = await respose.json();
console.log(data);
return data;
};
export async function AddDevice({
name,
mac_address,
user_id,
}: { name: string; mac_address: string; user_id: string }) {
const newDevice = await prisma.device.create({
data: {
name: name,
mac: mac_address,
userId: user_id,
},
});
revalidatePath("/devices");
return newDevice;
}