You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

186 lines
5.7 KiB

import { data } from "autoprefixer";
import { useState } from "react";
import Header from "../../components/header/Header";
import Nav from "../../components/nav/Nav";
import Payment from "../dashboard/Payment";
import BuyInfo from "./BuyInfo";
import CreditAndDiscount from "./CreditAndDiscount";
import Games from "./Games";
import Packages from "./Packages";
import UserFullInfo from "./UserFullInfo";
import UserInfo from "./UserInfo";
const Dashboard2 = ({
ActiveUserFullInfo,
UserFullInfoData,
showUserFullInfo,
hideUserFullInfo,
}) => {
console.log("dashboard2 run--------------------");
// Games functions --------------------------
const [gameId, setGameId] = useState(1);
const chooseGame = (id) => {
setGameId(id);
};
const [selectedGames,setSelectedGames] = useState([]);
const [buyInfoData,setBuyInfoData]=useState([]);
const [fake,setFake]=useState(0);
let gameList = ["ماجراجو","فرفره","آشپزباشی","صخره نورد","معمارک","کنجکاو","1"];
const addPackage=(GameID,data,index,remove,removeIndex)=>{
let newArray = selectedGames;
if (!newArray.includes(GameID)) {
newArray.push(GameID);
}
console.log("selectedGames");
console.log(newArray);
// setSelectedGames(newArray);
let newBuyInfoData = buyInfoData;
if(remove){
console.log("remove--------------------------");
console.log(GameID, removeIndex);
// newBuyInfoData = newBuyInfoData.filter(
// (item) => item.gameId !== GameID && item.packageIndex !== removeIndex
// );
newBuyInfoData = [];
for(let i=0;i<buyInfoData.length;i++){
console.log(buyInfoData[i].gameId, buyInfoData[i].packageIndex);
console.log(
buyInfoData[i].gameId != GameID &&
buyInfoData[i].packageIndex != removeIndex
);
if((buyInfoData[i].gameId != GameID) || (buyInfoData[i].packageIndex != removeIndex)){
console.log("ok")
newBuyInfoData.push(buyInfoData[i]);
}
}
console.log(newBuyInfoData);
// for (let i = 0; i < newBuyInfoData.length; i++) {
// if (
// newBuyInfoData[i].gameId !== id &&
// newBuyInfoData[i].packageIndex !== index
// ) {
// newBuyInfoData.push(buyInfoData[i]);
// }
// }
}
// setTimeout(()=>{console.log("hooooooo")},200);
newBuyInfoData.push({
id: Math.ceil(Math.random() * 10000),
title: gameList[GameID-1],
price: data.price,
time: data.time,
type: GameID < 7 ? 0 : 1,
gameId: GameID,
packageIndex:index
});
console.log('add package---------------------------');
console.log(newBuyInfoData);
setFake(fake + 1);
setBuyInfoData(newBuyInfoData);
setSelectedGames(newArray);
}
//---
const removePackage=(GameID,index)=>{
console.log("remove----------");
console.log(GameID,index);
let newBuyInfoData = [];
for (let i = 0; i < buyInfoData.length; i++) {
if (
buyInfoData[i].gameId !== GameID ||
buyInfoData[i].packageIndex !== index
) {
newBuyInfoData.push(buyInfoData[i]);
}
}
let newArray = [];
for(let i=0;i<selectedGames.length;i++){
console.log(selectedGames[i]);
console.log(selectedGames[i] === GameID);
if (selectedGames[i] === GameID) {
console.log("ops------");
} else {
newArray.push(selectedGames[i]);
}
}
console.log("SelectedGames:--------------------------");
console.log(newArray);
setFake(fake + 1);
setBuyInfoData(newBuyInfoData);
setSelectedGames(newArray);
}
//----
const [creditItem,setCreditItem]=useState(null);
const addCredit=(amount)=>{
console.log("addCredit");
setCreditItem(amount);
setFake(fake+1);
}
const removeCredit=()=>{
setCreditItem(null);
}
//closePayment--------------------------
const [showPayment, setShowPayment] = useState(false);
const closePayment = () => {
setShowPayment(false);
};
const showPaymentFunc = () => {
setShowPayment(true);
};
//discount-------------------------
const [discount,setDiscount]=useState(null);
// const addDiscount=(amount)=>{
// setDiscount();
// }
//creditIsActive-------------------
const [creditIsActive,setCreditIsActive] = useState(false);
return (
<div className="dashboard w-screen h-[91.5%] absolute top-[8.5%] z-0 left-0 bg-color5 flex">
<div className="dashboard-left-part w-[30.4%] h-full py-3 px-4 border-r border-color1">
<UserInfo
showUserFullInfo={showUserFullInfo}
UserFullInfoData={UserFullInfoData}
/>
<BuyInfo
showPaymentFunc={showPaymentFunc}
buyInfoData={buyInfoData}
removePackage={removePackage}
creditItem={creditItem}
removeCredit={removeCredit}
discount={discount}
/>
</div>
<div className="dashboard-right-part w-[63.1%] h-full py-3 relative">
<Games
selectedGames={selectedGames}
gameId={gameId}
chooseGame={chooseGame}
/>
<Packages gameId={gameId} addPackage={addPackage} />
<CreditAndDiscount addCredit={addCredit} />
{ActiveUserFullInfo && (
<div className="dashboard-blur-box w-full h-full absolute top-0 left-0 backdrop-blur z-40">
<UserFullInfo
buyBtn={false}
hideUserFullInfo={hideUserFullInfo}
UserFullInfoData={UserFullInfoData}
/>
</div>
)}
</div>
{/* {showUserFullInfo && <UserFullInfo />} */}
{showPayment && <Payment closePayment={closePayment} />}
</div>
);
};
export default Dashboard2