mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-08-03 15:07:42 +00:00
feat(admin-topup): add description field to topup form and validation for amount
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 8m56s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 8m56s
fix(verify-registration-otp): improve styling and structure of OTP verification form
This commit is contained in:
@ -230,6 +230,7 @@ export type AddTopupFormState = {
|
|||||||
message: string;
|
message: string;
|
||||||
fieldErrors?: {
|
fieldErrors?: {
|
||||||
amount?: string[];
|
amount?: string[];
|
||||||
|
description?: string[];
|
||||||
};
|
};
|
||||||
payload?: FormData;
|
payload?: FormData;
|
||||||
};
|
};
|
||||||
@ -242,6 +243,15 @@ export async function adminUserTopup(
|
|||||||
const amount = formData.get("amount") as string;
|
const amount = formData.get("amount") as string;
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
|
|
||||||
|
if (!amount) {
|
||||||
|
return {
|
||||||
|
status: false,
|
||||||
|
message: "Amount is required",
|
||||||
|
fieldErrors: { amount: ["Amount is required"], description: [] },
|
||||||
|
payload: formData,
|
||||||
|
}
|
||||||
|
}
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${process.env.SARLINK_API_BASE_URL}/api/billing/admin-topup/`,
|
`${process.env.SARLINK_API_BASE_URL}/api/billing/admin-topup/`,
|
||||||
{
|
{
|
||||||
|
@ -17,12 +17,14 @@ import {
|
|||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
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 { Textarea } from "../ui/textarea";
|
||||||
|
|
||||||
export type AddTopupFormState = {
|
export type AddTopupFormState = {
|
||||||
status: boolean;
|
status: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
fieldErrors?: {
|
fieldErrors?: {
|
||||||
amount?: string[];
|
amount?: string[];
|
||||||
|
description?: string[];
|
||||||
};
|
};
|
||||||
payload?: FormData;
|
payload?: FormData;
|
||||||
};
|
};
|
||||||
@ -81,9 +83,9 @@ export default function AddTopupDialogForm({ user_id }: { user_id?: string }) {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<form action={formAction}>
|
<form action={formAction}>
|
||||||
<div className="grid gap-4 py-4">
|
<div className="grid gap-4 py-4">
|
||||||
<div className="flex flex-col gap-2">
|
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<Label htmlFor="device_name">Topup Amount</Label>
|
<div className="flex flex-col gap-3">
|
||||||
|
<Label htmlFor="amount">Topup Amount</Label>
|
||||||
<input type="hidden" name="user_id" value={user_id} />
|
<input type="hidden" name="user_id" value={user_id} />
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
type="number"
|
||||||
@ -98,6 +100,23 @@ export default function AddTopupDialogForm({ user_id }: { user_id?: string }) {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<Label htmlFor="description">Topup Description</Label>
|
||||||
|
<input type="hidden" name="user_id" value={user_id} />
|
||||||
|
<Textarea
|
||||||
|
defaultValue={(state?.payload?.get("description") || "") as string}
|
||||||
|
rows={10}
|
||||||
|
name="description"
|
||||||
|
id="topup_description"
|
||||||
|
className="col-span-5 max-w-[375px] h-32 resize-none"
|
||||||
|
style={{ overflowY: "auto" }}
|
||||||
|
/>
|
||||||
|
{state.fieldErrors?.description && (
|
||||||
|
<span className="text-red-500 text-sm">
|
||||||
|
{state.fieldErrors.description[0]}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { redirect, useSearchParams } from "next/navigation";
|
||||||
|
import { useActionState } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
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 { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { VerifyRegistrationOTP } from "@/queries/authentication";
|
import { VerifyRegistrationOTP } from "@/queries/authentication";
|
||||||
import { Loader2 } from "lucide-react";
|
|
||||||
import Link from "next/link";
|
|
||||||
import { redirect, useSearchParams } from "next/navigation";
|
|
||||||
import { useActionState } from "react";
|
|
||||||
|
|
||||||
export default function VerifyRegistrationOTPForm({
|
export default function VerifyRegistrationOTPForm({
|
||||||
phone_number,
|
phone_number,
|
||||||
@ -28,7 +28,7 @@ export default function VerifyRegistrationOTPForm({
|
|||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
action={formAction}
|
action={formAction}
|
||||||
className="w-full max-w-xs bg-white dark:bg-sarLinkOrange/10 title-bg border rounded-lg shadow my-4"
|
className="w-full max-w-xs bg-white dark:bg-sarLinkOrange/10 title-bg border-2 border-sarLinkOrange/50 rounded-lg shadow my-4"
|
||||||
>
|
>
|
||||||
<div className="grid pb-4 pt-4 gap-4 px-4">
|
<div className="grid pb-4 pt-4 gap-4 px-4">
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
@ -37,7 +37,7 @@ export default function VerifyRegistrationOTPForm({
|
|||||||
{state.message}
|
{state.message}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="bg-sarLinkOrange/50 border border-yellow-900/50 dark:border-sarLinkOrange/50 rounded p-2 text-center text-sm text-gray-900 dark:text-gray-300">
|
<p className="bg-sarLinkOrange border border-yellow-900/50 dark:border-sarLinkOrange/50 rounded p-2 text-center text-sm text-gray-900 dark:text-orange-950">
|
||||||
Account verification OTP sent to [{phone_number}]
|
Account verification OTP sent to [{phone_number}]
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
@ -59,7 +59,7 @@ export default function VerifyRegistrationOTPForm({
|
|||||||
type="number"
|
type="number"
|
||||||
placeholder="Enter OTP"
|
placeholder="Enter OTP"
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-white text-black",
|
"bg-white text-black dark:text-white dark:bg-gray-950",
|
||||||
state.status === "verify_success" && "hidden",
|
state.status === "verify_success" && "hidden",
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user