Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import { useMsal } from "@azure/msal-react";
import { Tab } from "./Tab/Tab";
import { DataTable } from "../AdminDashboard/DataTable/DataTable";
import { ExportBtn } from "../../Components/ExportBtn/ExportBtn.js";
import Searchicon from "../../Assets/Icon/Searchicon.svg";
import { useSearchPolicyMutation } from "../../api/policyAPI"; // Assuming correct path
import "./AdminDashboard.css";
const AdminDashboard = () => {
const [activeTab, setActiveTab] = useState("Accounts");
const [accountsRows, setAccountsRows] = useState([]);
const [paymentsRows, setPaymentsRows] = useState([]);
const [policiesRows, setPoliciesRows] = useState([]);
const [searchQuery, setSearchQuery] = useState(""); // Search query state
const [searchResults, setSearchResults] = useState([]); // Search results state
const [loggedInUser, setLoggedinUser] = useState("");
const { accounts } = useMsal();
const [searchPolicy, { isLoading: isSearchLoading }] = useSearchPolicyMutation(); // Mutation hook
useEffect(() => {
setLoggedinUser(accounts[0]?.name?.split(" ")[0] || "");
}, [accounts]);
const handleSearch = async () => {
if (!searchQuery) return;
try {
const response = await searchPolicy({ policyNumber: searchQuery }).unwrap();
setSearchResults(response?.policies || []); // Assuming the API returns a `policies` array
} catch (error) {
console.error("Error searching for policies:", error);
}
};
const policiesColumns = [
{ id: "policyHolderName", name: "Policyholder" },
{ id: "policyNumber", name: "Policy number" },
{ id: "policyEffectiveDate", name: "Effective date" },
{ id: "user", name: "Users" },
{ id: "paymentStatus", name: "Payment status" },
{ id: "lastPayment", name: "Last payment" },
{ id: "eslStatus", name: "ESL status" },
{ id: "view_policy", name: "" },
];
const tabsArray = [
{
id: 1,
name: "Accounts",
rows: accountsRows,
columns: [], // Update with relevant columns
},
{
id: 2,
name: "Policies",
rows: searchResults.length > 0 ? searchResults : policiesRows,
columns: policiesColumns,
},
{
id: 3,
name: "Payments",
rows: paymentsRows,
columns: [], // Update with relevant columns
},
];
const getActiveTable = () => tabsArray.find((tabObj) => tabObj.name === activeTab);
const handleActiveTab = (tabName) => {
setActiveTab(tabName);
if (tabName === "Policies" && searchQuery) {
handleSearch();
}
};
return (
<div className="dashbaord-container">
<div className="admin-dashboard-top-section">
<h1 className="welcome-user">Welcome {loggedInUser}</h1>
<div className="tabs-search-conatiner">
<ul className="tabs-container">
{tabsArray.map((tab) => (
<Tab
key={tab.id}
id={tab.id}
setActiveTab={handleActiveTab}
activeTab={activeTab}
tab={tab}
/>
))}
</ul>
<div className="search-export-container">
<div className="search-container">
<img
alt="Search icon"
src={Searchicon}
width="20"
height="20"
fill="currentColor"
className="download-arrow"
viewBox="0 0 16 16"
/>
<input
className="search-input"
placeholder="Search Policy Number"
type="search"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
/>
<button onClick={handleSearch} disabled={isSearchLoading}>
Search
</button>
</div>
<ExportBtn activeTab={activeTab} />
</div>
</div>
</div>
<div className="admin-bottom-section">
<div className="admin-table-container">
<DataTable
columns={getActiveTable()?.columns || []}
rows={getActiveTable()?.rows || []}
activeTab={activeTab}
/>
</div>
</div>
</div>
);
};
export default AdminDashboard;
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team