diff --git a/src/App.tsx b/src/App.tsx index f4b72a1..c7efee9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -42,6 +42,7 @@ const App = () => { }> } /> } /> + {/* } /> */} }> } /> diff --git a/src/components/accounts/Account.tsx b/src/components/accounts/Account.tsx index 1d63d5a..0006088 100644 --- a/src/components/accounts/Account.tsx +++ b/src/components/accounts/Account.tsx @@ -6,6 +6,7 @@ import { useNavigate, useParams } from "react-router-dom"; import { FaCheck } from "react-icons/fa"; import Cards from "../home/Cards"; import AddInviteModal from "./AddInviteModal"; +import { Bounce, toast } from "react-toastify"; interface Transaction { id: number; @@ -24,6 +25,8 @@ const Account = () => { const { accountId } = useParams<{ accountId: string }>(); const [transactions, setTransactions] = useState([]); const [selectedTransactions, setSelectedTransactions] = useState([]); + const [accountsData, setAccountsData] = useState([]) + const [inviteLoading, setInviteLoading] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false); @@ -44,22 +47,62 @@ const Account = () => { if (accountId) fetchTransactions(); }, [accountId]); + const getAccountDetails = async () => { + try { + let res = await api.get('/api/user/accounts') + let items = res?.data + setAccountsData(items) + } catch (error) { + console.log(error) + } + } + + useEffect(() => { + getAccountDetails() + }, []) + + const navigate = useNavigate(); const handleTransactionClick = (id: number) => { navigate(`/accounts/${accountId}/transactions/${id}`); }; - const handleAddAccount = (accountName: string) => { - console.log(accountId) - setIsModalOpen(false); + const handleInvite = async (data: { i_accountName: number; email: string; role: string }) => { + setInviteLoading(true); + try { + const payloadInvite = { + email: data.email, + role: data.role + } + let res = await api.post(`/api/accounts/${data.i_accountName}/invite`, payloadInvite) + if (res?.data) { + toast.success("Invite Sent Successfully...!", { + position: "top-center", + autoClose: 1500, + hideProgressBar: false, + closeOnClick: false, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "light", + transition: Bounce, + }); + await fetchTransactions() + setIsModalOpen(false); + } + } catch (err) { + console.error('Failed to invite', err); + } finally { + setInviteLoading(false); + } }; return ( <> - + {transactions.length > 0 && ( -
+
@@ -116,8 +159,8 @@ const Account = () => {
)} - {isModalOpen && setIsModalOpen(false)} - onAddAccount={handleAddAccount} />} + {isModalOpen && setIsModalOpen(false)} onInvite={handleInvite} inviteLoading={inviteLoading} + accountOptions={accountsData} />} ); }; diff --git a/src/components/accounts/AccountNav.tsx b/src/components/accounts/AccountNav.tsx index 5024e7e..9239ca7 100644 --- a/src/components/accounts/AccountNav.tsx +++ b/src/components/accounts/AccountNav.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useRef, useState } from 'react'; // import { useSelector } from 'react-redux'; -import { Link, useLocation } from 'react-router-dom'; -import { FaSignOutAlt,FaUser } from "react-icons/fa"; +import { Link, useLocation, useNavigate } from 'react-router-dom'; +import { FaSignOutAlt, FaUser } from "react-icons/fa"; import api from '../../config/api'; // import { RootState } from '../../store/store'; @@ -32,17 +32,19 @@ const AccountNav: React.FC = ({ accountName = null, transaction // const user: UserState = useSelector((state: RootState) => state.user); const [user, setUser] = useState({ - id: "", - firstName: "", - lastName: "", - email: "", - language: "", - account: { - id: 0, - isDefault: false, - name: "", - }, - }); + id: "", + firstName: "", + lastName: "", + email: "", + language: "", + account: { + id: 0, + isDefault: false, + name: "", + }, + }); + + const navigate = useNavigate() const getUserDetails = async () => { try { @@ -68,6 +70,7 @@ const AccountNav: React.FC = ({ accountName = null, transaction const labelMap: Record = { accounts: "Accounts", transactions: "Transactions", + templates: "Templates" // Add more routes here if needed }; @@ -86,42 +89,58 @@ const AccountNav: React.FC = ({ accountName = null, transaction return () => document.removeEventListener("mousedown", handleClickOutside); }, []); - const handleLogout = () => { - // Add logout logic here - console.log('Logging out...'); - setOpen(false); + const handleLogout = async() => { + try { + let res = await api.post('/api/auth/logout') + if (res.status === 200) { + setOpen(false); + navigate("/login") + } + } catch (error) { + console.log(error) + } }; + const formatSegment = (segment: string) => + segment + .replace(/[-_]/g, " ") + .replace(/\b\w/g, (char) => char.toUpperCase()); return (
-