You are on page 1of 1

const handleReject = (clientId) => {

const client = clients.find(client => client.id === clientId);


const clientName = client.username; // Assuming 'username' holds the client
name
const clientEmail = client.id; // Assuming 'email' holds the client email

setStatus({ ...status, [clientId]: 'Rejected' });


fetch('http://localhost:5008/send-rejection-email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ client_name: clientName, client_email: clientEmail
}),
})
.then(response => {
if (response.ok) {
console.log('Rejection email sent successfully');
setTimeout(() => {
setStatus({ ...status, [clientId]: null });
removeClient(clientId);
}, 2000);
} else {
console.error('Failed to send rejection email');
setStatus({ ...status, [clientId]: null });
}
})
.catch(error => {
console.error('Error sending rejection email:', error);
setStatus({ ...status, [clientId]: null });
});
};

const removeClient = (clientId) => {


remove(ref(database, `Customer/${clientId}`))
.then(() => {
console.log("Customer data deleted successfully");
})
.catch((error) => {
console.error("Error deleting customer data: ", error);
});
};

You might also like