mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 09:48:22 +00:00
Refactor user actions and authentication components
- Updated user verification logic to include atoll and island relationships. - Introduced CreateClient function for integrating with external client API. - Replaced 'house_name' with 'address' in user signup data handling. - Added new Checkbox component for improved UI interactions. - Migrated database provider from SQLite to PostgreSQL and redefined user schema. - Removed obsolete migration files and ensured database integrity with new structure.
This commit is contained in:
@ -3,10 +3,10 @@
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import prisma from "@/lib/db";
|
||||
import { signUpFormSchema } from "@/lib/schemas";
|
||||
import { headers } from "next/headers";
|
||||
// import type { User } from "@prisma/client";
|
||||
import { redirect } from "next/navigation";
|
||||
import { z } from "zod";
|
||||
import { headers } from "next/headers";
|
||||
const formSchema = z.object({
|
||||
phoneNumber: z
|
||||
.string()
|
||||
@ -112,7 +112,7 @@ export async function signup(_actionState: ActionState, formData: FormData) {
|
||||
name: parsedData.data.name,
|
||||
islandId: parsedData.data.island_id,
|
||||
atollId: parsedData.data.atoll_id,
|
||||
house_name: parsedData.data.house_name,
|
||||
address: parsedData.data.address,
|
||||
id_card: parsedData.data.id_card,
|
||||
dob: new Date(parsedData.data.dob),
|
||||
role: "USER",
|
||||
|
89
actions/ninja/client.ts
Normal file
89
actions/ninja/client.ts
Normal file
@ -0,0 +1,89 @@
|
||||
"use server";
|
||||
// const raw = {
|
||||
// group_settings_id: "",
|
||||
// address1: "",
|
||||
// city: "F",
|
||||
// state: "Dharanboodhoo",
|
||||
// postal_code: "12040",
|
||||
// country_id: "462",
|
||||
// address2: "Skyvilla",
|
||||
// contacts: [
|
||||
// {
|
||||
// first_name: "Abdulla",
|
||||
// last_name: "Aidhaan",
|
||||
// email: "",
|
||||
// phone: "778-0588",
|
||||
// send_email: false,
|
||||
// custom_value1: "1971-02-24",
|
||||
// custom_value2: "A265117",
|
||||
// custom_value3: "",
|
||||
// },
|
||||
// ],
|
||||
// };
|
||||
|
||||
type CreateClientProps = {
|
||||
group_settings_id: string;
|
||||
address1: string;
|
||||
city: string;
|
||||
state: string;
|
||||
postal_code: string;
|
||||
country_id: string;
|
||||
address2: string;
|
||||
contacts: Contact;
|
||||
};
|
||||
|
||||
type Contact = {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
send_email: boolean;
|
||||
custom_value1: string;
|
||||
custom_value2: string;
|
||||
custom_value3: string;
|
||||
};
|
||||
export async function CreateClient({
|
||||
group_settings_id = "",
|
||||
address1 = "",
|
||||
city,
|
||||
state,
|
||||
postal_code = "",
|
||||
country_id = "462",
|
||||
address2,
|
||||
contacts,
|
||||
}: CreateClientProps) {
|
||||
const response = await fetch(
|
||||
"https://finance-staging.baraveli.dev/api/v1/clients",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-token": `${process.env.NINJA_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
group_settings_id,
|
||||
address1,
|
||||
city,
|
||||
state,
|
||||
postal_code,
|
||||
country_id,
|
||||
address2,
|
||||
contacts: [
|
||||
{
|
||||
first_name: contacts.first_name,
|
||||
last_name: contacts.last_name,
|
||||
email: contacts.email || "",
|
||||
phone: contacts.phone,
|
||||
send_email: contacts.send_email,
|
||||
custom_value1: contacts.custom_value1,
|
||||
custom_value2: contacts.custom_value2,
|
||||
custom_value3: contacts.custom_value3 || "",
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
);
|
||||
const data = await response.json();
|
||||
console.log(data.data.contacts);
|
||||
return data;
|
||||
}
|
@ -2,17 +2,21 @@
|
||||
|
||||
import prisma from "@/lib/db";
|
||||
import { revalidatePath } from "next/cache";
|
||||
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");
|
||||
}
|
||||
user.verified = true;
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: userId,
|
||||
@ -21,5 +25,24 @@ export async function VerifyUser(userId: string) {
|
||||
verified: true,
|
||||
},
|
||||
});
|
||||
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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user