Exploring Customer Deletion Page
Overview
The Customer Delete Page is a part of the Bank Frontend that allows users to remove customer records from the system. It provides a user-friendly interface for bank tellers to manage customer data efficiently.
How to Use the Customer Delete Page
To delete a customer, the user must enter the customer number and submit the request. The page retrieves the customer details and associated accounts using RESTful API calls. If the customer has no associated accounts, the deletion process proceeds, and the customer is removed from the database. If the customer has associated accounts, the user is notified, and the deletion process is halted. The page provides feedback to the user, such as confirmation messages for successful deletions or error messages if the deletion fails.
The handleSubmitButtonClick
async function handleSubmitButtonClick(){
let searchQuery = searchCustomerValue;
await getCustomerByNum(searchQuery)
.then(display())
}
Main Functions
The main functions involved in the Customer Delete Page include CustomerDeletePage
getCustomerByNum
deleteCustomer
deleteAccount
CustomerDeletePage
CustomerDeletePage
The CustomerDeletePage
The CustomerDeletePage
const CustomerDeletePage = () => {
/**
* States to store isOpened value of the table and the value the user has entered to search with
*/
const [isOpened, setIsOpened] = useState(false);
var [searchCustomerValue, setSearchCustomerValue] = useState("")
const [customerDetailsRows, setRows] = useState([]);
const [accountDetailsRows, setAccountRows] = useState([]);
const [isNoResultsModalOpen, setIsNoResultsModalOpen] = useState(false)
function handleCustomerNumberInput(e){
setSearchCustomerValue(e.target.value)
}
function display() {
setIsOpened(wasOpened => !wasOpened);
}
function displayNoResultsModal(){
setIsNoResultsModalOpen(wasOpened => !wasOpened)
getCustomerByNum
getCustomerByNum
The getCustomerByNum
The getCustomerByNum
/**
* Finds the customer using the customerNumber entered by the user and creates an array from the server response
* customerDetailsRows' state is set to this array
*/
async function getCustomerByNum(searchQuery) {
let responseData;
let rowBuild = [];
await axios
.get(process.env.REACT_APP_CUSTOMER_URL + `/${searchQuery}`)
.then(response => {
responseData = response.data;
try {
let row;
let formattedDOB = getDay(responseData.dateOfBirth) + "-" + getMonth(responseData.dateOfBirth) + "-" + getYear(responseData.dateOfBirth)
let formattedReviewDate = getDay(responseData.customerCreditScoreReviewDate) + "-" + getMonth(responseData.customerCreditScoreReviewDate) +
"-" + getYear(responseData.customerCreditScoreReviewDate)
row = {
id: parseInt(responseData.id).toString(),
customerNumber: parseInt(responseData.id).toString(),
sortCode: responseData.sortCode,
customerName: responseData.customerName,
deleteCustomer
deleteCustomer
The deleteCustomer
The deleteCustomer
/**
* Checks that a customer has no outstanding accounts and then deletes the customer
* If the customer still has accounts or the delete fails a failure modal is shown, else a success modal is shown
*/
async function deleteCustomer(row) {
let customerNumber = row.cells[0].value
let responseData;
let howManyAccountsData;
try {
await axios
.get(process.env.REACT_APP_ACCOUNT_URL + `/retrieveByCustomerNumber/${customerNumber}`)
.then(response => {
howManyAccountsData = response.data
})
let numberOfAccounts = howManyAccountsData.numberOfAccounts
if (parseInt(numberOfAccounts) === 0) {
await axios
.delete(process.env.REACT_APP_CUSTOMER_URL + `/${customerNumber}`)
.then(response => {
responseData = response.data
displayModal()
deleteAccount
deleteAccount
The deleteAccount
The deleteAccount
/**
* Deletes the account from a given row
*/
async function deleteAccount(row) {
let accountNumber = row.accountNumber
let responseData;
try {
await axios
.delete(process.env.REACT_APP_ACCOUNT_URL + `/${accountNumber}`)
.then(response => {
responseData = response.data
})
displayAccountModal()
displaySuccessfulAccountDeleteModal()
} catch (e) {
console.log(e)
displayAccountModal()
displayUnableDeleteModal()
}
}
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human