profile payment update
This commit is contained in:
parent
3efcf99151
commit
c0a89d3f69
|
|
@ -407,7 +407,7 @@ ipcMain.handle("get-payslips", async (event, vaId: string) => {
|
||||||
console.log("get-payslips", vaId)
|
console.log("get-payslips", vaId)
|
||||||
try {
|
try {
|
||||||
const response = await api.get(`/paySlip/${vaId}`);
|
const response = await api.get(`/paySlip/${vaId}`);
|
||||||
console.log(response.data , "Line 409")
|
console.log(response.data, "Line 409")
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: response.data || [],
|
data: response.data || [],
|
||||||
|
|
@ -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,156 +2,189 @@ 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;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChangePaymentModal: React.FC<ChangePaymentModalProps> = ({
|
const ChangePaymentModal: React.FC<ChangePaymentModalProps> = ({
|
||||||
isOpen,
|
isOpen,
|
||||||
onClose,
|
onClose,
|
||||||
}) => {
|
}) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { profile } = useSelector((state: RootState) => state.profile);
|
const { profile } = useSelector((state: RootState) => state.profile);
|
||||||
|
|
||||||
const [method, setMethod] = useState(profile?.paymentMethod || "");
|
const [method, setMethod] = useState(profile?.paymentMethod || "");
|
||||||
const [wiseEmail, setWiseEmail] = useState(profile?.wiseEmail || "");
|
const [wiseEmail, setWiseEmail] = useState(profile?.wiseEmail || "");
|
||||||
const [veemAccount, setVeemAccount] = useState(profile?.veemAccount || "");
|
const [veemAccount, setVeemAccount] = useState(profile?.veemAccount || "");
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
setMethod(profile?.paymentMethod || "");
|
setMethod(profile?.paymentMethod || "");
|
||||||
setWiseEmail(profile?.wiseEmail || "");
|
setWiseEmail(profile?.wiseEmail || "");
|
||||||
setVeemAccount(profile?.veemAccount || "");
|
setVeemAccount(profile?.veemAccount || "");
|
||||||
setError("");
|
setError("");
|
||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|
||||||
if (!isOpen) return null;
|
if (!isOpen) return null;
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
setError("");
|
setError("");
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
if (!method) {
|
if (!method) {
|
||||||
return setError("Please select a payment method.");
|
return setError("Please select a payment method.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === "wise" && !wiseEmail.trim()) {
|
if (method === "wise" && !wiseEmail.trim()) {
|
||||||
return setError("Wise email is required.");
|
return setError("Wise email is required.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === "wise" && !/^\S+@\S+\.\S+$/.test(wiseEmail)) {
|
if (method === "wise" && !/^\S+@\S+\.\S+$/.test(wiseEmail)) {
|
||||||
return setError("Enter a valid Wise email.");
|
return setError("Enter a valid Wise email.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === "veem" && !veemAccount.trim()) {
|
if (method === "veem" && !veemAccount.trim()) {
|
||||||
return setError("Veem account number is required.");
|
return setError("Veem account number is required.");
|
||||||
}
|
}
|
||||||
|
|
||||||
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.");
|
|
||||||
// }
|
|
||||||
|
|
||||||
setLoading(false);
|
// Call Electron API
|
||||||
};
|
const result = await window.electron.updatePayment(updateData);
|
||||||
|
|
||||||
return (
|
console.log(result)
|
||||||
<dialog open className="modal modal-open">
|
|
||||||
<div className="modal-box w-96">
|
|
||||||
|
|
||||||
<h3 className="font-bold text-lg mb-4 flex items-center gap-2">
|
if (result.success) {
|
||||||
<CreditCard size={18} /> Change Payment Method
|
// Prepare data for Redux update (clear unused field)
|
||||||
</h3>
|
const reduxUpdateData: any = {
|
||||||
|
paymentMethod: method
|
||||||
|
};
|
||||||
|
|
||||||
{/* Error */}
|
if (method === "wise") {
|
||||||
{error && (
|
reduxUpdateData.wiseEmail = wiseEmail.trim();
|
||||||
<div className="alert alert-error py-2 text-xs mb-3">{error}</div>
|
reduxUpdateData.veemAccount = ""; // Clear veem
|
||||||
)}
|
} else if (method === "veem") {
|
||||||
|
reduxUpdateData.veemAccount = veemAccount.trim();
|
||||||
|
reduxUpdateData.wiseEmail = ""; // Clear wise
|
||||||
|
}
|
||||||
|
|
||||||
{/* Dropdown */}
|
// Update Redux store
|
||||||
<div className="form-control mb-4">
|
dispatch(setProfile(result.data));
|
||||||
<label className="label">
|
|
||||||
<span className="text-sm font-medium">Payment Method</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<select
|
// Show success message if needed
|
||||||
className="select select-bordered select-sm"
|
// toast.success("Payment method updated successfully");
|
||||||
value={method}
|
|
||||||
onChange={(e) => setMethod(e.target.value)}
|
|
||||||
>
|
|
||||||
<option value="">Select method</option>
|
|
||||||
<option value="wise">Wise</option>
|
|
||||||
<option value="veem">Veem</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Wise Email */}
|
onClose();
|
||||||
{method === "wise" && (
|
} else {
|
||||||
<div className="form-control mb-4">
|
setError(result.message || "Failed to update payment info.");
|
||||||
<label className="label">
|
}
|
||||||
<span className="text-sm font-medium">Wise Email</span>
|
} catch (err: any) {
|
||||||
</label>
|
setError(err.message || "Failed to update payment info. Try again.");
|
||||||
<input
|
} finally {
|
||||||
type="email"
|
setLoading(false);
|
||||||
className="input input-bordered input-sm"
|
}
|
||||||
placeholder="Enter Wise email"
|
};
|
||||||
value={wiseEmail}
|
|
||||||
onChange={(e) => setWiseEmail(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Veem Account */}
|
return (
|
||||||
{method === "veem" && (
|
<dialog open className="modal modal-open">
|
||||||
<div className="form-control mb-4">
|
<div className="modal-box w-96">
|
||||||
<label className="label">
|
|
||||||
<span className="text-sm font-medium">Veem Account Number</span>
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="input input-bordered input-sm"
|
|
||||||
placeholder="Enter Veem account"
|
|
||||||
value={veemAccount}
|
|
||||||
onChange={(e) => setVeemAccount(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="modal-action">
|
<h3 className="font-bold text-lg mb-4 flex items-center gap-2">
|
||||||
<button className="btn btn-sm btn-ghost" onClick={onClose}>
|
<CreditCard size={18} /> Change Payment Method
|
||||||
Cancel
|
</h3>
|
||||||
</button>
|
|
||||||
|
|
||||||
<button
|
{/* Error */}
|
||||||
className={`btn btn-sm btn-primary ${loading ? "loading" : ""}`}
|
{error && (
|
||||||
onClick={handleSubmit}
|
<div className="alert alert-error py-2 text-xs mb-3">{error}</div>
|
||||||
disabled={loading}
|
)}
|
||||||
>
|
|
||||||
{loading ? "Updating..." : "Update"}
|
{/* Dropdown */}
|
||||||
</button>
|
<div className="form-control mb-4">
|
||||||
</div>
|
<label className="label">
|
||||||
</div>
|
<span className="text-sm font-medium">Payment Method</span>
|
||||||
</dialog>
|
</label>
|
||||||
);
|
|
||||||
|
<select
|
||||||
|
className="select select-bordered select-sm"
|
||||||
|
value={method}
|
||||||
|
onChange={(e) => setMethod(e.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">Select method</option>
|
||||||
|
<option value="wise">Wise</option>
|
||||||
|
<option value="veem">Veem</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Wise Email */}
|
||||||
|
{method === "wise" && (
|
||||||
|
<div className="form-control mb-4">
|
||||||
|
<label className="label">
|
||||||
|
<span className="text-sm font-medium">Wise Email</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
className="input input-bordered input-sm"
|
||||||
|
placeholder="Enter Wise email"
|
||||||
|
value={wiseEmail}
|
||||||
|
onChange={(e) => setWiseEmail(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Veem Account */}
|
||||||
|
{method === "veem" && (
|
||||||
|
<div className="form-control mb-4">
|
||||||
|
<label className="label">
|
||||||
|
<span className="text-sm font-medium">Veem Account Number</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="input input-bordered input-sm"
|
||||||
|
placeholder="Enter Veem account"
|
||||||
|
value={veemAccount}
|
||||||
|
onChange={(e) => setVeemAccount(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="modal-action">
|
||||||
|
<button className="btn btn-sm btn-ghost" onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className={`btn btn-sm btn-primary ${loading ? "loading" : ""}`}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{loading ? "Updating..." : "Update"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ChangePaymentModal;
|
export default ChangePaymentModal;
|
||||||
|
|
|
||||||
|
|
@ -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"}
|
||||||
|
|
@ -128,10 +117,10 @@ const Settings: React.FC = () => {
|
||||||
|
|
||||||
{profile?.wiseEmail&& (
|
{profile?.wiseEmail&& (
|
||||||
<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 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>
|
||||||
|
|
|
||||||
|
|
@ -154,16 +154,16 @@ interface Window {
|
||||||
vaId: string;
|
vaId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
type: string;
|
type: string;
|
||||||
time:string
|
time: string
|
||||||
}) => Promise<any>;
|
}) => Promise<any>;
|
||||||
stopProjectTracking: (data: {
|
stopProjectTracking: (data: {
|
||||||
vaId: string;
|
vaId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
type: string;
|
type: string;
|
||||||
time:string
|
time: string
|
||||||
}) => Promise<any>;
|
}) => Promise<any>;
|
||||||
trackingTabsOpeningClosing: (data: {
|
trackingTabsOpeningClosing: (data: {
|
||||||
id?: string;
|
id?: string;
|
||||||
logId: string;
|
logId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -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