feat : implement the quick pay screen
This commit is contained in:
179
src/app/(main)/accounts/account_details/page.tsx
Normal file
179
src/app/(main)/accounts/account_details/page.tsx
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import {
|
||||||
|
Group,
|
||||||
|
Paper,
|
||||||
|
Select,
|
||||||
|
Stack,
|
||||||
|
Text,
|
||||||
|
Title,
|
||||||
|
} from "@mantine/core";
|
||||||
|
import { notifications } from "@mantine/notifications";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useSearchParams } from "next/navigation";
|
||||||
|
|
||||||
|
interface accountData {
|
||||||
|
stAccountNo: string;
|
||||||
|
stAccountType: string;
|
||||||
|
stAvailableBalance: string;
|
||||||
|
custname: string;
|
||||||
|
stBookingNumber: string;
|
||||||
|
stApprovedAmount?: string; // optional for loan accounts
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AccountDetails() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [accountOptions, setAccountOptions] = useState<{ value: string; label: string }[]>([]);
|
||||||
|
const [selectedAccNo, setSelectedAccNo] = useState<string | null>(null);
|
||||||
|
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
||||||
|
const [accountDetails, setAccountDetails] = useState<accountData | null>(null);
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const passedAccNo = searchParams.get("accNo");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const token = localStorage.getItem("access_token");
|
||||||
|
if (!token) {
|
||||||
|
setAuthorized(false);
|
||||||
|
router.push("/login");
|
||||||
|
} else {
|
||||||
|
setAuthorized(true);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (authorized) {
|
||||||
|
const saved = sessionStorage.getItem("accountData");
|
||||||
|
if (saved) {
|
||||||
|
const parsed: accountData[] = JSON.parse(saved);
|
||||||
|
const options = parsed.map((acc) => ({
|
||||||
|
label: `${acc.stAccountNo} - ${acc.stAccountType}`,
|
||||||
|
value: acc.stAccountNo,
|
||||||
|
}));
|
||||||
|
setAccountOptions(options);
|
||||||
|
if (passedAccNo) {
|
||||||
|
handleAccountSelection(passedAccNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [authorized]);
|
||||||
|
|
||||||
|
const handleAccountSelection = async (accNo: string | null) => {
|
||||||
|
setSelectedAccNo(accNo);
|
||||||
|
setAccountDetails(null);
|
||||||
|
if (!accNo) return;
|
||||||
|
try {
|
||||||
|
const token = localStorage.getItem("access_token");
|
||||||
|
const response = await fetch("/api/customer", {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const data: accountData[] = await response.json();
|
||||||
|
if (response.ok && Array.isArray(data)) {
|
||||||
|
const matched = data.find((acc) => acc.stAccountNo === accNo);
|
||||||
|
if (matched) {
|
||||||
|
// Simulate approvedBalance for loan accounts
|
||||||
|
if (matched.stAccountType.toUpperCase().includes("LN")) {
|
||||||
|
matched.stApprovedAmount = (
|
||||||
|
parseFloat(matched.stAvailableBalance) + 20000
|
||||||
|
).toFixed(2); // dummy logic
|
||||||
|
}
|
||||||
|
setAccountDetails(matched);
|
||||||
|
} else {
|
||||||
|
notifications.show({
|
||||||
|
withBorder: true,
|
||||||
|
color: "orange",
|
||||||
|
title: "Account not found",
|
||||||
|
message: "Selected account was not found in the response.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid response");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
notifications.show({
|
||||||
|
withBorder: true,
|
||||||
|
color: "red",
|
||||||
|
title: "Fetch failed",
|
||||||
|
message: "Could not fetch account details. Try again.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!authorized) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Paper shadow="sm" radius="md" p="md" withBorder h={400}>
|
||||||
|
<Title order={3} mb="md">
|
||||||
|
Account Details
|
||||||
|
</Title>
|
||||||
|
|
||||||
|
<Stack gap="md">
|
||||||
|
<Select
|
||||||
|
label="Select Account Number"
|
||||||
|
placeholder="Choose account number"
|
||||||
|
data={accountOptions}
|
||||||
|
value={selectedAccNo}
|
||||||
|
onChange={handleAccountSelection}
|
||||||
|
searchable
|
||||||
|
/>
|
||||||
|
|
||||||
|
{accountDetails && (
|
||||||
|
<Paper withBorder p="md" radius="md" bg="gray.0">
|
||||||
|
<Stack gap="sm">
|
||||||
|
<Group p="apart">
|
||||||
|
<Text size="sm" fw={500} c="dimmed">Account Number</Text>
|
||||||
|
<Text size="md">{accountDetails.stAccountNo}</Text>
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<Group p="apart">
|
||||||
|
<Text size="sm" fw={500} c="dimmed">Account Type</Text>
|
||||||
|
<Text size="md">{accountDetails.stAccountType}</Text>
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<Group p="apart">
|
||||||
|
<Text size="sm" fw={500} c="dimmed">Description</Text>
|
||||||
|
<Text size="md">{accountDetails.stBookingNumber}</Text>
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
{/* Show Loan-specific fields */}
|
||||||
|
{accountDetails.stAccountType.toUpperCase().includes("LN") ? (
|
||||||
|
<>
|
||||||
|
<Group p="apart">
|
||||||
|
<Text size="sm" fw={500} c="dimmed">Approved Balance</Text>
|
||||||
|
<Text size="md" c="gray.8">
|
||||||
|
₹{parseFloat(accountDetails.stApprovedAmount || "0").toLocaleString("en-IN", {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
})}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
<Group p="apart">
|
||||||
|
<Text size="sm" fw={500} c="dimmed">Available Balance</Text>
|
||||||
|
<Text size="md" c="red">
|
||||||
|
– ₹{parseFloat(accountDetails.stAvailableBalance).toLocaleString("en-IN", {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
})}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Group p="apart">
|
||||||
|
<Text size="sm" fw={500} c="dimmed">Balance</Text>
|
||||||
|
<Text size="md" c="green">
|
||||||
|
₹{parseFloat(accountDetails.stAvailableBalance).toLocaleString("en-IN", {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
})}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
|
);
|
||||||
|
}
|
@@ -61,7 +61,6 @@ export default function AccountStatementPage() {
|
|||||||
}
|
}
|
||||||
}, [passedAccNo]);
|
}, [passedAccNo]);
|
||||||
|
|
||||||
|
|
||||||
const handleAccountTransaction = async () => {
|
const handleAccountTransaction = async () => {
|
||||||
if (!selectedAccNo || !startDate || !endDate) {
|
if (!selectedAccNo || !startDate || !endDate) {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
|
@@ -13,6 +13,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
|
|||||||
const links = [
|
const links = [
|
||||||
{ label: "Account Summary", href: "/accounts" },
|
{ label: "Account Summary", href: "/accounts" },
|
||||||
{ label: "Statement of Account", href: "/accounts/account_statement" },
|
{ label: "Statement of Account", href: "/accounts/account_statement" },
|
||||||
|
{ label: "Account Details", href: "/accounts/account_details" },
|
||||||
];
|
];
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const token = localStorage.getItem("access_token");
|
const token = localStorage.getItem("access_token");
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Paper, ScrollArea, Table, Text, Title } from "@mantine/core";
|
import { Group, Paper, ScrollArea, Table, Text, Title } from "@mantine/core";
|
||||||
import { notifications } from "@mantine/notifications";
|
import { notifications } from "@mantine/notifications";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -30,7 +30,7 @@ export default function AccountSummary() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (response.ok && Array.isArray(data)) {
|
if (response.ok && Array.isArray(data)) {
|
||||||
setAccountData(data);
|
setAccountData(data);
|
||||||
sessionStorage.setItem('accountData',JSON.stringify(data))
|
sessionStorage.setItem("accountData", JSON.stringify(data));
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
@@ -64,13 +64,25 @@ export default function AccountSummary() {
|
|||||||
padding: "10px",
|
padding: "10px",
|
||||||
};
|
};
|
||||||
|
|
||||||
const rows = accountData.map((acc, index) => (
|
// Filter accounts
|
||||||
|
const depositAccounts = accountData.filter(
|
||||||
|
(acc) => !acc.stAccountType.toUpperCase().includes("LN")
|
||||||
|
);
|
||||||
|
const loanAccounts = accountData.filter((acc) =>
|
||||||
|
acc.stAccountType.toUpperCase().includes("LN")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Function to render table rows
|
||||||
|
const renderRows = (data: accountData[]) =>
|
||||||
|
data.map((acc, index) => (
|
||||||
<tr key={index}>
|
<tr key={index}>
|
||||||
<td style={{ ...cellStyle, textAlign: "left" }}>{acc.custname}</td>
|
|
||||||
<td style={{ ...cellStyle, textAlign: "left" }}>{acc.stAccountType}</td>
|
<td style={{ ...cellStyle, textAlign: "left" }}>{acc.stAccountType}</td>
|
||||||
<td style={{ ...cellStyle, textAlign: "right", color: '#1c7ed6', cursor: "pointer" }}
|
<td
|
||||||
onClick={() => router.push(`/accounts/account_statement?accNo=${acc.stAccountNo}`)}>
|
style={{ ...cellStyle, textAlign: "right", color: "#1c7ed6", cursor: "pointer" }}
|
||||||
{acc.stAccountNo}</td>
|
onClick={() => router.push(`/accounts/account_details?accNo=${acc.stAccountNo}`)}
|
||||||
|
>
|
||||||
|
{acc.stAccountNo}
|
||||||
|
</td>
|
||||||
<td style={{ ...cellStyle, textAlign: "right" }}>
|
<td style={{ ...cellStyle, textAlign: "right" }}>
|
||||||
{parseFloat(acc.stAvailableBalance).toLocaleString("en-IN", {
|
{parseFloat(acc.stAvailableBalance).toLocaleString("en-IN", {
|
||||||
minimumFractionDigits: 2,
|
minimumFractionDigits: 2,
|
||||||
@@ -79,17 +91,18 @@ export default function AccountSummary() {
|
|||||||
</tr>
|
</tr>
|
||||||
));
|
));
|
||||||
|
|
||||||
if (authorized) {
|
// Table component
|
||||||
return (
|
const renderTable = (title: string, rows: JSX.Element[]) => (
|
||||||
<Paper shadow="sm" radius="md" p="md" withBorder>
|
<Paper shadow="sm" radius="md" p="md" withBorder w="100%"
|
||||||
<Title order={3} mb="sm">
|
// bg="#97E6B8"
|
||||||
Account Summary (Currency - INR)
|
>
|
||||||
|
<Title order={4} mb="sm">
|
||||||
|
{title}
|
||||||
</Title>
|
</Title>
|
||||||
<ScrollArea>
|
<ScrollArea>
|
||||||
<Table style={{ borderCollapse: "collapse", width: "100%" }}>
|
<Table style={{ borderCollapse: "collapse", width: "100%" }}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr style={{ backgroundColor: "#3385ff" }}>
|
<tr style={{ backgroundColor: "#3385ff" }}>
|
||||||
<th style={{ ...cellStyle, textAlign: "left" }}>Customer Name</th>
|
|
||||||
<th style={{ ...cellStyle, textAlign: "left" }}>Account Type</th>
|
<th style={{ ...cellStyle, textAlign: "left" }}>Account Type</th>
|
||||||
<th style={{ ...cellStyle, textAlign: "right" }}>Account No.</th>
|
<th style={{ ...cellStyle, textAlign: "right" }}>Account No.</th>
|
||||||
<th style={{ ...cellStyle, textAlign: "right" }}>Book Balance</th>
|
<th style={{ ...cellStyle, textAlign: "right" }}>Book Balance</th>
|
||||||
@@ -98,11 +111,28 @@ export default function AccountSummary() {
|
|||||||
<tbody>{rows}</tbody>
|
<tbody>{rows}</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
</Paper>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (authorized) {
|
||||||
|
return (
|
||||||
|
<Paper shadow="sm" radius="md" p="md" withBorder h={400}
|
||||||
|
// bg="linear-gradient(90deg,rgba(195, 218, 227, 1) 0%, rgba(151, 230, 184, 1) 50%)"
|
||||||
|
>
|
||||||
|
<Title order={3} mb="md">Account Summary</Title>
|
||||||
|
<Group align="flex-start" grow>
|
||||||
|
{/* Left table for Deposit Accounts */}
|
||||||
|
{depositAccounts.length > 0 && renderTable("Deposit Accounts (INR)", renderRows(depositAccounts))}
|
||||||
|
|
||||||
|
{/* Right table for Loan Accounts (only shown if available) */}
|
||||||
|
{loanAccounts.length > 0 && renderTable("Loan Accounts (INR)", renderRows(loanAccounts))}
|
||||||
|
</Group>
|
||||||
<Text mt="sm" size="xs" c="dimmed">
|
<Text mt="sm" size="xs" c="dimmed">
|
||||||
* Book Balance includes uncleared effects.
|
* Book Balance includes uncleared effects.
|
||||||
</Text>
|
</Text>
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -12,10 +12,9 @@ export default function Layout({ children }: { children: React.ReactNode }) {
|
|||||||
|
|
||||||
const links = [
|
const links = [
|
||||||
{ label: " Quick Pay", href: "/funds_transfer" },
|
{ label: " Quick Pay", href: "/funds_transfer" },
|
||||||
{ label: "Send to Beneficiary", href: "/accounts/account_statement" },
|
{ label: "Add Beneficiary", href: "/accounts/add_beneficiary" },
|
||||||
{ label: "Transfer within the bank", href: "/accounts/account_statement" },
|
{ label: "View Beneficiary ", href: "/accounts/view_beneficiary" },
|
||||||
{ label: "Add Beneficary", href: "/accounts/account_statement" },
|
{ label: "Send to Beneficiary", href: "/accounts/send_beneficiary" },
|
||||||
{ label: "View Beneficary ", href: "/accounts/account_statement" },
|
|
||||||
];
|
];
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const token = localStorage.getItem("access_token");
|
const token = localStorage.getItem("access_token");
|
||||||
|
@@ -1,20 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import {
|
import { Button, Group, Modal, Paper, Radio, ScrollArea, Select, Stack, Text, TextInput, Title } from "@mantine/core";
|
||||||
Button,
|
|
||||||
Group,
|
|
||||||
Paper,
|
|
||||||
Radio,
|
|
||||||
ScrollArea,
|
|
||||||
Select,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
TextInput,
|
|
||||||
Title,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { notifications } from "@mantine/notifications";
|
import { notifications } from "@mantine/notifications";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
import { generateOTP } from'@/app/OTPGenerator';
|
||||||
|
|
||||||
interface accountData {
|
interface accountData {
|
||||||
stAccountNo: string;
|
stAccountNo: string;
|
||||||
@@ -30,11 +20,13 @@ export default function QuickPay() {
|
|||||||
const [accountData, setAccountData] = useState<accountData[]>([]);
|
const [accountData, setAccountData] = useState<accountData[]>([]);
|
||||||
const [selectedAccNo, setSelectedAccNo] = useState<string | null>(null);
|
const [selectedAccNo, setSelectedAccNo] = useState<string | null>(null);
|
||||||
const [beneficiaryAcc, setBeneficiaryAcc] = useState("");
|
const [beneficiaryAcc, setBeneficiaryAcc] = useState("");
|
||||||
|
const [showPayeeAcc, setShowPayeeAcc] = useState(true);
|
||||||
const [confirmBeneficiaryAcc, setConfirmBeneficiaryAcc] = useState("");
|
const [confirmBeneficiaryAcc, setConfirmBeneficiaryAcc] = useState("");
|
||||||
const [beneficiaryType, setBeneficiaryType] = useState<string | null>(null);
|
const [beneficiaryType, setBeneficiaryType] = useState<string | null>(null);
|
||||||
const [isVisibilityLocked, setIsVisibilityLocked] = useState(false);
|
const [isVisibilityLocked, setIsVisibilityLocked] = useState(false);
|
||||||
const [amount, setAmount] = useState("");
|
const [amount, setAmount] = useState("");
|
||||||
const [remarks, setRemarks] = useState("");
|
const [remarks, setRemarks] = useState("");
|
||||||
|
const [showConfirmModel, setConfirmModel] = useState(false);
|
||||||
const [showTxnPassword, setShowTxnPassword] = useState(false);
|
const [showTxnPassword, setShowTxnPassword] = useState(false);
|
||||||
const [txnPassword, setTxnPassword] = useState("");
|
const [txnPassword, setTxnPassword] = useState("");
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
@@ -42,6 +34,17 @@ export default function QuickPay() {
|
|||||||
const [beneficiaryName, setBeneficiaryName] = useState<string | null>(null);
|
const [beneficiaryName, setBeneficiaryName] = useState<string | null>(null);
|
||||||
const [showOtpField, setShowOtpField] = useState(false);
|
const [showOtpField, setShowOtpField] = useState(false);
|
||||||
const [otp, setOtp] = useState("");
|
const [otp, setOtp] = useState("");
|
||||||
|
const [generateOtp, setGenerateOtp] = useState("");
|
||||||
|
|
||||||
|
async function handleGenerateOtp() {
|
||||||
|
// const value = await generateOTP(6);
|
||||||
|
const value = "123456";
|
||||||
|
setGenerateOtp(value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedAccount = accountData.find((acc) => acc.stAccountNo === selectedAccNo);
|
||||||
|
const getFullMaskedAccount = (acc: string) => { return "X".repeat(acc.length); };
|
||||||
|
|
||||||
const accountOptions = accountData.map((acc) => ({
|
const accountOptions = accountData.map((acc) => ({
|
||||||
value: acc.stAccountNo,
|
value: acc.stAccountNo,
|
||||||
@@ -60,7 +63,7 @@ export default function QuickPay() {
|
|||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (response.ok && Array.isArray(data)) {
|
if (response.ok && Array.isArray(data)) {
|
||||||
const filterSAaccount =data.filter((acc)=>acc.stAccountType==='SA');
|
const filterSAaccount = data.filter((acc) => acc.stAccountType === 'SA');
|
||||||
setAccountData(filterSAaccount);
|
setAccountData(filterSAaccount);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -90,10 +93,8 @@ export default function QuickPay() {
|
|||||||
}
|
}
|
||||||
}, [authorized]);
|
}, [authorized]);
|
||||||
|
|
||||||
const isValidTxnPassword = (password: string) =>
|
|
||||||
/[A-Z]/i.test(password) && /[0-9]/.test(password) && /[^a-zA-Z0-9]/.test(password);
|
|
||||||
|
|
||||||
const handleValidate = async () => {
|
async function handleValidate(){
|
||||||
if (!selectedAccNo || !beneficiaryAcc ||
|
if (!selectedAccNo || !beneficiaryAcc ||
|
||||||
!confirmBeneficiaryAcc
|
!confirmBeneficiaryAcc
|
||||||
) {
|
) {
|
||||||
@@ -139,6 +140,8 @@ export default function QuickPay() {
|
|||||||
} else {
|
} else {
|
||||||
setBeneficiaryName("Invalid account number");
|
setBeneficiaryName("Invalid account number");
|
||||||
setValidationStatus("error");
|
setValidationStatus("error");
|
||||||
|
setBeneficiaryAcc("");
|
||||||
|
setConfirmBeneficiaryAcc("");
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
setBeneficiaryName("Invalid account number");
|
setBeneficiaryName("Invalid account number");
|
||||||
@@ -146,7 +149,7 @@ export default function QuickPay() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProceed = async () => {
|
async function handleProceed(){
|
||||||
if (!selectedAccNo || !beneficiaryAcc || !confirmBeneficiaryAcc || !beneficiaryType || !amount || !remarks) {
|
if (!selectedAccNo || !beneficiaryAcc || !confirmBeneficiaryAcc || !beneficiaryType || !amount || !remarks) {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
title: "Validation Error",
|
title: "Validation Error",
|
||||||
@@ -164,28 +167,8 @@ export default function QuickPay() {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!showOtpField && !showTxnPassword && !showConfirmModel) {
|
||||||
if (!showTxnPassword) {
|
setConfirmModel(true);
|
||||||
setShowTxnPassword(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!txnPassword || !isValidTxnPassword(txnPassword)) {
|
|
||||||
notifications.show({
|
|
||||||
title: "Weak Password",
|
|
||||||
message: "Password must contain letter, number, and special character",
|
|
||||||
color: "red",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!showOtpField) {
|
|
||||||
setShowOtpField(true);
|
|
||||||
notifications.show({
|
|
||||||
title: "OTP Sent",
|
|
||||||
message: "Check your registered device for OTP",
|
|
||||||
color: "green",
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +180,28 @@ export default function QuickPay() {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (otp !== generateOtp) {
|
||||||
|
notifications.show({
|
||||||
|
title: "Invalid OTP",
|
||||||
|
message: "The OTP entered does not match",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!showTxnPassword) {
|
||||||
|
setShowTxnPassword(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!txnPassword) {
|
||||||
|
notifications.show({
|
||||||
|
title: "Missing field",
|
||||||
|
message: "Please Enter Transaction Password Before Proceed",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
const token = localStorage.getItem("access_token");
|
const token = localStorage.getItem("access_token");
|
||||||
@@ -212,23 +216,18 @@ export default function QuickPay() {
|
|||||||
fromAccount: selectedAccNo,
|
fromAccount: selectedAccNo,
|
||||||
toAccount: beneficiaryAcc,
|
toAccount: beneficiaryAcc,
|
||||||
toAccountType: beneficiaryType,
|
toAccountType: beneficiaryType,
|
||||||
amount,
|
amount: amount,
|
||||||
narration: remarks,
|
narration: remarks,
|
||||||
txnPassword,
|
tpassword:txnPassword,
|
||||||
otp,
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await res.json();
|
const result = await res.json();
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
title: "Success",
|
title: "Success",
|
||||||
message: "Transaction successful",
|
message: "Transaction successful",
|
||||||
color: "green",
|
color: "green",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset
|
|
||||||
setShowTxnPassword(false);
|
setShowTxnPassword(false);
|
||||||
setTxnPassword("");
|
setTxnPassword("");
|
||||||
setShowOtpField(false);
|
setShowOtpField(false);
|
||||||
@@ -238,7 +237,7 @@ export default function QuickPay() {
|
|||||||
} else {
|
} else {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
title: "Error",
|
title: "Error",
|
||||||
message: result?.message || "Transaction failed",
|
message: result?.error || "Transaction failed",
|
||||||
color: "red",
|
color: "red",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -256,6 +255,42 @@ export default function QuickPay() {
|
|||||||
if (!authorized) return null;
|
if (!authorized) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
<Modal
|
||||||
|
opened={showConfirmModel}
|
||||||
|
onClose={() => setConfirmModel(false)}
|
||||||
|
// title="Confirm Transaction"
|
||||||
|
centered
|
||||||
|
>
|
||||||
|
<Stack>
|
||||||
|
<Title order={4}>Confirm Transaction</Title>
|
||||||
|
<Text><strong>Debit Account:</strong> {selectedAccNo}</Text>
|
||||||
|
<Text><strong>Payee Account:</strong> {beneficiaryAcc}</Text>
|
||||||
|
<Text><strong>Payee Name:</strong> {beneficiaryName}</Text>
|
||||||
|
<Text><strong>Amount:</strong> ₹ {amount}</Text>
|
||||||
|
<Text><strong>Remarks:</strong> ₹ {remarks}</Text>
|
||||||
|
</Stack>
|
||||||
|
<Group justify="flex-end" mt="md">
|
||||||
|
<Button variant="default" onClick={() => setConfirmModel(false)}>Cancel</Button>
|
||||||
|
<Button
|
||||||
|
color="blue"
|
||||||
|
onClick={async () => {
|
||||||
|
setConfirmModel(false);
|
||||||
|
const otp = await handleGenerateOtp();
|
||||||
|
setShowOtpField(true);
|
||||||
|
notifications.show({
|
||||||
|
title: "OTP Sent",
|
||||||
|
message: `Check your registered device for OTP`,
|
||||||
|
color: "green",
|
||||||
|
autoClose: 5000,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Confirm
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Modal>
|
||||||
|
{/* main content */}
|
||||||
<Paper shadow="sm" radius="md" p="md" withBorder h={400}>
|
<Paper shadow="sm" radius="md" p="md" withBorder h={400}>
|
||||||
<Title order={3} mb="md">
|
<Title order={3} mb="md">
|
||||||
Quick Pay
|
Quick Pay
|
||||||
@@ -268,7 +303,6 @@ export default function QuickPay() {
|
|||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
|
|
||||||
{bankType === "own" ? (
|
{bankType === "own" ? (
|
||||||
<ScrollArea style={{ flex: 1 }}>
|
|
||||||
<div style={{ maxHeight: "320px", overflowY: "auto" }}>
|
<div style={{ maxHeight: "320px", overflowY: "auto" }}>
|
||||||
<Stack gap="xs">
|
<Stack gap="xs">
|
||||||
<Group grow>
|
<Group grow>
|
||||||
@@ -279,24 +313,26 @@ export default function QuickPay() {
|
|||||||
value={selectedAccNo}
|
value={selectedAccNo}
|
||||||
onChange={setSelectedAccNo}
|
onChange={setSelectedAccNo}
|
||||||
withAsterisk
|
withAsterisk
|
||||||
disabled={isVisibilityLocked}
|
readOnly={isVisibilityLocked}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Beneficiary Account No"
|
label="Payee Account No"
|
||||||
value={beneficiaryAcc}
|
value={showPayeeAcc ? beneficiaryAcc : getFullMaskedAccount(beneficiaryAcc)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = e.currentTarget.value;
|
const value = e.currentTarget.value;
|
||||||
if (/^\d*$/.test(value)) {
|
if (/^\d*$/.test(value)) {
|
||||||
setBeneficiaryAcc(value);
|
setBeneficiaryAcc(value);
|
||||||
|
setShowPayeeAcc(true);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onBlur={() => setShowPayeeAcc(false)}
|
||||||
|
onFocus={() => setShowPayeeAcc(true)}
|
||||||
withAsterisk
|
withAsterisk
|
||||||
disabled={isVisibilityLocked}
|
readOnly={isVisibilityLocked}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Confirm Beneficiary Account No"
|
label="Confirm Payee Account No"
|
||||||
value={confirmBeneficiaryAcc}
|
value={confirmBeneficiaryAcc}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = e.currentTarget.value;
|
const value = e.currentTarget.value;
|
||||||
@@ -304,23 +340,29 @@ export default function QuickPay() {
|
|||||||
setConfirmBeneficiaryAcc(value);
|
setConfirmBeneficiaryAcc(value);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onCopy={(e) => e.preventDefault()}
|
// onCopy={(e) => e.preventDefault()}
|
||||||
onPaste={(e) => e.preventDefault()}
|
// onPaste={(e) => e.preventDefault()}
|
||||||
onCut={(e) => e.preventDefault()}
|
// onCut={(e) => e.preventDefault()}
|
||||||
withAsterisk
|
withAsterisk
|
||||||
disabled={isVisibilityLocked}
|
readOnly={isVisibilityLocked}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
|
<Group justify="space-between" >
|
||||||
<Group align="center" gap="sm">
|
<Text size="xs" c="green" style={{ visibility: selectedAccount ? "visible" : "hidden" }}>Available Balance :
|
||||||
<Button variant="filled" color="blue" onClick={handleValidate}>
|
{selectedAccount ? selectedAccount.stAvailableBalance : 0}
|
||||||
Validate
|
</Text>
|
||||||
</Button>
|
<Group justify="center">
|
||||||
{validationStatus === "success" && <Text c="green">{beneficiaryName}</Text>}
|
{validationStatus === "error" && <Text size="sm" fw={700} ta="right" c="red">{beneficiaryName}</Text>}
|
||||||
{validationStatus === "error" && <Text c="red">{beneficiaryName}</Text>}
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Group grow>
|
<Group grow>
|
||||||
|
<TextInput
|
||||||
|
label="Payee Name"
|
||||||
|
value={validationStatus === "success" && beneficiaryName ? beneficiaryName : ""}
|
||||||
|
// disabled
|
||||||
|
readOnly
|
||||||
|
/>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
label="Beneficiary A/c Type"
|
label="Beneficiary A/c Type"
|
||||||
placeholder="Select type"
|
placeholder="Select type"
|
||||||
@@ -328,6 +370,7 @@ export default function QuickPay() {
|
|||||||
value={beneficiaryType}
|
value={beneficiaryType}
|
||||||
onChange={setBeneficiaryType}
|
onChange={setBeneficiaryType}
|
||||||
withAsterisk
|
withAsterisk
|
||||||
|
readOnly={showOtpField}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -335,7 +378,11 @@ export default function QuickPay() {
|
|||||||
type="number"
|
type="number"
|
||||||
value={amount}
|
value={amount}
|
||||||
onChange={(e) => setAmount(e.currentTarget.value)}
|
onChange={(e) => setAmount(e.currentTarget.value)}
|
||||||
|
error={
|
||||||
|
selectedAccount && Number(amount) > Number(selectedAccount.stAvailableBalance) ?
|
||||||
|
"Amount exceeds available balance" : false}
|
||||||
withAsterisk
|
withAsterisk
|
||||||
|
readOnly={showOtpField}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -344,9 +391,21 @@ export default function QuickPay() {
|
|||||||
value={remarks}
|
value={remarks}
|
||||||
onChange={(e) => setRemarks(e.currentTarget.value)}
|
onChange={(e) => setRemarks(e.currentTarget.value)}
|
||||||
withAsterisk
|
withAsterisk
|
||||||
|
readOnly={showOtpField}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
|
<Group grow>
|
||||||
|
{showOtpField && (
|
||||||
|
<TextInput
|
||||||
|
label="OTP"
|
||||||
|
placeholder="Enter OTP"
|
||||||
|
type="otp"
|
||||||
|
value={otp}
|
||||||
|
onChange={(e) => setOtp(e.currentTarget.value)}
|
||||||
|
withAsterisk
|
||||||
|
disabled={showTxnPassword}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{showTxnPassword && (
|
{showTxnPassword && (
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Transaction Password"
|
label="Transaction Password"
|
||||||
@@ -357,18 +416,12 @@ export default function QuickPay() {
|
|||||||
withAsterisk
|
withAsterisk
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
</Group>
|
||||||
{showOtpField && (
|
|
||||||
<TextInput
|
|
||||||
label="OTP"
|
|
||||||
placeholder="Enter OTP"
|
|
||||||
value={otp}
|
|
||||||
onChange={(e) => setOtp(e.currentTarget.value)}
|
|
||||||
withAsterisk
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Group justify="flex-start">
|
<Group justify="flex-start">
|
||||||
|
<Button variant="filled" color="blue" onClick={handleValidate} disabled={validationStatus === "success"}>
|
||||||
|
Validate
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="filled"
|
variant="filled"
|
||||||
color="blue"
|
color="blue"
|
||||||
@@ -376,17 +429,17 @@ export default function QuickPay() {
|
|||||||
loading={isSubmitting}
|
loading={isSubmitting}
|
||||||
disabled={validationStatus !== "success"}
|
disabled={validationStatus !== "success"}
|
||||||
>
|
>
|
||||||
{showOtpField ? "Proceed to Pay" : "Proceed"}
|
{!showTxnPassword && showOtpField ? "Validate the OTP" : showTxnPassword ? "Proceed to Pay" : "Proceed"}
|
||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
</Stack>
|
</Stack>
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
|
||||||
) : (
|
) : (
|
||||||
<Text size="lg" mt="md">
|
<Text size="lg" mt="md">
|
||||||
hii
|
hii
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</Paper>
|
</Paper>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
10
src/app/OTPGenerator.ts
Normal file
10
src/app/OTPGenerator.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export function generateOTP(length: number) {
|
||||||
|
const digits = '0123456789';
|
||||||
|
let otp = '';
|
||||||
|
otp += digits[Math.floor(Math.random() * 9)+1]; //first digit cannot be zero
|
||||||
|
for (let i = 1; i < length; i++) {
|
||||||
|
otp += digits[Math.floor(Math.random() * digits.length)];
|
||||||
|
}
|
||||||
|
// console.log("OTP generate :",otp);
|
||||||
|
return otp;
|
||||||
|
}
|
Reference in New Issue
Block a user