import { Badge, Box, Button, FormControl, FormHelperText, FormLabel, HStack, Input, Select, Text, useToast, } from "@chakra-ui/react"; import React, { useEffect, useState } from "react"; import { OPACITY_ON_LOAD } from "../../Layout/animations"; import NormalTable from "../../Components/DataTable/NormalTable"; import { useGetUnbanInvestorQuery } from "../../Services/ban.investor.service"; import { formatDate, generateSerialNumber } from "../../Constants/Constants"; import { TABLE_PAGINATION } from "../../Constants/Paginations"; import ReactQuill from "react-quill"; import "react-quill/dist/quill.snow.css"; // Importing the Quill snow theme import { useSendCustomEmailMutation } from "../../Services/contact.service"; import { EmailIcon } from "@chakra-ui/icons"; import ToastBox from "../../Components/ToastBox"; const EmailNotification = () => { const [isLoading, setIsLoading] = useState(false); const [selectedRadio, setSelectedRadio] = useState([]); const [subject, setSubject] = useState(""); const [value, setValue] = useState(""); // Quill content (body) const toast = useToast(); const [sendCustomNotification] = useSendCustomEmailMutation(); const [searchTerm, setSearchTerm] = useState(""); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(""); const [country, setCountry] = useState(""); const [kyc, setKyc] = useState(""); // ===========================[Table Setup]============================== const tableHeadRow = [ "Sr N/O", "Date", "Client ID", "First Name", "Last Name", "Country", "Phone Number", "E-mail ID", "KYC Status", ]; const [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size); const [currentPage, setCurrentPage] = useState(TABLE_PAGINATION?.page); // const { // data: investorDetails, // isLoading: investorDetailsLoading, // refetch, // } = useGetUnbanInvestorQuery({ // page: currentPage, // Omit pagination for search // size: 10000, // Omit pagination for search // }); useEffect(() => { const handler = setTimeout(() => { setDebouncedSearchTerm(searchTerm.trim()); // Trim to remove leading/trailing spaces }, 300); return () => clearTimeout(handler); }, [searchTerm]); const { data: investorDetails, isLoading: investorDetailsLoading, refetch, } = useGetUnbanInvestorQuery( { page: 1, // Omit pagination for search size: 10000, // Omit pagination for search // page: debouncedSearchTerm ? undefined : currentPage, // Omit pagination for search // size: debouncedSearchTerm ? undefined : pageSize, // Omit pagination for search search: debouncedSearchTerm, country_xid: country, KYCStatus: kyc, }, { skip: debouncedSearchTerm === "" && searchTerm !== "", // Skip if search is empty and it's not the initial request } ); const extractedArray = investorDetails?.data?.rows?.map((item, idx) => ({ id: item?.principal_xid, "Sr N/O": ( {generateSerialNumber(idx, currentPage, pageSize)} ), Date: ( {formatDate(item?.date)} ), "Client ID": ( {item?.clientReference_id} ), "First Name": ( {item?.firstName} ), "Last Name": ( {item?.lastName} ), Country: ( {item?.country} ), "Phone Number": ( {item?.phoneNumber} ), "E-mail ID": ( {item?.emailAddress} ), "KYC Status": ( {item?.KYCStatus === true ? "Completed" : "Not Completed"} ), })); const modules = { toolbar: [ // [{ header: "1" }, { header: "2" }, // // { font: [] } // ], // [{ size: [] }], ["bold", "italic", "underline", "strike", "blockquote"], [{ list: "ordered" }, { list: "bullet" }], ["clean"], ], }; // Main submission logic const handleSend = async (e) => { e.preventDefault(); // Prevent default form submission if (!subject || !value) { toast({ render: () => ( ), }); return; } if (selectedRadio.length === 0) { toast({ render: () => ( ), }); return; } setIsLoading(true); const emailPayload = { subject, body: value, principal_xid: selectedRadio, }; try { const res = await sendCustomNotification(emailPayload); console.log(res); if (res?.error) { toast({ render: () => ( ), }); setIsLoading(false); } else if (res?.data) { toast({ render: () => , }); setIsLoading(false); setSubject(""); setValue(""); setSelectedRadio([]); } else { toast({ render: () => ( ), }); setIsLoading(false); } } catch (error) {} }; return ( {/* Customize your email */} Subject setSubject(e.target.value)} focusBorderColor="forestGreen.300" rounded={0.5} type="text" /> {/* Entered subject will be reflected on emails subject body. */} Create Custom body {/* We'll never share your email. */} setSearchTerm(e.target.value)} /> ); }; export default EmailNotification;