refactor: Update source code with the NPCI and CBS API
@@ -1,34 +1,19 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { TextInput, Button, Grid, Text, PasswordInput } from '@mantine/core';
|
import { TextInput, Button, Grid, Text, PasswordInput,Loader,Group, Select, Stack } from '@mantine/core';
|
||||||
import { notifications } from '@mantine/notifications';
|
import { notifications } from '@mantine/notifications';
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
const MockOthersAccountValidation =
|
|
||||||
[
|
|
||||||
{
|
|
||||||
'stBenAccountNo': '50077736834',
|
|
||||||
'stBenName': 'Ram Patnayak',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'stBenAccountNo': '50088836834',
|
|
||||||
'stBenName': 'Sumit Ghosh',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'stBenAccountNo': '21112076570',
|
|
||||||
'stBenName': 'Mr Sumit Ghosh',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function AddBeneficiaryOthers() {
|
export default function AddBeneficiaryOthers() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const [bankName, setBankName] = useState('');
|
const [bankName, setBankName] = useState('');
|
||||||
const [ifsccode, setIfsccode] = useState('');
|
const [ifsccode, setIfsccode] = useState('');
|
||||||
const [branchName, setBranchName] = useState('');
|
const [branchName, setBranchName] = useState('');
|
||||||
const [accountNo, setAccountNo] = useState('');
|
const [accountNo, setAccountNo] = useState('');
|
||||||
const [confirmAccountNo, setConfirmAccountNo] = useState('');
|
const [confirmAccountNo, setConfirmAccountNo] = useState('');
|
||||||
|
const [beneficiaryType, setBeneficiaryType] = useState<string | null>(null);
|
||||||
const [nickName, setNickName] = useState('');
|
const [nickName, setNickName] = useState('');
|
||||||
const [beneficiaryName, setBeneficiaryName] = useState<string | null>(null);
|
const [beneficiaryName, setBeneficiaryName] = useState<string | null>(null);
|
||||||
const [otp, setOtp] = useState('');
|
const [otp, setOtp] = useState('');
|
||||||
@@ -38,7 +23,6 @@ export default function AddBeneficiaryOthers() {
|
|||||||
const [validationStatus, setValidationStatus] = useState<'success' | 'error' | null>(null);
|
const [validationStatus, setValidationStatus] = useState<'success' | 'error' | null>(null);
|
||||||
const [isVisibilityLocked, setIsVisibilityLocked] = useState(false);
|
const [isVisibilityLocked, setIsVisibilityLocked] = useState(false);
|
||||||
const [showPayeeAcc, setShowPayeeAcc] = useState(true);
|
const [showPayeeAcc, setShowPayeeAcc] = useState(true);
|
||||||
|
|
||||||
const getFullMaskedAccount = (acc: string) => { return "X".repeat(acc.length); };
|
const getFullMaskedAccount = (acc: string) => { return "X".repeat(acc.length); };
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -99,7 +83,7 @@ export default function AddBeneficiaryOthers() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const validateAndSendOtp = async () => {
|
const validateAndSendOtp = async () => {
|
||||||
if (!bankName || !ifsccode || !branchName || !accountNo || !confirmAccountNo) {
|
if (!bankName || !ifsccode || !branchName || !accountNo || !confirmAccountNo || !beneficiaryType) {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
withBorder: true,
|
withBorder: true,
|
||||||
color: "red",
|
color: "red",
|
||||||
@@ -147,13 +131,9 @@ export default function AddBeneficiaryOthers() {
|
|||||||
}
|
}
|
||||||
// Validation for now
|
// Validation for now
|
||||||
try {
|
try {
|
||||||
// const matched = MockOthersAccountValidation.find(
|
setLoading(true);
|
||||||
// (entry) => entry.stBenAccountNo === accountNo
|
|
||||||
// );
|
|
||||||
|
|
||||||
const token = localStorage.getItem("access_token");
|
const token = localStorage.getItem("access_token");
|
||||||
const response = await fetch(
|
const response = await fetch(`/api/beneficiary/validate/outside-bank?accountNo=${accountNo}&ifscCode=${ifsccode}&remitterName=""`,
|
||||||
`http://localhost:8080/api/beneficiary/validate/outside-bank?accountNo=${accountNo}&ifscCode=${ifsccode}&remitterName=""`,
|
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -163,7 +143,6 @@ export default function AddBeneficiaryOthers() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (response.ok && data?.name) {
|
if (response.ok && data?.name) {
|
||||||
setBeneficiaryName(data.name);
|
setBeneficiaryName(data.name);
|
||||||
setValidationStatus("success");
|
setValidationStatus("success");
|
||||||
@@ -189,9 +168,23 @@ export default function AddBeneficiaryOthers() {
|
|||||||
setBeneficiaryName("Something went wrong");
|
setBeneficiaryName("Something went wrong");
|
||||||
setValidationStatus("error");
|
setValidationStatus("error");
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const verifyOtp = () => {
|
const verifyOtp = () => {
|
||||||
|
if (!otp) {
|
||||||
|
notifications.show({
|
||||||
|
withBorder: true,
|
||||||
|
color: "Red",
|
||||||
|
title: "Null Field",
|
||||||
|
message: "Please Enter Valid OTP",
|
||||||
|
autoClose: 5000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (otp === generatedOtp) {
|
if (otp === generatedOtp) {
|
||||||
setOtpVerified(true);
|
setOtpVerified(true);
|
||||||
notifications.show({
|
notifications.show({
|
||||||
@@ -211,20 +204,70 @@ export default function AddBeneficiaryOthers() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const AddBen = () => {
|
const AddBen = async () => {
|
||||||
notifications.show({
|
try {
|
||||||
withBorder: true,
|
const token = localStorage.getItem("access_token");
|
||||||
color: "green",
|
const response = await fetch(`/api/beneficiary`, {
|
||||||
title: "Beneficiary Added",
|
method: "POST",
|
||||||
message: "Beneficiary added successfully.",
|
headers: {
|
||||||
autoClose: 5000,
|
"Content-Type": "application/json",
|
||||||
});
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
accountNo: accountNo,
|
||||||
|
ifscCode: ifsccode,
|
||||||
|
accountType: beneficiaryType,
|
||||||
|
name: beneficiaryName
|
||||||
|
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
if (response.ok) {
|
||||||
|
notifications.show({
|
||||||
|
withBorder: true,
|
||||||
|
color: "green",
|
||||||
|
title: "Added",
|
||||||
|
message: "Beneficiary Added successfully",
|
||||||
|
autoClose: 5000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
notifications.show({
|
||||||
|
withBorder: true,
|
||||||
|
color: "Red",
|
||||||
|
title: "Error",
|
||||||
|
message: data?.error,
|
||||||
|
autoClose: 5000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
notifications.show({
|
||||||
|
title: "Error",
|
||||||
|
message: "Something went wrong",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
finally{
|
||||||
|
setBankName('');
|
||||||
|
setBranchName('');
|
||||||
|
setIfsccode('');
|
||||||
|
setAccountNo('');
|
||||||
|
setConfirmAccountNo('');
|
||||||
|
setBeneficiaryName('');
|
||||||
|
setNickName('');
|
||||||
|
setBeneficiaryType(null);
|
||||||
|
setIsVisibilityLocked(false);
|
||||||
|
setOtpSent(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!authorized) return null;
|
if (!authorized) return null;
|
||||||
return (
|
return (
|
||||||
<Grid gutter="md">
|
<Grid gutter="md" style={{padding:'5px'}}>
|
||||||
|
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="IFSC Code"
|
label="IFSC Code"
|
||||||
@@ -236,34 +279,30 @@ export default function AddBeneficiaryOthers() {
|
|||||||
setIfsccode(val);
|
setIfsccode(val);
|
||||||
}}
|
}}
|
||||||
maxLength={11}
|
maxLength={11}
|
||||||
required
|
withAsterisk
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Bank Name"
|
label="Bank Name"
|
||||||
placeholder="Enter bank"
|
|
||||||
value={bankName}
|
value={bankName}
|
||||||
disabled
|
disabled
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
let val = e.currentTarget.value.replace(/[^A-Za-z ]/g, "");
|
let val = e.currentTarget.value.replace(/[^A-Za-z ]/g, "");
|
||||||
setBankName(val.slice(0, 100));
|
setBankName(val.slice(0, 100));
|
||||||
}}
|
}}
|
||||||
required
|
withAsterisk
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Branch Name"
|
label="Branch Name"
|
||||||
value={branchName}
|
value={branchName}
|
||||||
disabled
|
disabled
|
||||||
maxLength={100}
|
maxLength={100}
|
||||||
required
|
withAsterisk
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Beneficiary Account Number"
|
label="Beneficiary Account Number"
|
||||||
@@ -280,11 +319,9 @@ export default function AddBeneficiaryOthers() {
|
|||||||
onFocus={() => setShowPayeeAcc(true)}
|
onFocus={() => setShowPayeeAcc(true)}
|
||||||
readOnly={isVisibilityLocked}
|
readOnly={isVisibilityLocked}
|
||||||
maxLength={17}
|
maxLength={17}
|
||||||
// disabled={isVisibilityLocked}
|
withAsterisk
|
||||||
required
|
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Confirm Beneficiary Account Number"
|
label="Confirm Beneficiary Account Number"
|
||||||
@@ -297,12 +334,11 @@ export default function AddBeneficiaryOthers() {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
maxLength={17}
|
maxLength={17}
|
||||||
// disabled={isVisibilityLocked}
|
|
||||||
readOnly={isVisibilityLocked}
|
readOnly={isVisibilityLocked}
|
||||||
required
|
withAsterisk
|
||||||
onCopy={(e) => e.preventDefault()}
|
// onCopy={(e) => e.preventDefault()}
|
||||||
onPaste={(e) => e.preventDefault()}
|
// onPaste={(e) => e.preventDefault()}
|
||||||
onCut={(e) => e.preventDefault()}
|
// onCut={(e) => e.preventDefault()}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{validationStatus === "error" && (
|
{validationStatus === "error" && (
|
||||||
@@ -311,16 +347,17 @@ export default function AddBeneficiaryOthers() {
|
|||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<TextInput
|
<Select
|
||||||
label="Nick Name (Optional)"
|
label="Beneficiary Account Type"
|
||||||
placeholder="Enter nickname (optional)"
|
placeholder="Select type"
|
||||||
value={nickName}
|
data={["Savings", "Current"]}
|
||||||
onChange={(e) => setNickName(e.currentTarget.value)}
|
value={beneficiaryType}
|
||||||
|
onChange={setBeneficiaryType}
|
||||||
|
readOnly={isVisibilityLocked}
|
||||||
|
withAsterisk
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Beneficiary Name"
|
label="Beneficiary Name"
|
||||||
@@ -330,14 +367,28 @@ export default function AddBeneficiaryOthers() {
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
<Grid.Col span={4}>
|
||||||
|
<TextInput
|
||||||
|
label="Nick Name (Optional)"
|
||||||
|
placeholder="Enter nickname (optional)"
|
||||||
|
value={nickName}
|
||||||
|
onChange={(e) => setNickName(e.currentTarget.value)}
|
||||||
|
|
||||||
|
/>
|
||||||
|
</Grid.Col>
|
||||||
{!otpSent && (
|
{!otpSent && (
|
||||||
<Grid.Col>
|
<Grid.Col >
|
||||||
<Button onClick={validateAndSendOtp}>Validate</Button>
|
<Group gap="sm">
|
||||||
|
<Button onClick={validateAndSendOtp} disabled={loading}>Validate</Button>
|
||||||
|
{loading && (
|
||||||
|
<>
|
||||||
|
<Loader size='sm' type="bars"></Loader>
|
||||||
|
<Text>Looking for Beneficiary Name</Text>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{otpSent && (
|
{otpSent && (
|
||||||
<>
|
<>
|
||||||
<Grid.Col span={3}>
|
<Grid.Col span={3}>
|
||||||
@@ -347,15 +398,13 @@ export default function AddBeneficiaryOthers() {
|
|||||||
value={otp}
|
value={otp}
|
||||||
onChange={(e) => setOtp(e.currentTarget.value)}
|
onChange={(e) => setOtp(e.currentTarget.value)}
|
||||||
maxLength={6}
|
maxLength={6}
|
||||||
disabled={otpVerified} // ✅ Disable after verified
|
disabled={otpVerified} //Disable after verified
|
||||||
/>
|
/>
|
||||||
</Grid.Col >
|
</Grid.Col >
|
||||||
<Grid.Col >
|
<Grid.Col >
|
||||||
{!otpVerified ? (
|
{!otpVerified ? (
|
||||||
<Button onClick={verifyOtp}>Validate OTP</Button>
|
<Button onClick={verifyOtp}>Validate OTP</Button>
|
||||||
) : (
|
) : (
|
||||||
|
|
||||||
|
|
||||||
<Button color="blue" size="sm" onClick={AddBen}>
|
<Button color="blue" size="sm" onClick={AddBen}>
|
||||||
Add
|
Add
|
||||||
</Button>
|
</Button>
|
||||||
@@ -364,8 +413,6 @@ export default function AddBeneficiaryOthers() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -192,14 +192,14 @@ const AddBeneficiary: React.FC = () => {
|
|||||||
<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">Add Beneficiary</Title>
|
<Title order={3} mb="md">Add Beneficiary</Title>
|
||||||
|
|
||||||
<Radio.Group value={bankType} onChange={setBankType} name="bankType" withAsterisk mb="md">
|
{/* <Radio.Group value={bankType} onChange={setBankType} name="bankType" withAsterisk mb="md">
|
||||||
<Group justify="center">
|
<Group justify="center">
|
||||||
<Radio value="own" label="Own Bank" />
|
<Radio value="own" label="Own Bank" />
|
||||||
<Radio value="outside" label="Outside Bank" />
|
<Radio value="outside" label="Outside Bank" />
|
||||||
</Group>
|
</Group>
|
||||||
</Radio.Group>
|
</Radio.Group> */}
|
||||||
|
|
||||||
{bankType === "own" ? (
|
{/* {bankType === "own" ? (
|
||||||
<Grid gutter="md">
|
<Grid gutter="md">
|
||||||
<Grid.Col span={4}>
|
<Grid.Col span={4}>
|
||||||
<Select
|
<Select
|
||||||
@@ -310,11 +310,11 @@ const AddBeneficiary: React.FC = () => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
) : (
|
) : ( */}
|
||||||
<Grid gutter="md">
|
<Grid gutter="md">
|
||||||
<AddBeneficiaryOthers />
|
<AddBeneficiaryOthers />
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
{/* )} */}
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -473,7 +473,6 @@ export default function QuickPay() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Group justify="flex-start">
|
<Group justify="flex-start">
|
||||||
<Button variant="filled" color="blue" onClick={handleValidate} disabled={validationStatus === "success"}>
|
<Button variant="filled" color="blue" onClick={handleValidate} disabled={validationStatus === "success"}>
|
||||||
Validate
|
Validate
|
||||||
|
@@ -14,43 +14,13 @@ interface accountData {
|
|||||||
custname: string;
|
custname: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MockBeneficiaryData =
|
|
||||||
[
|
|
||||||
{
|
|
||||||
'stBankName': 'Kangra Central Co-operative Bank',
|
|
||||||
'stBenAccountNo': '50077736845',
|
|
||||||
'stBenName': 'RAJAT MAHARANA',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'stBankName': 'Kangra Central Co-operative Bank',
|
|
||||||
'stBenAccountNo': '50077742351',
|
|
||||||
'stBenName': 'RAJAT MAHARANA',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'stBankName': 'Kangra Central Co-operative Bank',
|
|
||||||
'stBenAccountNo': '20002076570',
|
|
||||||
'stBenName': 'Mr. PUSHKAR . SHARMA',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'stBankName': 'State Bank of India',
|
|
||||||
'stBenAccountNo': '50077742361',
|
|
||||||
'stIFSC': 'SBIN0004567',
|
|
||||||
'stBenName': 'Sachin Sharma',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'stBankName': 'ICICI',
|
|
||||||
'stBenAccountNo': '90088842361',
|
|
||||||
'stIFSC': 'ICICI0004567',
|
|
||||||
'stBenName': 'Eshika Paul',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function SendToBeneficiaryOwn() {
|
export default function SendToBeneficiaryOwn() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [bankType, setBankType] = useState("own");
|
const [bankType, setBankType] = useState("own");
|
||||||
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
||||||
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 [beneficiaryData, setBeneficiaryData] = useState<any[]>([]);
|
||||||
const [beneficiaryAcc, setBeneficiaryAcc] = useState<string | null>(null);
|
const [beneficiaryAcc, setBeneficiaryAcc] = useState<string | null>(null);
|
||||||
const [beneficiaryName, setBeneficiaryName] = useState<string | null>(null);
|
const [beneficiaryName, setBeneficiaryName] = useState<string | null>(null);
|
||||||
const [beneficiaryType, setBeneficiaryType] = useState<string | null>(null);
|
const [beneficiaryType, setBeneficiaryType] = useState<string | null>(null);
|
||||||
@@ -77,25 +47,35 @@ export default function SendToBeneficiaryOwn() {
|
|||||||
label: `${acc.stAccountNo} (${acc.stAccountType})`,
|
label: `${acc.stAccountNo} (${acc.stAccountType})`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const benAccountOption = MockBeneficiaryData.filter((ben_acc) =>
|
const FetchBeneficiaryDetails = async () => {
|
||||||
bankType === 'own' ? ben_acc.stBankName === 'Kangra Central Co-operative Bank' : true)
|
try {
|
||||||
.map((ben_acc) => ({
|
const token = localStorage.getItem("access_token");
|
||||||
value: ben_acc.stBenAccountNo,
|
const response = await fetch("/api/beneficiary", {
|
||||||
label: `${ben_acc.stBenAccountNo}-${ben_acc.stBenName}`,
|
method: "GET",
|
||||||
|
headers: {
|
||||||
}));
|
"Content-Type": "application/json",
|
||||||
const handleBeneficiary = (benAcc: string | null) => {
|
Authorization: `Bearer ${token}`,
|
||||||
if (benAcc) {
|
},
|
||||||
setBeneficiaryAcc(benAcc);
|
});
|
||||||
const selected = MockBeneficiaryData.find((item) => item.stBenAccountNo === benAcc);
|
const data = await response.json();
|
||||||
if (selected)
|
console.log(data);
|
||||||
setBeneficiaryName(selected.stBenName);
|
if (response.ok && Array.isArray(data)) {
|
||||||
|
setBeneficiaryData(data);
|
||||||
|
} else {
|
||||||
|
notifications.show({
|
||||||
|
title: "Error",
|
||||||
|
message: "Unable to fetch beneficiary list",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
notifications.show({
|
||||||
|
title: "Error",
|
||||||
|
message: "Something went wrong while fetching beneficiaries",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
};
|
||||||
setBeneficiaryAcc('');
|
|
||||||
setBeneficiaryName('');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const FetchAccountDetails = async () => {
|
const FetchAccountDetails = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -136,9 +116,37 @@ export default function SendToBeneficiaryOwn() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (authorized) {
|
if (authorized) {
|
||||||
FetchAccountDetails();
|
FetchAccountDetails();
|
||||||
|
FetchBeneficiaryDetails();
|
||||||
}
|
}
|
||||||
}, [authorized]);
|
}, [authorized]);
|
||||||
|
|
||||||
|
const benAccountOption = beneficiaryData
|
||||||
|
.filter((ben) =>
|
||||||
|
bankType === "own" ? ben.ifscCode?.startsWith("KACE") : true
|
||||||
|
)
|
||||||
|
.map((ben) => ({
|
||||||
|
value: ben.accountNo,
|
||||||
|
label: `${ben.accountNo} - ${ben.name}`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const handleBeneficiary = (benAcc: string | null) => {
|
||||||
|
if (benAcc) {
|
||||||
|
setBeneficiaryAcc(benAcc);
|
||||||
|
const selected = beneficiaryData.find(
|
||||||
|
(item) => item.accountNo === benAcc
|
||||||
|
);
|
||||||
|
if (selected) {
|
||||||
|
setBeneficiaryName(selected.name);
|
||||||
|
setBeneficiaryType(selected.accountType);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setBeneficiaryAcc(null);
|
||||||
|
setBeneficiaryName(null);
|
||||||
|
setBeneficiaryType(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
async function handleProceed() {
|
async function handleProceed() {
|
||||||
if (!selectedAccNo || !beneficiaryAcc! || !beneficiaryName || !beneficiaryType || !amount || !remarks) {
|
if (!selectedAccNo || !beneficiaryAcc! || !beneficiaryName || !beneficiaryType || !amount || !remarks) {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
@@ -253,7 +261,6 @@ export default function SendToBeneficiaryOwn() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!authorized) return null;
|
if (!authorized) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal
|
<Modal
|
||||||
@@ -351,7 +358,6 @@ export default function SendToBeneficiaryOwn() {
|
|||||||
withAsterisk
|
withAsterisk
|
||||||
readOnly={showOtpField}
|
readOnly={showOtpField}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Amount"
|
label="Amount"
|
||||||
type="number"
|
type="number"
|
||||||
|
@@ -43,11 +43,11 @@ const MockBeneficiaryData =
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
export default function SendToBeneficiaryOthers() {
|
export default function SendToBeneficiaryOthers() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
||||||
const [accountData, setAccountData] = useState<accountData[]>([]);
|
const [accountData, setAccountData] = useState<accountData[]>([]);
|
||||||
|
const [beneficiaryData, setBeneficiaryData] = useState<any[]>([]);
|
||||||
const [selectedAccNo, setSelectedAccNo] = useState<string | null>(null);
|
const [selectedAccNo, setSelectedAccNo] = useState<string | null>(null);
|
||||||
const [beneficiaryAcc, setBeneficiaryAcc] = useState<string | null>(null);
|
const [beneficiaryAcc, setBeneficiaryAcc] = useState<string | null>(null);
|
||||||
const [beneficiaryName, setBeneficiaryName] = useState<string | null>(null);
|
const [beneficiaryName, setBeneficiaryName] = useState<string | null>(null);
|
||||||
@@ -70,31 +70,63 @@ export default function SendToBeneficiaryOthers() {
|
|||||||
setGenerateOtp(value);
|
setGenerateOtp(value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FetchBeneficiaryDetails = async () => {
|
||||||
|
try {
|
||||||
|
const token = localStorage.getItem("access_token");
|
||||||
|
const response = await fetch("/api/beneficiary", {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
console.log(data);
|
||||||
|
if (response.ok && Array.isArray(data)) {
|
||||||
|
setBeneficiaryData(data);
|
||||||
|
} else {
|
||||||
|
notifications.show({
|
||||||
|
title: "Error",
|
||||||
|
message: "Unable to fetch beneficiary list",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
notifications.show({
|
||||||
|
title: "Error",
|
||||||
|
message: "Something went wrong while fetching beneficiaries",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
const selectedAccount = accountData.find((acc) => acc.stAccountNo === selectedAccNo);
|
const selectedAccount = accountData.find((acc) => acc.stAccountNo === selectedAccNo);
|
||||||
const accountOptions = accountData.map((acc) => ({
|
const accountOptions = accountData.map((acc) => ({
|
||||||
value: acc.stAccountNo,
|
value: acc.stAccountNo,
|
||||||
label: `${acc.stAccountNo} (${acc.stAccountType})`,
|
label: `${acc.stAccountNo} (${acc.stAccountType})`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const benAccountOption = MockBeneficiaryData.filter((ben_acc) =>
|
const benAccountOption = beneficiaryData.
|
||||||
ben_acc.stBankName !== 'Kangra Central Co-operative Bank')
|
filter((ben) => !ben.ifscCode?.startsWith("KACE"))
|
||||||
.map((ben_acc) => ({
|
.map((ben) => ({
|
||||||
value: ben_acc.stBenAccountNo,
|
value: ben.accountNo,
|
||||||
label: ben_acc.stBenAccountNo,
|
label: `${ben.accountNo} - ${ben.name}`,
|
||||||
|
|
||||||
}));
|
}));
|
||||||
const handleBeneficiary = (benAcc: string | null) => {
|
|
||||||
if (benAcc) {
|
const handleBeneficiary = (ben: string | null) => {
|
||||||
setBeneficiaryAcc(benAcc);
|
if (ben) {
|
||||||
const selected = MockBeneficiaryData.find((item) => item.stBenAccountNo === benAcc);
|
setBeneficiaryAcc(ben);
|
||||||
if (selected)
|
const selected = beneficiaryData.find((item) => item.accountNo === ben && !item.ifscCode?.startsWith("KACE"));
|
||||||
setBeneficiaryName(selected.stBenName);
|
if (selected) {
|
||||||
setBeneficiaryIFSC(selected?.stIFSC ?? '');
|
setBeneficiaryName(selected.name);
|
||||||
}
|
setBeneficiaryIFSC(selected?.ifscCode ?? '');
|
||||||
else {
|
}
|
||||||
setBeneficiaryAcc('');
|
else {
|
||||||
setBeneficiaryName('');
|
setBeneficiaryAcc('');
|
||||||
setBeneficiaryIFSC('');
|
setBeneficiaryName('');
|
||||||
|
setBeneficiaryIFSC('');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +169,7 @@ export default function SendToBeneficiaryOthers() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (authorized) {
|
if (authorized) {
|
||||||
FetchAccountDetails();
|
FetchAccountDetails();
|
||||||
|
FetchBeneficiaryDetails();
|
||||||
}
|
}
|
||||||
}, [authorized]);
|
}, [authorized]);
|
||||||
|
|
||||||
|
@@ -1,13 +1,41 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Button, Group, Modal, Paper, Radio, ScrollArea, Select, Stack, Text, TextInput, Title } from "@mantine/core";
|
import { Center, Group, Loader, 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 Image, { StaticImageData } from "next/image";
|
||||||
|
import BOI from '@/app/image/bank_logo/BOI.jpg';
|
||||||
|
import hdfc from '@/app/image/bank_logo/hdfc.jpg';
|
||||||
|
import sbi from '@/app/image/bank_logo/sbi.jpg';
|
||||||
|
import icici from '@/app/image/bank_logo/icici.jpg'
|
||||||
|
import pnb from '@/app/image/bank_logo/pnb.jpg'
|
||||||
|
import axis from '@/app/image/bank_logo/axis.jpg'
|
||||||
|
import logo from '@/app/image/bank_logo/bank.jpg';
|
||||||
|
|
||||||
|
interface Beneficiary {
|
||||||
|
accountNo: string;
|
||||||
|
name: string;
|
||||||
|
accountType: string;
|
||||||
|
ifscCode: string;
|
||||||
|
bankName: string;
|
||||||
|
branchName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bankLogo: Record<string, StaticImageData> = {
|
||||||
|
"BANK OF INDIA": BOI,
|
||||||
|
"HDFC BANK LTD": hdfc,
|
||||||
|
"STATE BANK OF INDIA": sbi,
|
||||||
|
"ICICI BANK LTD": icici,
|
||||||
|
"PUNJAB NATIONAL BANK": pnb,
|
||||||
|
"AXIS BANK": axis
|
||||||
|
}
|
||||||
|
|
||||||
export default function ViewBeneficiary() {
|
export default function ViewBeneficiary() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
const [authorized, setAuthorized] = useState<boolean | null>(null);
|
||||||
|
const [beneficiaries, setBeneficiaries] = useState<Beneficiary[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const token = localStorage.getItem("access_token");
|
const token = localStorage.getItem("access_token");
|
||||||
@@ -18,13 +46,85 @@ export default function ViewBeneficiary() {
|
|||||||
setAuthorized(true);
|
setAuthorized(true);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchBeneficiaries = async () => {
|
||||||
|
try {
|
||||||
|
const token = localStorage.getItem("access_token");
|
||||||
|
const response = await fetch(`/api/beneficiary`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error("Failed to fetch beneficiaries");
|
||||||
|
const data = await response.json();
|
||||||
|
setBeneficiaries(data);
|
||||||
|
} catch (error) {
|
||||||
|
notifications.show({
|
||||||
|
title: "Error",
|
||||||
|
message: "Unable to fetch beneficiaries. Please try again later.",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchBeneficiaries();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<Center h="60vh">
|
||||||
|
<Loader size="lg" color="green" />
|
||||||
|
</Center>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!authorized) return null;
|
if (!authorized) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper shadow="sm" radius="md" p="md" withBorder h={400}>
|
<Paper shadow="sm" radius="md" p="md" withBorder h={400}>
|
||||||
<Text>View beneficiary feature coming soon.</Text>
|
<Title order={3} mb="md">My Beneficiaries</Title>
|
||||||
</Paper>
|
{beneficiaries.length === 0 ? (
|
||||||
|
<Text>No beneficiaries found.</Text>
|
||||||
|
) : (
|
||||||
|
<ScrollArea h={300} type="always">
|
||||||
|
<Table highlightOnHover withTableBorder stickyHeader style={{ borderCollapse: "collapse", width: "100%" }}>
|
||||||
|
<Table.Thead>
|
||||||
|
<Table.Tr style={{ backgroundColor: "#3385ff" }}>
|
||||||
|
<Table.Th>Bank</Table.Th>
|
||||||
|
<Table.Th>Account No</Table.Th>
|
||||||
|
<Table.Th>Name</Table.Th>
|
||||||
|
<Table.Th>Type</Table.Th>
|
||||||
|
<Table.Th>IFSC</Table.Th>
|
||||||
|
{/* <Table.Th>Branch</Table.Th> */}
|
||||||
|
</Table.Tr>
|
||||||
|
</Table.Thead>
|
||||||
|
<Table.Tbody>
|
||||||
|
{beneficiaries.map((b, i) => (
|
||||||
|
<Table.Tr key={i}>
|
||||||
|
<Table.Td>
|
||||||
|
<Group gap='sm'>
|
||||||
|
<Image
|
||||||
|
src={bankLogo[b.bankName] || logo}
|
||||||
|
alt={b.bankName}
|
||||||
|
width={20}
|
||||||
|
height={15}
|
||||||
|
/>
|
||||||
|
{b.bankName}
|
||||||
|
</Group>
|
||||||
|
</Table.Td>
|
||||||
|
<Table.Td style={{ textAlign: "right" }}>{b.accountNo}</Table.Td>
|
||||||
|
<Table.Td>{b.name}</Table.Td>
|
||||||
|
<Table.Td>{b.accountType}</Table.Td>
|
||||||
|
<Table.Td style={{ textAlign: "center" }}>{b.ifscCode}</Table.Td>
|
||||||
|
{/* <Table.Td>{b.branchName}</Table.Td> */}
|
||||||
|
</Table.Tr>
|
||||||
|
))}
|
||||||
|
</Table.Tbody>
|
||||||
|
</Table>
|
||||||
|
</ScrollArea>
|
||||||
|
)}
|
||||||
|
</Paper >
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -224,7 +224,7 @@ export default function Home() {
|
|||||||
</Box> */}
|
</Box> */}
|
||||||
<Stack>
|
<Stack>
|
||||||
<Text fw={700}> ** Book Balance includes uncleared effect.</Text>
|
<Text fw={700}> ** Book Balance includes uncleared effect.</Text>
|
||||||
<Text fw={700}> ** Click on the "Show Balance" to display balance for the Deposit and Loan account.</Text>
|
<Text fw={700}> ** Click on the "Show Balance"to display balance for the Deposit and Loan account.</Text>
|
||||||
{/* <Text fw={700}> ** Click on the "Get Statement" to display last 5 transactions.</Text> */}
|
{/* <Text fw={700}> ** Click on the "Get Statement" to display last 5 transactions.</Text> */}
|
||||||
<Text></Text>
|
<Text></Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
@@ -32,6 +32,17 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|||||||
'Authorization': `Bearer ${token}`
|
'Authorization': `Bearer ${token}`
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
notifications.show({
|
||||||
|
withBorder: true,
|
||||||
|
color: "red",
|
||||||
|
title: "Error",
|
||||||
|
message: "Internal Server Error",
|
||||||
|
autoClose: 5000,
|
||||||
|
});
|
||||||
|
localStorage.removeItem("access_token");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (response.ok && Array.isArray(data)) {
|
if (response.ok && Array.isArray(data)) {
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
|
BIN
src/app/image/bank_logo/BOI.jpg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
src/app/image/bank_logo/axis.jpg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
src/app/image/bank_logo/bank.jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
src/app/image/bank_logo/hdfc.jpg
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
src/app/image/bank_logo/icici.jpg
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
src/app/image/bank_logo/pnb.jpg
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
src/app/image/bank_logo/sbi.jpg
Normal file
After Width: | Height: | Size: 3.6 KiB |
@@ -84,39 +84,62 @@ export default function Login() {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await fetch('api/auth/login', {
|
try {
|
||||||
method: 'POST',
|
const response = await fetch('api/auth/login', {
|
||||||
headers: {
|
method: 'POST',
|
||||||
'Content-Type': 'application/json',
|
headers: {
|
||||||
},
|
'Content-Type': 'application/json',
|
||||||
body: JSON.stringify({
|
},
|
||||||
customerNo: CIF,
|
body: JSON.stringify({
|
||||||
password: psw,
|
customerNo: CIF,
|
||||||
}),
|
password: psw,
|
||||||
});
|
}),
|
||||||
const data = await response.json();
|
});
|
||||||
setIsLogging(true);
|
if (!response.ok) {
|
||||||
if (response.ok) {
|
notifications.show({
|
||||||
|
withBorder: true,
|
||||||
|
color: "red",
|
||||||
|
title: "Error",
|
||||||
|
message: "Internal Server Error",
|
||||||
|
autoClose: 5000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
console.log(data);
|
console.log(data);
|
||||||
const token = data.token;
|
setIsLogging(true);
|
||||||
localStorage.setItem("access_token", token);
|
if (response.ok) {
|
||||||
if (data.FirstTimeLogin === true) {
|
console.log(data);
|
||||||
router.push("/SetPassword")
|
const token = data.token;
|
||||||
|
localStorage.setItem("access_token", token);
|
||||||
|
if (data.FirstTimeLogin === true) {
|
||||||
|
router.push("/SetPassword")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
router.push("/home");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
router.push("/home");
|
setIsLogging(false);
|
||||||
|
notifications.show({
|
||||||
|
withBorder: true,
|
||||||
|
color: "red",
|
||||||
|
title: "Wrong User Id or Password",
|
||||||
|
message: "Wrong User Id or Password",
|
||||||
|
autoClose: 5000,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
catch (error: any) {
|
||||||
setIsLogging(false);
|
|
||||||
notifications.show({
|
notifications.show({
|
||||||
withBorder: true,
|
withBorder: true,
|
||||||
color: "red",
|
color: "red",
|
||||||
title: "Wrong User Id or Password",
|
title: "Error",
|
||||||
message: "Wrong User Id or Password",
|
message: "Internal Server Error,Please try again Later",
|
||||||
autoClose: 5000,
|
autoClose: 5000,
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|