diff --git a/src/Opex.js b/src/Opex.js index 965ab96..e56efb0 100644 --- a/src/Opex.js +++ b/src/Opex.js @@ -17,6 +17,7 @@ import axios from "axios"; import jwt_decode from "jwt-decode"; import {getTokenByRefreshToken} from "js-api-client"; import setupAxios from "./setupAxios"; +import WhiteList from "./pages/WhiteList/WhiteList"; function Opex() { const {auth, setAuth} = useAuth(); @@ -70,6 +71,7 @@ function Opex() { }/> }/> }/> + }/> }/> diff --git a/src/components/SideBar/SideBar.js b/src/components/SideBar/SideBar.js index 8064ad2..a7d1218 100644 --- a/src/components/SideBar/SideBar.js +++ b/src/components/SideBar/SideBar.js @@ -2,6 +2,7 @@ import {toAbsoluteUrl} from "../utils"; import {NavLink} from "react-router-dom"; import * as Routes from "../../routes/routes"; import Icon from "../Icon/Icon"; +import {WhiteList} from "../../routes/routes"; const SideBar = ({closeMenu}) => { return
@@ -10,7 +11,6 @@ const SideBar = ({closeMenu}) => { logo
-
  • @@ -36,6 +36,12 @@ const SideBar = ({closeMenu}) => { KYC
  • +
  • + + + White List + +
diff --git a/src/components/TopBar/Title/Title.js b/src/components/TopBar/Title/Title.js index c40e95a..70ba3e2 100644 --- a/src/components/TopBar/Title/Title.js +++ b/src/components/TopBar/Title/Title.js @@ -1,6 +1,7 @@ import React from "react"; import {Route, Routes} from "react-router-dom"; import * as RoutesName from "../../../routes/routes"; +import WhiteList from "../../../pages/WhiteList/WhiteList"; const Title = () => { @@ -12,6 +13,7 @@ const Title = () => { + ); }; diff --git a/src/pages/WhiteList/WhiteList.js b/src/pages/WhiteList/WhiteList.js new file mode 100644 index 0000000..bbe1b3b --- /dev/null +++ b/src/pages/WhiteList/WhiteList.js @@ -0,0 +1,206 @@ +import React, {useState} from 'react'; +import classes from './WhiteList.module.css' +import Loading from "../../components/Loading"; +import {copyToClipboard, toAbsoluteUrl} from "../../components/utils"; +import {Link} from "react-router-dom"; +import Pagination from "../../components/Pagination/Pagination"; +import ScrollBar from "../../components/ScrollBar"; +import {useGetWhiteList} from "../../query"; +import {adminDeleteWhiteList, adminUpdateWhiteList} from "js-api-client/admin/whiteList"; +import {toast} from "react-hot-toast"; + +const WhiteList = () => { + + const {data: whiteUsers, isLoading, error, refetch} = useGetWhiteList() + + const [loading, setLoading] = useState(null) + const [addLoading, setAddLoading] = useState(false) + const [search, setSearch] = useState(false) + + const [email, setEmail] = useState(''); + + const deleteFromWhiteList = (user, index) => { + setLoading(index) + + const whiteListData = {"data":[`${user}`]} + + adminDeleteWhiteList(whiteListData) + .then(() => { + toast.success(`${user} removed from white list`) + refetch() + }).catch(() => { + toast.error("Something went wrong") + }).finally(() => { + setLoading(null) + setSearch(false) + setEmail("") + }) + } + + const addToWhitelist = () => { + + const whiteUser = whiteUsers?.find( f => f === email) + + if (whiteUser !== undefined) { + return toast.error("User exist in list") + } + + setAddLoading(true) + + const whiteListData = {"data":[`${email}`]} + + adminUpdateWhiteList(whiteListData) + .then(() => { + toast.success(`${email} added to white list`) + refetch() + }).catch(() => { + toast.error("Something went wrong") + }).finally(() => { + setSearch(false) + setEmail("") + setAddLoading(false) + }) + + } + + const content = () => { + if (isLoading) { + return + + + + + } + if (whiteUsers?.length === 0 ) { + return + No User Exist + + } + if (search) { + + const whiteUser = whiteUsers?.find( f => f === email) + + if (whiteUser === undefined) { + return + No User Exist + + } + + return + {1} + {whiteUser} + + copyToClipboard(whiteUser)}> + copy + + + + { + loading === 1 ? : + + } + + + } + return whiteUsers?.map((user, index) => + {index + 1} + {user} + + copyToClipboard(user)}> + copy + + + + { + loading === index ? : + + } + + ) + } + + + + + + + return ( + +
+ + +
+
+
+ Email + setEmail(e.target.value)}/> +
+ + + + + +
+ +
+ Total: {whiteUsers?.length} +
+ +
+ + + + + + + + + + + + + { + content() + } + +
+ Email
+ {error ? +
+