diff --git a/src/actions/payoutMethods/index.ts b/src/actions/payoutMethods/index.ts index dbca68c21..ebe536d49 100644 --- a/src/actions/payoutMethods/index.ts +++ b/src/actions/payoutMethods/index.ts @@ -218,8 +218,6 @@ const deleteSolanaHandler = async ( }; }; - - export const addUpi = createSafeAction(upiIdInsertSchema, addUpiHandler); export const addSolanaAddress = createSafeAction( diff --git a/src/actions/payoutMethods/schema.ts b/src/actions/payoutMethods/schema.ts index 0bb9d7c36..461a934aa 100644 --- a/src/actions/payoutMethods/schema.ts +++ b/src/actions/payoutMethods/schema.ts @@ -3,13 +3,13 @@ import { z } from 'zod'; export const payoutMethodSchema = z.object({ upiId: z .string() - .refine((value) => /^[0-9A-Za-z._-]{2,256}@[A-Za-z]{2,64}$/.test(value), { + .refine((value) => (/^[0-9A-Za-z._-]{2,256}@[A-Za-z]{2,64}$/).test(value), { message: 'Enter a valid UPI address', }) .optional(), solanaAddress: z .string() - .refine((value) => /^[A-Za-z0-9]{44}$/.test(value), { + .refine((value) => (/^[A-Za-z0-9]{44}$/).test(value), { message: 'Enter a valid Solana address', }) .optional(), @@ -18,13 +18,13 @@ export const payoutMethodSchema = z.object({ export const upiIdInsertSchema = z.object({ upiId: z .string() - .refine((value) => /^[0-9A_Za-z._-]{2,256}@[A_Za-z]{2,64}$/.test(value), { + .refine((value) => (/^[0-9A_Za-z._-]{2,256}@[A_Za-z]{2,64}$/).test(value), { message: 'Invalid UPI address', }), }); export const solanaAddressInsertSchema = z.object({ - solanaAddress: z.string().refine((value) => /^[A-Za-z0-9]{44}$/.test(value), { + solanaAddress: z.string().refine((value) => (/^[A-Za-z0-9]{44}$/).test(value), { message: 'Invalid Solana address', }), }); diff --git a/src/actions/payoutMethods/types.ts b/src/actions/payoutMethods/types.ts index df83d29c6..c2da5b631 100644 --- a/src/actions/payoutMethods/types.ts +++ b/src/actions/payoutMethods/types.ts @@ -1,5 +1,9 @@ import { z } from 'zod'; -import { payoutMethodDeleteSchema, solanaAddressInsertSchema, upiIdInsertSchema } from './schema'; +import { + payoutMethodDeleteSchema, + solanaAddressInsertSchema, + upiIdInsertSchema, +} from './schema'; import { ActionState } from '@/lib/create-safe-action'; import { SolanaAddress, UpiId } from '@prisma/client'; import { Delete } from '@/lib/utils'; @@ -8,7 +12,13 @@ export type InputTypeCreateUpi = z.infer; export type ReturnTypeCreateUpi = ActionState; export type InputTypeCreateSolana = z.infer; -export type ReturnTypeCreateSolana = ActionState; +export type ReturnTypeCreateSolana = ActionState< + InputTypeCreateSolana, + SolanaAddress +>; export type DeleteTypePayoutMethod = z.infer; -export type ReturnTypePayoutMethodDelete = ActionState; +export type ReturnTypePayoutMethodDelete = ActionState< + DeleteTypePayoutMethod, + Delete +>; diff --git a/src/app/payout-methods/page.tsx b/src/app/payout-methods/page.tsx index fc2a193ad..a947d55be 100644 --- a/src/app/payout-methods/page.tsx +++ b/src/app/payout-methods/page.tsx @@ -1,141 +1,167 @@ -"use client" -import { useEffect, useState } from "react"; -import { Button } from "@/components/ui/button"; -import NewPayoutDialog from "@/components/NewPayoutDialog"; -import { Trash } from "lucide-react" -import { deleteSolanaAddress, deleteUpiId, getPayoutMethods } from "@/actions/payoutMethods"; -import { SolanaAddress, UpiId } from "@prisma/client"; -import { useAction } from "@/hooks/useAction"; -import { toast } from "sonner"; +'use client'; +import { useEffect, useState } from 'react'; +import { Button } from '@/components/ui/button'; +import NewPayoutDialog from '@/components/NewPayoutDialog'; +import { Trash } from 'lucide-react'; +import { + deleteSolanaAddress, + deleteUpiId, + getPayoutMethods, +} from '@/actions/payoutMethods'; +import { SolanaAddress, UpiId } from '@prisma/client'; +import { useAction } from '@/hooks/useAction'; +import { toast } from 'sonner'; export default function Page() { + const [isDialogBoxOpen, setIsDialogBoxOpen] = useState(false); + const [btnClicked, setBtnClicked] = useState(''); - const [isDialogBoxOpen, setIsDialogBoxOpen] = useState(false) - const [btnClicked, setBtnClicked] = useState("") + const openDialog = (e: any) => { + setIsDialogBoxOpen(true); + setBtnClicked(e.target.id); + }; - const openDialog = (e: any) => { - setIsDialogBoxOpen(true) - setBtnClicked(e.target.id) - } - - const closeDialog = () => setIsDialogBoxOpen(false) + const closeDialog = () => setIsDialogBoxOpen(false); - const [upiAddresses, setUpiAddresses] = useState([]) - const [solanaAddresses, setSolanaAddresses] = useState([]) + const [upiAddresses, setUpiAddresses] = useState([]); + const [solanaAddresses, setSolanaAddresses] = useState< + SolanaAddress[] | undefined + >([]); - const fetchPayoutMethods = async () => { - const result = await getPayoutMethods() - if (result) { - setUpiAddresses(result.upiIds) - setSolanaAddresses(result.solanaAddresses) - } + const fetchPayoutMethods = async () => { + const result = await getPayoutMethods(); + if (result) { + setUpiAddresses(result.upiIds); + setSolanaAddresses(result.solanaAddresses); } + }; - const { execute: executeDeleteUPI } = useAction(deleteUpiId, { - onSuccess: () => { - toast.success("UPI Address deleted successfully") - }, - onError: () => { - toast.error("Failed to delete UPI id") - } - }) + const { execute: executeDeleteUPI } = useAction(deleteUpiId, { + onSuccess: () => { + toast.success('UPI Address deleted successfully'); + }, + onError: () => { + toast.error('Failed to delete UPI id'); + }, + }); - const { execute: executeDeleteSolana } = useAction(deleteSolanaAddress, { - onSuccess: () => { - toast.success("Solana Address deleted successfully") - }, - onError: () => { - toast.error("Failed to delete Solana address") - } - }) + const { execute: executeDeleteSolana } = useAction(deleteSolanaAddress, { + onSuccess: () => { + toast.success('Solana Address deleted successfully'); + }, + onError: () => { + toast.error('Failed to delete Solana address'); + }, + }); - const handleUpiDelete = (id: number) => { - executeDeleteUPI({ id: id }) - fetchPayoutMethods() - } + const handleUpiDelete = (id: number) => { + executeDeleteUPI({ id }); + fetchPayoutMethods(); + }; - const handleSolanaDelete = (id: number) => { - executeDeleteSolana({ id: id }) - fetchPayoutMethods() - } + const handleSolanaDelete = (id: number) => { + executeDeleteSolana({ id }); + fetchPayoutMethods(); + }; - useEffect(() => { - fetchPayoutMethods() - }, []) + useEffect(() => { + fetchPayoutMethods(); + }, []); - useEffect(() => { - fetchPayoutMethods() - }, [isDialogBoxOpen]) + useEffect(() => { + fetchPayoutMethods(); + }, [isDialogBoxOpen]); - return ( -
-
-
-

Payout Methods

-
-
-
-
-

UPI Addresses

- - -
-
- { - upiAddresses?.length !== 0 ? ( - upiAddresses?.map((upi, index) => ( -
-

{upi.value}

- -
- )) - ) : -
-

No addresses added yet!

-
- } -
-
+ return ( +
+
+
+

Payout Methods

+
+
+
+
+

UPI Addresses

+ + +
+
+ {upiAddresses?.length !== 0 ? ( + upiAddresses?.map((upi, index) => ( +
+

+ {upi.value} +

+ +
+ )) + ) : ( +
+

No addresses added yet!

-
-
-
-

Solana Addresses

- -
-
- { - solanaAddresses?.length !== 0 ? ( - solanaAddresses?.map((sol, index) => ( -
-

{sol.value}

- -
- )) - ) : -
-

No addresses added yet!

-
- } -
-
+ )} +
+
+
+
+
+
+

Solana Addresses

+ +
+
+ {solanaAddresses?.length !== 0 ? ( + solanaAddresses?.map((sol, index) => ( +
+

+ {sol.value} +

+ +
+ )) + ) : ( +
+

No addresses added yet!

- + )}
+
- ); -} \ No newline at end of file +
+
+ ); +} diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index dbeaada3f..78e2dac42 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -121,10 +121,11 @@ export function Sidebar({
@@ -189,12 +190,14 @@ export function ToggleButton({ className={`block h-0.5 w-6 rounded-sm bg-black transition-all duration-300 ease-out dark:bg-white ${!sidebarOpen ? 'translate-y-1 rotate-45' : '-translate-y-0.5'}`} > ); diff --git a/src/components/Signin.tsx b/src/components/Signin.tsx index 2119d7b8a..a8261dddc 100644 --- a/src/components/Signin.tsx +++ b/src/components/Signin.tsx @@ -1,31 +1,27 @@ 'use client'; + import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { signIn } from 'next-auth/react'; import { useRouter } from 'next/navigation'; -import React, { useRef, useState } from 'react'; - +import React, { useState } from 'react'; import { toast } from 'sonner'; + const Signin = () => { const [isPasswordVisible, setIsPasswordVisible] = useState(false); - const [checkingPassword, setCheckingPassword] = useState(false); const [requiredError, setRequiredError] = useState({ emailReq: false, passReq: false, }); - const [isButtonDisabled, setisButtonDisabled] = useState({ - isEmail: true, - isPassword: true, - }); + const router = useRouter(); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); function togglePasswordVisibility() { setIsPasswordVisible((prevState: any) => !prevState); } - const router = useRouter(); - const email = useRef(''); - const password = useRef(''); const handleSubmit = async (e?: React.FormEvent) => { const loadId = toast.loading('Signing in...'); @@ -33,18 +29,19 @@ const Signin = () => { e.preventDefault(); } - if (!email.current || !password.current) { + if (!email.trim() || !password.trim()) { setRequiredError({ - emailReq: email.current ? false : true, - passReq: password.current ? false : true, + emailReq: email.trim() ? false : true, + passReq: password.trim() ? false : true, }); - toast.dismiss(loadId); + setTimeout(() => { + toast.dismiss(loadId); + }, 0); return; } - setCheckingPassword(true); const res = await signIn('credentials', { - username: email.current, - password: password.current, + username: email, + password, redirect: false, }); @@ -53,8 +50,7 @@ const Signin = () => { router.push('/'); toast.success('Signed In'); } else { - toast.error('oops something went wrong..!'); - setCheckingPassword(false); + toast.error('Invalid credentials'); } }; return ( @@ -72,15 +68,11 @@ const Signin = () => { id="email" placeholder="name@email.com" onChange={(e) => { + setEmail(e.target.value); setRequiredError((prevState) => ({ ...prevState, emailReq: false, })); - setisButtonDisabled((prevState) => ({ - ...prevState, - isEmail: e.target.value.trim() === '' ? true : false, - })); - email.current = e.target.value; }} /> {requiredError.emailReq && ( @@ -97,15 +89,11 @@ const Signin = () => { id="password" placeholder="••••••••" onChange={(e) => { + setPassword(e.target.value); setRequiredError((prevState) => ({ ...prevState, passReq: false, })); - setisButtonDisabled((prevState) => ({ - ...prevState, - isPassword: e.target.value.trim() === '' ? true : false, - })); - password.current = e.target.value; }} onKeyDown={async (e) => { if (e.key === 'Enter') { @@ -163,7 +151,7 @@ const Signin = () => {