From bd172be9a5b3cdffa0d0c6e6272b5d61dfc481f2 Mon Sep 17 00:00:00 2001 From: Francisco Pessano Date: Mon, 25 Oct 2021 18:42:53 -0300 Subject: [PATCH] My account logic done --- src/App.js | 7 ++ .../Admin/Account/AccountInfo/AccountInfo.jsx | 100 ++++++++++++++++++ .../Firebase Querys/bringDataFromFirebase.js | 24 +++++ .../HeaderAccount/HeaderAccount.jsx | 19 ++++ .../AccountInfo/Scripts/hideRefferCode.js | 12 +++ 5 files changed, 162 insertions(+) create mode 100644 src/components/Admin/Account/AccountInfo/AccountInfo.jsx create mode 100644 src/components/Admin/Account/AccountInfo/Firebase Querys/bringDataFromFirebase.js create mode 100644 src/components/Admin/Account/AccountInfo/HeaderAccount/HeaderAccount.jsx create mode 100644 src/components/Admin/Account/AccountInfo/Scripts/hideRefferCode.js diff --git a/src/App.js b/src/App.js index f134027..71ac809 100644 --- a/src/App.js +++ b/src/App.js @@ -16,6 +16,7 @@ import Game from "./components/Game/Game"; import AdminIdentify from "./components/Admin/AdminIdentify/AdminIdentify"; import DemoControlPanel from "./components/Demo Admin/Control Panel/DemoControlPanel"; import PasswordRecovery from "./components/Admin/AdminIdentify/Identify/PasswordRecovery/PasswordRecovery"; +import AccountInfo from "./components/Admin/Account/AccountInfo/AccountInfo"; function App() { return ( @@ -23,6 +24,12 @@ function App() { <> + + + + + + diff --git a/src/components/Admin/Account/AccountInfo/AccountInfo.jsx b/src/components/Admin/Account/AccountInfo/AccountInfo.jsx new file mode 100644 index 0000000..ff6bec2 --- /dev/null +++ b/src/components/Admin/Account/AccountInfo/AccountInfo.jsx @@ -0,0 +1,100 @@ +import React, { useState } from 'react' +import { getAuth, onAuthStateChanged } from "firebase/auth" + + +import capitalize from '../../Control Panel/Scripts/Capilazate' +import bringDataFromFirebase from './Firebase Querys/bringDataFromFirebase' +import HeaderAccount from './HeaderAccount/HeaderAccount' +import hideRefferCode from './Scripts/hideRefferCode' + +const AccountInfo = () => { + + const [name, setName] = useState('') + const [email, setEmail] = useState(false) + const [position, setPosition] = useState('') + + const [refferCode, setRefferCode] = useState('') + const [refferCodeHide, setRefferCodeHide] = useState(true) + + const [loading, setLoading] = useState(true) + + const closeSession = async () => { + + } + + const applyResult = (result) => { + + setName(result['name']) + setPosition(result['position']) + setRefferCode(result['refferCode']) + } + + const bringData = async (email) => { + + const result = await bringDataFromFirebase(email) + + await console.log(result); + + await applyResult(await result) + + setLoading(false) + } + + React.useEffect(() => { + + + const auth = getAuth() + + onAuthStateChanged(auth, (user) => { + + if (user) { + setEmail(user.email) + bringData(user.email) + } + }) + + + + + + + }, []) + + return ( + <> + + + { + loading ? +

aaa

+ : +
+

{name}

+

{capitalize(position)}

+ + + +

{email}

+ +
+ +

{refferCodeHide ? hideRefferCode(refferCode) : refferCode}

+ +
+
+ } + + + + ) +} + +export default AccountInfo diff --git a/src/components/Admin/Account/AccountInfo/Firebase Querys/bringDataFromFirebase.js b/src/components/Admin/Account/AccountInfo/Firebase Querys/bringDataFromFirebase.js new file mode 100644 index 0000000..61a5abb --- /dev/null +++ b/src/components/Admin/Account/AccountInfo/Firebase Querys/bringDataFromFirebase.js @@ -0,0 +1,24 @@ +import { doc, getFirestore, getDoc } from "firebase/firestore" +import { firestore } from "../../../../../Firebase/Firebase_Config" + +const bringDataFromFirebase = async (email) => { + + const data = {} + + try { + + console.log(email) + + const db = getFirestore(firestore) + const reference = doc(db, 'users', email) + const documentSnap = await getDoc(reference) + + return await documentSnap.data() + + } catch (error) { + console.log(error) + } + +} + +export default bringDataFromFirebase diff --git a/src/components/Admin/Account/AccountInfo/HeaderAccount/HeaderAccount.jsx b/src/components/Admin/Account/AccountInfo/HeaderAccount/HeaderAccount.jsx new file mode 100644 index 0000000..e4f231e --- /dev/null +++ b/src/components/Admin/Account/AccountInfo/HeaderAccount/HeaderAccount.jsx @@ -0,0 +1,19 @@ +import React from 'react' +import { withRouter } from 'react-router' + +const HeaderAccount = (props) => { + return ( +
+

My Account

+ + +
+ ) +} + +export default withRouter(HeaderAccount) \ No newline at end of file diff --git a/src/components/Admin/Account/AccountInfo/Scripts/hideRefferCode.js b/src/components/Admin/Account/AccountInfo/Scripts/hideRefferCode.js new file mode 100644 index 0000000..89aeac3 --- /dev/null +++ b/src/components/Admin/Account/AccountInfo/Scripts/hideRefferCode.js @@ -0,0 +1,12 @@ +const hideRefferCode = (refferCode) => { + + let hiddenRefferCode = '' + + for (let i = 0; i < refferCode.length; i++) { + hiddenRefferCode = hiddenRefferCode + '•' + } + + return hiddenRefferCode +} + +export default hideRefferCode