profile payment update
This commit is contained in:
parent
3efcf99151
commit
c0a89d3f69
|
|
@ -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 = () => {
|
export const sendTokenExpired = () => {
|
||||||
console.log("⚠️ Sending token-expired event to renderer");
|
console.log("⚠️ Sending token-expired event to renderer");
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,12 @@ contextBridge.exposeInMainWorld('electron', {
|
||||||
changePassword: (data: { oldPassword: string; password: string; cPassword: string }) =>
|
changePassword: (data: { oldPassword: string; password: string; cPassword: string }) =>
|
||||||
ipcRenderer.invoke("change-password", data),
|
ipcRenderer.invoke("change-password", data),
|
||||||
|
|
||||||
|
updatePayment: (data: {
|
||||||
|
paymentMethod: string;
|
||||||
|
wiseEmail?: string;
|
||||||
|
veemAccount?: string;
|
||||||
|
}) => ipcRenderer.invoke('update-payment', data),
|
||||||
|
|
||||||
onTokenExpired: (callback) => {
|
onTokenExpired: (callback) => {
|
||||||
// Remove old listeners
|
// Remove old listeners
|
||||||
ipcRenderer.removeAllListeners("token-expired");
|
ipcRenderer.removeAllListeners("token-expired");
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
|
||||||
import { CreditCard } from "lucide-react";
|
import { CreditCard } from "lucide-react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { RootState } from "../../../store";
|
import { RootState } from "../../../store";
|
||||||
|
import { setProfile } from "../../../store/profileSlice";
|
||||||
|
|
||||||
interface ChangePaymentModalProps {
|
interface ChangePaymentModalProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
|
@ -55,23 +56,55 @@ const ChangePaymentModal: React.FC<ChangePaymentModalProps> = ({
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// try {
|
try {
|
||||||
// // Replace with your electron API
|
// Prepare data for API
|
||||||
// await window.electron.updatePayment({
|
const updateData: any = {
|
||||||
// method,
|
paymentMethod: method
|
||||||
// wiseEmail: method === "wise" ? wiseEmail.trim() : "",
|
};
|
||||||
// veemAccount: method === "veem" ? veemAccount.trim() : "",
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // Refresh or update Redux
|
// Add appropriate field based on selection
|
||||||
// // dispatch(updateProfile({...}));
|
if (method === "wise") {
|
||||||
|
updateData.wiseEmail = wiseEmail.trim();
|
||||||
|
} else if (method === "veem") {
|
||||||
|
updateData.veemAccount = veemAccount.trim();
|
||||||
|
}
|
||||||
|
|
||||||
// onClose();
|
console.log("Sending to electron:", updateData);
|
||||||
// } catch (err) {
|
|
||||||
// setError("Failed to update payment info. Try again.");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
// 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);
|
setLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -104,21 +104,10 @@ const Settings: React.FC = () => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{profile?.paymentMethod === "wise" && (
|
{profile?.veemAccount && (
|
||||||
<div className="p-2 rounded bg-base-200/40">
|
<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">
|
<p className="text-xs text-base-content/60 flex items-center gap-1 mb-0.5">
|
||||||
💳 Wise
|
🏦 Veem Account
|
||||||
</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
|
|
||||||
</p>
|
</p>
|
||||||
<p className="text-xs font-medium truncate" title={profile?.veemAccount || "N/A"}>
|
<p className="text-xs font-medium truncate" title={profile?.veemAccount || "N/A"}>
|
||||||
{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 ">
|
<p className="text-xs text-base-content/60 flex items-center gap-1 mb-0.5 ">
|
||||||
🏦 Wise Email
|
🏦 Wise Email
|
||||||
</p>
|
</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"}
|
{profile?.wiseEmail || "N/A"}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,13 @@ interface Window {
|
||||||
cPassword: string;
|
cPassword: string;
|
||||||
}) => Promise<{ success: boolean; message?: string; data?: any }>;
|
}) => 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;
|
onTokenExpired: (callback: () => void) => void;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue