Compare commits

...

2 Commits

Author SHA1 Message Date
victorAnumudu 762601a5c3 made kid wallet refresh when parent transfers cash 2024-03-20 13:44:14 +01:00
victorAnumudu 1e28a0e15b made kid wallet refresh when parent transfers cash 2024-03-20 13:43:23 +01:00
4 changed files with 32 additions and 6 deletions
@@ -65,6 +65,9 @@ export default function SocketIOContextProvider({children}) {
if(message.action == "REFRESH_TASK" && message.audience == "PARENT"){ // for refreshing parent account when child accepts or rejects a job
dispatch(tableReload({type:'PARENTFAMILYTASKLIST'})) // dispatches to update parent family task list on parent side
}
if(message.action == "REFRESH_WALLET" && message.family_uid == user_uid && message.audience == "MEMBER"){ // for refreshing child wallet account when parent sends money to kid
dispatch(tableReload({type:'WALLETTABLE'})) // dispatches to update wallet balance on family side
}
// console.log('DATA', data)
});
}, [socket]);
@@ -17,6 +17,8 @@ function FamilyWallet({familyData}) {
setFamilyWallet({loading:true, data: []})
apiUrl.getFamilyWallet({family_uid:familyData?.uid}).then(res => {
setFamilyWallet({loading:false, data: res?.data?.result_list || []})
console.log('familyData', familyData, res?.data?.result_list)
}).catch(error => {
setFamilyWallet({loading:false, data: []})
})
@@ -9,8 +9,9 @@ import usersService from "../../../../services/UsersService";
import LoadingSpinner from "../../../Spinners/LoadingSpinner";
import { PriceFormatter } from "../../../Helpers/PriceFormatter";
import { tableReload } from "../../../../store/TableReloads";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { apiConst } from "../../../../lib/apiConst";
import { SocketValues } from "../../../Contexts/SocketIOContext";
const validationSchema = Yup.object().shape({
// amount: Yup.string()
@@ -30,6 +31,11 @@ const validationSchema = Yup.object().shape({
});
function FamilyAddFundPopout({ action, situation, wallet, familyData }) {
const {userDetails} = useSelector((state) => state?.userDetails); // Gets User Detail
const { parentAssignJobToKid } = SocketValues() // socket emit event from FULL account
const dispatch = useDispatch();
const apiUrl = new usersService();
@@ -54,6 +60,7 @@ function FamilyAddFundPopout({ action, situation, wallet, familyData }) {
};
// FUNCTION TO PERFORM FAMILY TRANSFER
const handleAddFund = (values) => {
setRequestStatus({ loading: true, status: false, message: "" });
let senderBal = startTransfer?.data?.origing_current_balance || ""; // SENDER'S ACCOUNT BALANCE
@@ -132,6 +139,17 @@ function FamilyAddFundPopout({ action, situation, wallet, familyData }) {
status: true,
message: "Transfer Successful",
});
//SENDS MESSAGE TO SOCKET TO UPDATE CHILD ACCOUNT
// message, room
let socketMsg = {
"audience": "MEMBER",
"action": "REFRESH_WALLET",
"family_uid": reqData.family_uid,
}
let socketRoom = `FAMILY-${userDetails.uid}`
parentAssignJobToKid(socketMsg, socketRoom) //SENDS MESSAGE TO SOCKET TO UPDATE CHILD ACCOUNT
setTimeout(() => {
setRequestStatus({ loading: false, status: false, message: "" });
dispatch(tableReload({ type: "WALLETTABLE" })); // UPDATES PARENT WALLET ACCOUNT
@@ -170,13 +188,13 @@ function FamilyAddFundPopout({ action, situation, wallet, familyData }) {
return (
<ModalCom action={action} situation={situation}>
<div className="relative logout-modal-wrapper lg:w-[500px] h-full lg:h-auto bg-white dark:bg-dark-white lg:rounded-2xl">
<div className="logout-modal-header w-full flex items-center justify-between lg:px-10 lg:py-8 px-[30px] py-[23px] border-b border-light-purple dark:border-[#5356fb29] ">
<h1 className="text-26 font-bold text-dark-gray dark:text-white tracking-wide">
<div className="modal-header-con">
<h1 className="modal-title">
Add Fund
</h1>
<button
type="button"
className="text-[#374557] dark:text-red-500"
className="modal-close-btn"
onClick={action}
>
<svg
@@ -271,7 +289,7 @@ function FamilyAddFundPopout({ action, situation, wallet, familyData }) {
<div className="field w-full mb-[0.5rem]">
<div className="w-full">
<label
htmlFor="Job Delivery Details"
htmlFor="job-label"
className="input-label text-[#181c32] dark:text-white text-[13.975px] leading-[20.9625px] font-semibold flex items-center gap-1"
>
Comment
+4 -1
View File
@@ -9,6 +9,9 @@ const FamilyWalletBox = lazy(() => import("./FamilyWalletBox"));
const FamilyWalletCon = () => {
const apiCall = new usersService();
// const { walletDetails } = useSelector((state) => state?.walletDetails); // WALLET STORE
const {userDetails} = useSelector((state) => state?.userDetails); // GETS USER INFO
const { walletTable } = useSelector((state) => state.tableReload);
const [paymentHistory, setPaymentHistory] = useState({
@@ -23,7 +26,7 @@ const FamilyWalletCon = () => {
const getFamilyWalletBal = () => {
setFamilyWalletBal({loading:true, data: []})
apiCall.getFamilyWallet({family_uid: localStorage.getItem("uid")}).then(res => {
apiCall.getFamilyWallet({family_uid: userDetails.uid}).then(res => {
setFamilyWalletBal({loading:false, data: res?.data?.result_list})
}).catch(error => {
setFamilyWalletBal({loading:false, data: []})