mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-04-20 03:50:20 +00:00
feat: update signup and OTP verification forms to enhance error handling and state management
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m16s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m16s
This commit is contained in:
parent
470e8452b5
commit
1e023ebf13
@ -77,9 +77,25 @@ export async function signin(previousState: ActionState, formData: FormData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ActionState = {
|
export type ActionState = {
|
||||||
message: string;
|
status?: string;
|
||||||
status: string;
|
|
||||||
payload?: FormData;
|
payload?: FormData;
|
||||||
|
errors?: z.typeToFlattenedError<
|
||||||
|
{
|
||||||
|
id_card: string;
|
||||||
|
phone_number: string;
|
||||||
|
name: string;
|
||||||
|
atoll_id: string;
|
||||||
|
island_id: string;
|
||||||
|
address: string;
|
||||||
|
dob: Date;
|
||||||
|
terms: string;
|
||||||
|
policy: string;
|
||||||
|
accNo: string;
|
||||||
|
},
|
||||||
|
string
|
||||||
|
>;
|
||||||
|
db_error?: string;
|
||||||
|
error?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function signup(_actionState: ActionState, formData: FormData) {
|
export async function signup(_actionState: ActionState, formData: FormData) {
|
||||||
@ -119,11 +135,12 @@ export async function signup(_actionState: ActionState, formData: FormData) {
|
|||||||
db_error: "phone_number",
|
db_error: "phone_number",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const [signupError, signupResponse] = await tryCatch(
|
const [signupError, signupResponse] = await tryCatch(
|
||||||
backendRegister({
|
backendRegister({
|
||||||
payload: {
|
payload: {
|
||||||
firstname: parsedData.data.name,
|
firstname: parsedData.data.name.split(" ")[0],
|
||||||
lastname: parsedData.data.name,
|
lastname: parsedData.data.name.split(" ")[1],
|
||||||
username: parsedData.data.phone_number,
|
username: parsedData.data.phone_number,
|
||||||
address: parsedData.data.address,
|
address: parsedData.data.address,
|
||||||
id_card: parsedData.data.id_card,
|
id_card: parsedData.data.id_card,
|
||||||
@ -141,39 +158,11 @@ export async function signup(_actionState: ActionState, formData: FormData) {
|
|||||||
throw new Error(signupError.message);
|
throw new Error(signupError.message);
|
||||||
}
|
}
|
||||||
console.log("SIGNUP RESPONSE", signupResponse);
|
console.log("SIGNUP RESPONSE", signupResponse);
|
||||||
// if (!isValidPerson) {
|
|
||||||
// await SendUserRejectionDetailSMS({
|
|
||||||
// details: `
|
|
||||||
// A new user has requested for verification. \n
|
|
||||||
// USER DETAILS:
|
|
||||||
// Name: ${parsedData.data.name}
|
|
||||||
// Address: ${parsedData.data.address}
|
|
||||||
// ID Card: ${parsedData.data.id_card}
|
|
||||||
// DOB: ${parsedData.data.dob.toLocaleDateString("en-US", {
|
|
||||||
// month: "short",
|
|
||||||
// day: "2-digit",
|
|
||||||
// year: "numeric",
|
|
||||||
// })}
|
|
||||||
// ACC No: ${parsedData.data.accNo}\n\nVerify the user with the following link: ${process.env.BETTER_AUTH_URL}/users/${newUser.id}/verify
|
|
||||||
// `,
|
|
||||||
// phoneNumber: process.env.ADMIN_PHONENUMBER ?? "",
|
|
||||||
// });
|
|
||||||
// return {
|
|
||||||
// message:
|
|
||||||
// "Your account has been requested for verification. Please wait for a response from admin.",
|
|
||||||
// payload: formData,
|
|
||||||
// db_error: "invalidPersonValidation",
|
|
||||||
// };
|
|
||||||
|
|
||||||
// if (isValidPerson) {
|
|
||||||
// await authClient.phoneNumber.sendOtp({
|
|
||||||
// phoneNumber: newUser.phoneNumber,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
redirect(
|
redirect(
|
||||||
`/auth/verify-otp-registration?phone_number=${encodeURIComponent(signupResponse.t_username)}`,
|
`/auth/verify-otp-registration?phone_number=${encodeURIComponent(signupResponse.t_username)}`,
|
||||||
);
|
);
|
||||||
return { message: "User created successfully" };
|
return { message: "User created successfully", error: "success" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendOtp = async (phoneNumber: string, code: string) => {
|
export const sendOtp = async (phoneNumber: string, code: string) => {
|
||||||
|
@ -34,6 +34,9 @@ export default function SignUpForm() {
|
|||||||
|
|
||||||
const [actionState, action, isPending] = React.useActionState(signup, {
|
const [actionState, action, isPending] = React.useActionState(signup, {
|
||||||
message: "",
|
message: "",
|
||||||
|
db_error: "",
|
||||||
|
errors: undefined,
|
||||||
|
payload: new FormData(),
|
||||||
});
|
});
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
@ -4,11 +4,9 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { VerifyRegistrationOTP } from "@/queries/authentication";
|
import { VerifyRegistrationOTP } from "@/queries/authentication";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { Loader2 } from "lucide-react";
|
import { Loader2 } from "lucide-react";
|
||||||
import { signIn } from "next-auth/react";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect, useRouter, useSearchParams } from "next/navigation";
|
import { redirect, useSearchParams } from "next/navigation";
|
||||||
import { useActionState } from "react";
|
import { useActionState } from "react";
|
||||||
|
|
||||||
export default function VerifyRegistrationOTPForm({
|
export default function VerifyRegistrationOTPForm({
|
||||||
@ -42,7 +40,6 @@ export default function VerifyRegistrationOTPForm({
|
|||||||
type="number"
|
type="number"
|
||||||
name="mobile"
|
name="mobile"
|
||||||
defaultValue={phone_number}
|
defaultValue={phone_number}
|
||||||
value={phone_number}
|
|
||||||
hidden
|
hidden
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
|
Loading…
x
Reference in New Issue
Block a user