diff --git a/.env.example b/.env.example index 319aefd..1e085bc 100644 --- a/.env.example +++ b/.env.example @@ -7,8 +7,11 @@ VITE_CHECKER="Checker" # Role Encryption key VITE_ROLE_ENCRYPTION_KEY="export" +# Super Admin +VITE_SUPER_ADMIN_ID=1 + # BaseURL -VITE_BAS_URL="http://localhost:5000/api/v1" +VITE_BAS_URL="your_base_url" # BaseURL for Images -VITE_IMAGE_URL="https://sprint9.tanami.betadelivery.com/" \ No newline at end of file +VITE_IMAGE_URL="your_base_url" \ No newline at end of file diff --git a/src/Components/Pagination.jsx b/src/Components/Pagination.jsx index 0a82531..488775d 100644 --- a/src/Components/Pagination.jsx +++ b/src/Components/Pagination.jsx @@ -5,7 +5,7 @@ import { ChevronLeftIcon, ChevronRightIcon } from "@chakra-ui/icons"; const Pagination = ({ pageSize, setPageSize, - totalItems, + totalItems = 1, isLoading, setCurrentPage, currentPage, @@ -84,7 +84,7 @@ const Pagination = ({ onClick={paginationNext} className="link pointer" isDisabled={currentPage === totalPages} - aria-label="Next Page" + aria-label="Next Page" /> diff --git a/src/Constants/Constants.js b/src/Constants/Constants.js index da74880..c863ac9 100644 --- a/src/Constants/Constants.js +++ b/src/Constants/Constants.js @@ -4,7 +4,7 @@ import * as XLSX from 'xlsx'; import CryptoJS from "crypto-js"; -export const generateSerialNumber = (index, currentPage, pageSize) => { +export const generateSerialNumber = (index, currentPage = 1, pageSize = 1) => { return (currentPage - 1) * pageSize + (index + 1); }; @@ -12,7 +12,7 @@ export function getTomorrowDate() { const today = new Date(); const tomorrow = new Date(today); tomorrow.setDate(today.getDate() + 1); - + // Format the date as YYYY-MM-DD (ISO 8601) return tomorrow.toISOString().split('T')[0]; } @@ -34,7 +34,7 @@ export function removeTrailingZeros(value) { } - export function getCountdownTimer(utcDateString) { +export function getCountdownTimer(utcDateString) { // Parse the UTC datetime string into a Date object const targetDate = new Date(utcDateString); const now = new Date(); @@ -57,7 +57,7 @@ export function removeTrailingZeros(value) { const remainingMinutes = minutes % 60; const remainingSeconds = seconds % 60; - return `${remainingDays === 0 ? "": remainingDays+"d"} ${remainingHours === 0 ? "": remainingHours+"h"} ${remainingMinutes}m ${remainingSeconds}s `; + return `${remainingDays === 0 ? "" : remainingDays + "d"} ${remainingHours === 0 ? "" : remainingHours + "h"} ${remainingMinutes}m ${remainingSeconds}s `; } @@ -97,28 +97,28 @@ export function debounce(func, delay) { async function resolveMx(domain, recordType) { return new Promise((resolve, reject) => { - dns.resolveMx(domain, (err, mxRecords) => { - if (err) { - reject(err); - return; - } - const addresses = mxRecords.map((mxRecord) => mxRecord.exchange); - resolve(addresses); - }); + dns.resolveMx(domain, (err, mxRecords) => { + if (err) { + reject(err); + return; + } + const addresses = mxRecords.map((mxRecord) => mxRecord.exchange); + resolve(addresses); + }); }); } // Async function to check email address validity export async function checkEmailValidity(email) { try { - const domain = email?.split("@")[1]; - const addresses = await resolveMx(domain, "MX"); + const domain = email?.split("@")[1]; + const addresses = await resolveMx(domain, "MX"); - if (addresses && addresses?.length > 0) { - return true; - } - return false; // No MX record exists + if (addresses && addresses?.length > 0) { + return true; + } + return false; // No MX record exists } catch (err) { - return false; // Error occurred + return false; // Error occurred } } @@ -126,15 +126,15 @@ export async function checkEmailValidity(email) { // Function to convert timestamp to readable date format in Gulf timezone export function formatTimestampInGulfTimezone(timestamp) { const date = new Date(timestamp); - const options = { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - timeZone: 'Asia/Dubai', // Gulf Standard Time (GST) timezone - timeZoneName: 'short' + const options = { + year: 'numeric', + month: 'long', + day: 'numeric', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + timeZone: 'Asia/Dubai', // Gulf Standard Time (GST) timezone + timeZoneName: 'short' }; return date.toLocaleDateString('en-GB', options); } @@ -164,7 +164,7 @@ const getNestedValue = (obj, key) => { export const exportToExcel = (data, headers) => { const flattenedData = data.map((item) => { const newItem = {}; - + // Loop through customHeaders and get the correct values headers.forEach((header) => { newItem[header.label] = getNestedValue(item, header.key); // Use the helper function @@ -175,7 +175,7 @@ export const exportToExcel = (data, headers) => { // Now pass flattenedData to your Excel library to generate the file // Assuming you're using a library like `xlsx` for this part: - + const worksheet = XLSX.utils.json_to_sheet(flattenedData); const workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1"); @@ -233,4 +233,8 @@ export const decryptString = (ciphertext) => { const bytes = CryptoJS.AES.decrypt(ciphertext, import.meta.env.VITE_ROLE_ENCRYPTION_KEY); const originalText = bytes.toString(CryptoJS.enc.Utf8); return originalText; -}; \ No newline at end of file +}; + +export const SUPER_ADMIN_ID = import.meta.env.VITE_SUPER_ADMIN_ID || 1 +export const MAKER_ID = import.meta.env.VITE_MAKER_ID || 1 +export const CHECKER_ID = import.meta.env.VITE_CHECKER_ID || 2 \ No newline at end of file diff --git a/src/Constants/Paginations.js b/src/Constants/Paginations.js index b01cbd8..e657279 100644 --- a/src/Constants/Paginations.js +++ b/src/Constants/Paginations.js @@ -1,2 +1,2 @@ -export const TABLE_PAGINATION = { page: 1, size:20 } +export const TABLE_PAGINATION = { page: 1, size: 20 } export const IMAGE_URI = import.meta.env.VITE_API_IMAGE_URL \ No newline at end of file diff --git a/src/Pages/Admin/Investor/BankInvestor/BankInvestor.jsx b/src/Pages/Admin/Investor/BankInvestor/BankInvestor.jsx index e3f162a..90d9c15 100644 --- a/src/Pages/Admin/Investor/BankInvestor/BankInvestor.jsx +++ b/src/Pages/Admin/Investor/BankInvestor/BankInvestor.jsx @@ -1,27 +1,25 @@ import { - Avatar, Badge, Box, HStack, Input, Select, - Switch, Text, useDisclosure, useToast, } from "@chakra-ui/react"; -import React, { useContext, useEffect, useState, useRef } from "react"; -import { Link, Link as RouterLink, useNavigate } from "react-router-dom"; -import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; -import { debounce } from "../../../Master/Sponser/AddSponser"; -import { OPACITY_ON_LOAD } from "../../../../Layout/animations"; -import NormalTable from "../../../../Components/DataTable/NormalTable"; +import React, { useContext, useEffect, useRef, useState } from "react"; +import { useNavigate } from "react-router-dom"; import CustomAlertDialog from "../../../../Components/CustomAlertDialog"; -import Pagination from "../../../../Components/Pagination"; +import NormalTable from "../../../../Components/DataTable/NormalTable"; import ToastBox from "../../../../Components/ToastBox"; -import ReasonBanModal from "./ReasonBanModal"; -import { useGetbanInvestorQuery } from "../../../../Services/ban.investor.service"; import { TABLE_PAGINATION } from "../../../../Constants/Paginations"; +import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; +import { OPACITY_ON_LOAD } from "../../../../Layout/animations"; +import { useGetbanInvestorQuery } from "../../../../Services/ban.investor.service"; +import { debounce } from "../../../Master/Sponser/AddSponser"; +import ReasonBanModal from "./ReasonBanModal"; +import Pagination from "../../../../Components/Pagination"; const formatDate = (date) => new Date(date).toLocaleDateString(); // Simple date formatter @@ -233,8 +231,6 @@ const BankInvestor = () => { ), })); - console.log(extractedArray); - const handleDelete = () => { const updatedInvestorDetails = InvestorDetails.filter( (sponsor) => sponsor.id !== actionId @@ -278,6 +274,14 @@ const BankInvestor = () => { /> + {/* { const d = new Date(date); @@ -46,31 +47,28 @@ const SubAdmin = () => { const [mouseEntered, setMouseEntered] = useState(false); const [mouseEnteredId, setMouseEnteredId] = useState(""); // const [deleteSponser] = useDeleteSponserMutation(); - const { sponser, setSponser, slideFromRight } = - useContext(GlobalStateContext); + const { slideFromRight } = useContext(GlobalStateContext); // =========================== [Use State] ============================= - const [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size); - const [currentPage, setCurrentPage] = useState(TABLE_PAGINATION?.page); + // const [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size); + // const [currentPage, setCurrentPage] = useState(TABLE_PAGINATION?.page); const [searchTerm, setSearchTerm] = useState(""); - const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(""); - const [isSwitchOn, setIsSwitchOn] = useState(true); + // const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(""); // Debounce the search term to avoid making a request on every keystroke - useEffect(() => { - const handler = setTimeout(() => { - setDebouncedSearchTerm(searchTerm); - }, 500); // Adjust delay as needed - return () => { - clearTimeout(handler); - }; - }, [searchTerm]); + // useEffect(() => { + // const handler = setTimeout(() => { + // setDebouncedSearchTerm(searchTerm); + // }, 500); // Adjust delay as needed + // return () => { + // clearTimeout(handler); + // }; + // }, [searchTerm]); - const { - data: subAdmin, - error, - isLoading: isSponserLoading, - } = useGetSubAdminMasterQuery(); + const { data: subAdmin, isLoading: isSponserLoading } = + useGetSubAdminMasterQuery(); + + const [deleteUser] = useDeleteUserMutation(); const [toggleStatus] = useToggleStatusMutation(); @@ -91,13 +89,13 @@ const SubAdmin = () => { }); const handleToggleStatus = async (isMaker, id) => { - console.log("hit"); + // console.log("hit"); const data = { - role_xid: isMaker ? "2" : "1", + role_xid: isMaker ? CHECKER_ID : MAKER_ID, }; - console.log("=======================",data) + console.log("=======================", data); try { - const res = await toggleStatus({id, data}); + const res = await toggleStatus({ id, data }); if (res?.error) { toast({ render: () => ( @@ -137,7 +135,7 @@ const SubAdmin = () => { "Action", ]; - const extractedArray = subAdmin?.data?.map((item, index) => ({ + const extractedArray = filteredData?.map((item, index) => ({ "Sr No": ( { className="d-flex align-items-center fw-bold web-text-small" > {/* {item.id} */} - {generateSerialNumber(index, currentPage, pageSize)} + {generateSerialNumber(index)} ), "First Name": ( @@ -180,13 +178,13 @@ const SubAdmin = () => { ), Role: ( - + {item?.role[0]?.role} @@ -231,7 +229,7 @@ const SubAdmin = () => { - {/* { placement="top" > - */} + ), })); // =========================== [ Delete Function ] ================================= - // const handleDelete = async () => { - // console.log(actionId); - // setIsLoading(true); - // try { - // const response = await deleteSponser(actionId); - // console.log(response?.data); - // if (response?.error?.data?.code === 400) { - // toast({ - // render: () => ( - // - // ), - // }); - // setIsLoading(false); - // setDeleteAlert(false); - // } else if ( - // response?.data?.statusCode === 201 || - // response?.data?.statusCode === 200 - // ) { - // toast({ - // render: () => ( - // - // ), - // }); - // setIsLoading(false); - // setDeleteAlert(false); - // } - // } catch (error) {} - // }; - - console.log(isSponserLoading); + const handleDelete = async () => { + setIsLoading(true); + try { + const response = await deleteUser(actionId); + if (response?.error?.data?.code === 400) { + toast({ + render: () => ( + + ), + }); + setIsLoading(false); + setDeleteAlert(false); + } else if ( + response?.data?.statusCode === 201 || + response?.data?.statusCode === 200 + ) { + toast({ + render: () => ( + + ), + }); + setIsLoading(false); + setDeleteAlert(false); + } + } catch (error) {} + }; return ( @@ -322,14 +318,14 @@ const SubAdmin = () => { {/* ====================[Pagination]===================== */} - + /> */} {/* =====================[Add Button]===================== */} @@ -366,8 +362,8 @@ const SubAdmin = () => { setDeleteAlert(false)} isOpen={deleteAlert} - message={"Are you sure you want to delete sponers?"} - // alertHandler={handleDelete} + message={"Are you sure you want to delete sub-admin?"} + alertHandler={handleDelete} isLoading={isLoading} /> diff --git a/src/Services/subadmin.service.js b/src/Services/subadmin.service.js index d6103b9..8e6305e 100644 --- a/src/Services/subadmin.service.js +++ b/src/Services/subadmin.service.js @@ -29,7 +29,7 @@ export const sabAdminMaster = createApi({ method: "POST", body: data, }), - invalidatesTags: ["getSubAdmin","prePopulate"], + invalidatesTags: ["getSubAdmin", "prePopulate"], }), // // ========[Update Sponser]======== @@ -50,7 +50,7 @@ export const sabAdminMaster = createApi({ // // ========[Toggle Status]======== toggleStatus: builder.mutation({ - query: ({id, data}) => ({ + query: ({ id, data }) => ({ url: `/subadmin/admin/toggle-role/${id}`, method: "PATCH", body: data, @@ -58,6 +58,17 @@ export const sabAdminMaster = createApi({ invalidatesTags: ["getSubAdmin"], }), + + // ==========[Delete User] ========== + deleteUser: builder.mutation({ + query: (id) => ({ + url: `/subadmin/admin/${id}`, + method: "DELETE", + }), + invalidatesTags: ["getSubAdmin"], + }), + + // // ========[Get Active]======== // getActiveSponserMaster: builder.query({ @@ -90,9 +101,10 @@ export const sabAdminMaster = createApi({ // Export hooks for usage in functional components export const { - useGetSubAdminMasterQuery, - useCreateSubAdminMutation, - useUpdateSubAdminMutation, - useGetSubAdminByIdQuery, - useToggleStatusMutation + useGetSubAdminMasterQuery, + useCreateSubAdminMutation, + useUpdateSubAdminMutation, + useGetSubAdminByIdQuery, + useToggleStatusMutation, + useDeleteUserMutation, } = sabAdminMaster;