import React, { useEffect, useState, useCallback } from 'react'; import { Link, useNavigate, useLocation } from "react-router-dom"; import Billing from "../components/Billing.jsx"; import Priorities from "../components/Priorities.jsx"; import Branding from "../components/Branding.jsx"; import AnalyticsTab from '../components/AnalyticsTab.jsx'; import EditOrgTab from '../components/EditOrgTab.jsx'; import CloudSyncTab from '../components/CloudSyncTab.jsx'; import SSOTab from "../components/ssoTab.jsx" import { ToastContainer, toast } from "react-toastify"; import { Button, Tooltip } from '@mui/material'; const OrganizationTab = (props) => { const location = useLocation(); const navigate = useNavigate(); const { userdata, globalUrl, serverside, isCloud, checkLogin, notifications, setNotifications, stripeKey, setSelectedOrganization, selectedStatus, setSelectedStatus, selectedOrganization, handleGetOrg, handleStatusChange, handleEditOrg, isLoaded, removeCookie } = props; const [selectedTab, setSelectedTab] = useState('org_config'); const [organizationFeatures, setOrganizationFeatures] = useState({}); const [billingInfo, setBillingInfo] = useState({}); const [orgRequest, setOrgRequest] = React.useState(true); const [curIndex, setCurIndex] = React.useState(0); const [unreadNotifications, setUnreadNotifications] = React.useState( notifications?.filter((notification) => notification.read === false)?.length ); useEffect(() => { const queryParams = new URLSearchParams(location.search); const tabName = queryParams.get('admin_tab'); if (tabName) { const decodedTabName = decodeURIComponent(tabName); setSelectedTab(decodedTabName); if (decodedTabName === 'org_config') { setCurIndex(0); } else if(decodedTabName === 'sso'){ setCurIndex(1) }else if (decodedTabName === 'notifications' || decodedTabName === 'priorities') { setCurIndex(2); } else if (decodedTabName === 'billingstats' || decodedTabName === 'billing') { setCurIndex(3); } else if (decodedTabName === 'branding(beta)') { setCurIndex(4); } // else if (decodedTabName === 'analytics') { // setCurIndex(5); // } } }, [location.search]); const handleTabClick = (tabName) => { const formattedTabName = tabName.toLowerCase().replace(/[\s&]+/g, ''); const encodedTabName = encodeURIComponent(formattedTabName); setSelectedTab(formattedTabName); document.title = `Shuffle - admin - ${formattedTabName}`; navigate(`?admin_tab=${encodedTabName}`); }; const handleNotifications = useCallback(() => { const unreadCount = notifications?.filter((notification) => notification.read === false).length; setUnreadNotifications(unreadCount); },[unreadNotifications,notifications]); useEffect(() => { if ((unreadNotifications !== notifications?.filter((notification) => notification.read === false).length) !== unreadNotifications) { handleNotifications(); } }, [notifications]); const renderContent = () => { switch (selectedTab) { case 'org_config': return ; case 'sso': return case `notifications`: case `priorities`: return ( ); case 'billingstats' : case 'billing' : return ( ); case 'branding(beta)': return ; // case 'analytics': // return ; default: return ; } }; return (
{['Org Configuration', "sso", "Notifications", 'Billing & Stats', 'Branding (Beta)'].map((tabName, index) => (
))}
{renderContent()}
); }; export default OrganizationTab;