From eafc5868e24b803a98a9b2fe2e7f7cb749485ec4 Mon Sep 17 00:00:00 2001 From: Hossein Date: Sun, 26 Nov 2023 16:32:21 +0330 Subject: [PATCH 1/2] #117: Add whitelist component and api --- src/Opex.js | 2 + src/components/SideBar/SideBar.js | 7 + src/components/TopBar/Title/Title.js | 2 + src/pages/WhiteList/WhiteList.js | 208 + src/pages/WhiteList/WhiteList.module.css | 29 + src/query/hooks/useGetWhiteList.js | 13 + src/query/index.js | 3 +- src/routes/routes.js | 1 + yarn.lock | 15136 +++++++++++++++++++++ 9 files changed, 15400 insertions(+), 1 deletion(-) create mode 100644 src/pages/WhiteList/WhiteList.js create mode 100644 src/pages/WhiteList/WhiteList.module.css create mode 100644 src/query/hooks/useGetWhiteList.js create mode 100644 yarn.lock 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..110bcf4 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
@@ -36,6 +37,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..9cafcfd --- /dev/null +++ b/src/pages/WhiteList/WhiteList.js @@ -0,0 +1,208 @@ +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 ? +
    +