diff --git a/src/Pages/EmailNotification/EmailNotification.jsx b/src/Pages/EmailNotification/EmailNotification.jsx index b9026fa..9c05f63 100644 --- a/src/Pages/EmailNotification/EmailNotification.jsx +++ b/src/Pages/EmailNotification/EmailNotification.jsx @@ -1,28 +1,37 @@ -import { Badge, Box, Button, FormControl, FormHelperText, FormLabel, HStack, Text } from '@chakra-ui/react' -import React, { 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 { + Badge, + Box, + Button, + FormControl, + FormHelperText, + FormLabel, + HStack, + Input, + Text, + useToast, +} from "@chakra-ui/react"; +import React, { 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 [value, setValue] = useState(''); + const [isLoading, setIsLoading] = useState(false); + const [selectedRadio, setSelectedRadio] = useState([]); + const [subject, setSubject] = useState(""); + const [value, setValue] = useState(""); // Quill content (body) + const toast = useToast(); - const { - data : investorDetails, - isLoading: investorDetailsLoading, - refetch, - } = useGetUnbanInvestorQuery(); + const [sendCustomNotification] = useSendCustomEmailMutation(); - - // ====================================================[Table Setup]================================================================ + // ===========================[Table Setup]============================== const tableHeadRow = [ "Sr N/O", "Date", @@ -35,11 +44,17 @@ const EmailNotification = () => { "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 + }); const extractedArray = investorDetails?.data?.rows?.map((item, idx) => ({ id: item?.principal_xid, @@ -50,7 +65,7 @@ const EmailNotification = () => { color={"gray.600"} className="d-flex align-items-center fw-bold web-text-small" > - {generateSerialNumber(idx,currentPage, pageSize )} + {generateSerialNumber(idx, currentPage, pageSize)} ), Date: ( @@ -110,7 +125,7 @@ const EmailNotification = () => { color={item?.KYCStatus === false ? "red" : "blue"} px={2} py={0.5} - variant={'ghost'} + variant={"ghost"} > {item?.KYCStatus === true ? "Completed" : "Incompleted"} @@ -118,71 +133,167 @@ const EmailNotification = () => { ), })); - - console.log(value); - - const modules = { toolbar: [ - [{ 'header': '1'}, { 'header': '2'}, { 'font': [] }], - [{size: []}], - ['bold', 'italic', 'underline', 'strike', 'blockquote'], - [{'list': 'ordered'}, {'list': 'bullet'}], - // ['link', 'image', 'video'], - ['clean'] + [{ header: "1" }, { header: "2" }, { font: [] }], + [{ size: [] }], + ["bold", "italic", "underline", "strike", "blockquote"], + [{ list: "ordered" }, { list: "bullet" }], + ["clean"], ], }; - return ( - + + // 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, + }; -{/* */} - - - - Customize your email - - - - We'll never share your email. - + 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) + } - {/* - Output: - - */} - {/* */} + } 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. + */} + + + + + - - ) -} -export default EmailNotification \ No newline at end of file + + + + + ); +}; + +export default EmailNotification; diff --git a/src/Routes/Nav.js b/src/Routes/Nav.js index 8818b5f..c581df5 100644 --- a/src/Routes/Nav.js +++ b/src/Routes/Nav.js @@ -213,11 +213,11 @@ export const nav = [ path: "/notification", icon: MdNotificationsNone, }, - // { - // title: "Email Notification", - // path: "/email", - // icon: AtSignIcon, - // }, + { + title: "Email Notification", + path: "/email", + icon: AtSignIcon, + }, { title: "Contact Details", path: "/contact", diff --git a/src/Services/ban.investor.service.js b/src/Services/ban.investor.service.js index 12e840d..fb525aa 100644 --- a/src/Services/ban.investor.service.js +++ b/src/Services/ban.investor.service.js @@ -22,7 +22,7 @@ export const banInvestorDetails = createApi({ getUnbanInvestor: builder.query({ query: ({ page, size, search, kycStatus, country }) => { // Start with the base URL, including searchTerm - let baseURL = `/investorDetails/admin/getAllUnbanned/?search=${search || ""}`; + let baseURL = `/investorDetails/admin/getAllUnbanned?search=${search || ""}`; // Conditionally append kycStatus if it's defined if (kycStatus) { diff --git a/src/Services/contact.service.js b/src/Services/contact.service.js index c8eb562..74dc6cb 100644 --- a/src/Services/contact.service.js +++ b/src/Services/contact.service.js @@ -51,9 +51,26 @@ export const contact = createApi({ body: data, }), }), + + + + + + sendCustomEmail : builder.mutation({ + query: (data) => ({ + url: `/notification/admin/send-custom-email`, + method: "POST", + body: data, + }), + }), + + + + + }), }); // Export hooks for usage in functional components -export const { useGetContactQuery, useUpdateContactMutation, useSendNotificationMutation } = contact; +export const { useGetContactQuery, useUpdateContactMutation, useSendNotificationMutation, useSendCustomEmailMutation } = contact;