feat: confirmation popup for Action Icon in view Beneficiary,

This commit is contained in:
2025-10-09 12:46:14 +05:30
parent 75a4e9199b
commit 917a17d826
3 changed files with 76 additions and 6 deletions

View File

@@ -390,9 +390,9 @@ export default function AddBeneficiaryOthers() {
maxLength={17}
readOnly={isVisibilityLocked}
withAsterisk
// onCopy={(e) => e.preventDefault()}
// onPaste={(e) => e.preventDefault()}
// onCut={(e) => e.preventDefault()}
onCopy={(e) => e.preventDefault()}
onPaste={(e) => e.preventDefault()}
onCut={(e) => e.preventDefault()}
/>
{validationStatus === "error" && (
@@ -454,7 +454,7 @@ export default function AddBeneficiaryOthers() {
maxLength={6}
disabled={otpVerified}
withAsterisk
style={{ flex: 1 }}
style={{ flex: 1 }}
/>
{!otpVerified && (

View File

@@ -1,7 +1,7 @@
"use client";
import React, { useEffect, useState } from "react";
import { Center, Group, Loader, Paper, ScrollArea, Table, Text, Title } from "@mantine/core";
import { Center, Group, Loader, Paper, ScrollArea, Table, Text, Title, TextInput, Button, } from "@mantine/core";
import { notifications } from "@mantine/notifications";
import { useRouter } from "next/navigation";
import Image from "next/image";
@@ -68,6 +68,63 @@ export default function ViewBeneficiary() {
}
if (!authorized) return null;
//add delete beneficiary
async function handleDeleteBeneficiary(accountNo: string) {
const isConfirmed = window.confirm("Are you sure you want to delete this beneficiary?");
if (!isConfirmed) return;
try {
const token = localStorage.getItem("access_token");
// Step 1: generate OTP
await fetch("/api/otp/generate", {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
});
const otp = prompt("An OTP has been sent to your registered number. Please enter it:");
if (!otp) return; // cancelled
// Step 2: verify OTP
const verify = await fetch("/api/otp/verify", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({ otp }),
});
if (!verify.ok) {
alert("Invalid OTP!");
return;
}
// Step 3: delete beneficiary
const res = await fetch(`/api/beneficiary/${accountNo}`, {
method: "DELETE",
headers: { Authorization: `Bearer ${token}` },
});
if (res.ok) {
setBeneficiaries((prev) => prev.filter((b) => b.accountNo !== accountNo));
alert("Beneficiary deleted successfully.");
} else {
alert("Error deleting beneficiary.");
}
} catch (err) {
alert("Something went wrong. Please try again.");
}
}
//add delete beneficiary
return (
<Paper shadow="sm" radius="md" p="md" withBorder h={400}>
<Title order={3} mb="md">My Beneficiaries</Title>
@@ -105,7 +162,16 @@ export default function ViewBeneficiary() {
<Table.Td>{b.name}</Table.Td>
<Table.Td>{b.accountType}</Table.Td>
<Table.Td style={{ textAlign: "center" }}>{b.ifscCode}</Table.Td>
<Table.Td style={{ textAlign: "center" }}><IconTrash color="red" /></Table.Td>
{/* <Table.Td style={{ textAlign: "center" }}><IconTrash color="red" /></Table.Td> */}
<Table.Td style={{ textAlign: "center" }}>
<IconTrash
color="red"
style={{ cursor: "pointer" }}
onClick={() => handleDeleteBeneficiary(b.accountNo)}
/>
</Table.Td>
</Table.Tr>
))}
</Table.Tbody>

View File

@@ -304,6 +304,10 @@ export default function ChangePassword() {
withAsterisk
rightSection={icon}
readOnly={step !== "form"}
onCopy={(e) => e.preventDefault()}
onPaste={(e) => e.preventDefault()}
onCut={(e) => e.preventDefault()}
/>
{/* Captcha */}