profile payment update

This commit is contained in:
JaiPandey425 2025-12-05 17:47:58 +05:30
parent 3efcf99151
commit c0a89d3f69
5 changed files with 216 additions and 140 deletions

View File

@ -493,6 +493,47 @@ ipcMain.handle("get-adjustments-list", async (event, vaId: string) => {
});
ipcMain.handle("update-payment", async (event, data: Record<string, any>) => {
console.log("data-update-payment", data);
// Build userDetails object
const userDetails: Record<string, any> = {
paymentMethod: data.paymentMethod,
};
// Add payment-specific fields
if (data.paymentMethod === "wise" && data.wiseEmail) {
userDetails.wiseEmail = data.wiseEmail;
// Clear veemAccount when switching to wise
userDetails.veemAccount = "";
} else if (data.paymentMethod === "veem" && data.veemAccount) {
userDetails.veemAccount = data.veemAccount;
// Clear wiseEmail when switching to veem
userDetails.wiseEmail = "";
}
// Build final payload
const payload = {
userDetails: userDetails,
};
console.log("Update Payment payload", payload);
try {
const response = await api.patch("/profile", payload);
console.log("Update-payment-response", response);
return { success: true, data: response?.data?.userDetails };
} catch (error: any) {
console.error("❌ Update payment error:", error.message);
return {
success: false,
message: error.response?.data?.message || "Payment update failed",
};
}
});
export const sendTokenExpired = () => {
console.log("⚠️ Sending token-expired event to renderer");

View File

@ -34,6 +34,12 @@ contextBridge.exposeInMainWorld('electron', {
changePassword: (data: { oldPassword: string; password: string; cPassword: string }) =>
ipcRenderer.invoke("change-password", data),
updatePayment: (data: {
paymentMethod: string;
wiseEmail?: string;
veemAccount?: string;
}) => ipcRenderer.invoke('update-payment', data),
onTokenExpired: (callback) => {
// Remove old listeners
ipcRenderer.removeAllListeners("token-expired");

View File

@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
import { CreditCard } from "lucide-react";
import { useSelector, useDispatch } from "react-redux";
import { RootState } from "../../../store";
import { setProfile } from "../../../store/profileSlice";
interface ChangePaymentModalProps {
isOpen: boolean;
@ -55,23 +56,55 @@ const ChangePaymentModal: React.FC<ChangePaymentModalProps> = ({
setLoading(true);
// try {
// // Replace with your electron API
// await window.electron.updatePayment({
// method,
// wiseEmail: method === "wise" ? wiseEmail.trim() : "",
// veemAccount: method === "veem" ? veemAccount.trim() : "",
// });
try {
// Prepare data for API
const updateData: any = {
paymentMethod: method
};
// // Refresh or update Redux
// // dispatch(updateProfile({...}));
// Add appropriate field based on selection
if (method === "wise") {
updateData.wiseEmail = wiseEmail.trim();
} else if (method === "veem") {
updateData.veemAccount = veemAccount.trim();
}
// onClose();
// } catch (err) {
// setError("Failed to update payment info. Try again.");
// }
console.log("Sending to electron:", updateData);
// Call Electron API
const result = await window.electron.updatePayment(updateData);
console.log(result)
if (result.success) {
// Prepare data for Redux update (clear unused field)
const reduxUpdateData: any = {
paymentMethod: method
};
if (method === "wise") {
reduxUpdateData.wiseEmail = wiseEmail.trim();
reduxUpdateData.veemAccount = ""; // Clear veem
} else if (method === "veem") {
reduxUpdateData.veemAccount = veemAccount.trim();
reduxUpdateData.wiseEmail = ""; // Clear wise
}
// Update Redux store
dispatch(setProfile(result.data));
// Show success message if needed
// toast.success("Payment method updated successfully");
onClose();
} else {
setError(result.message || "Failed to update payment info.");
}
} catch (err: any) {
setError(err.message || "Failed to update payment info. Try again.");
} finally {
setLoading(false);
}
};
return (

View File

@ -104,21 +104,10 @@ const Settings: React.FC = () => {
</div>
{profile?.paymentMethod === "wise" && (
{profile?.veemAccount && (
<div className="p-2 rounded bg-base-200/40">
<p className="text-xs text-base-content/60 flex items-center gap-1 mb-0.5">
💳 Wise
</p>
<p className="text-xs font-medium truncate" title={profile?.payoneerAccount || "N/A"}>
{maskLast5(profile?.wiseEmail)}
</p>
</div>
)}
{profile?.paymentMethod === "veem" && (
<div className="p-2 rounded bg-base-200/40">
<p className="text-xs text-base-content/60 flex items-center gap-1 mb-0.5">
🏦 Veem
🏦 Veem Account
</p>
<p className="text-xs font-medium truncate" title={profile?.veemAccount || "N/A"}>
{profile?.veemAccount || "N/A"}
@ -131,7 +120,7 @@ const Settings: React.FC = () => {
<p className="text-xs text-base-content/60 flex items-center gap-1 mb-0.5 ">
🏦 Wise Email
</p>
<p className="text-xs font-medium truncate" title={profile?.veemAccount || "N/A"}>
<p className="text-xs font-medium overflow-auto no-scrollbar" title={profile?.wiseEmail || "N/A"}>
{profile?.wiseEmail || "N/A"}
</p>
</div>

7
types.d.ts vendored
View File

@ -193,6 +193,13 @@ interface Window {
cPassword: string;
}) => Promise<{ success: boolean; message?: string; data?: any }>;
// In your electron API handler
updatePayment: (data: {
paymentMethod: string;
wiseEmail?: string;
veemAccount?: string;
}) => Promise<{ success: boolean; message?: string; data?: any }>;
onTokenExpired: (callback: () => void) => void;