super admin flow and login issue

This commit is contained in:
momorew
2026-09-10 15:45:12 +05:30
parent fa0a3f65f4
commit 8e7de74472
4 changed files with 43 additions and 26 deletions
+21 -4
View File
@@ -1,5 +1,6 @@
import { useState, useEffect, useMemo } from 'react';
import { ExternalLink, Box, Search, Rocket } from 'lucide-react';
import { useNavigate } from 'react-router-dom';
import { ExternalLink, Box, Search, Rocket, Settings } from 'lucide-react';
import { moduleApi, type Module } from '../modules/user/UserModuleApi';
import { useAuth } from '../../context/AuthContext';
import { useTranslation } from 'react-i18next';
@@ -7,6 +8,8 @@ import CustomInput from '../../components/custom/CustomInput';
const Dashboard = () => {
const { user } = useAuth();
const navigate = useNavigate();
const isSuperAdmin = Boolean(user?.is_superadmin);
const { t } = useTranslation(['dashboard', 'common']);
const [modules, setModules] = useState<Module[]>([]);
@@ -29,6 +32,11 @@ const Dashboard = () => {
}, []);
const handleModuleClick = async (moduleId: string) => {
if (isSuperAdmin) {
navigate(`/admin/modules?edit=${encodeURIComponent(moduleId)}`);
return;
}
try {
const response = await moduleApi.launchModule(moduleId);
@@ -169,10 +177,19 @@ const Dashboard = () => {
<div className="pt-4 border-t border-gray-50 mt-auto">
<button
onClick={() => handleModuleClick(module.module_id)}
className="w-full flex items-center justify-center gap-2 py-2.5 px-4 bg-gray-50 hover:bg-blue-600 text-gray-700 hover:text-white rounded-xl font-medium transition-all duration-200 group-hover:shadow-md"
className="w-full flex items-center justify-center gap-2 py-2.5 px-4 bg-gray-50 hover:bg-blue-600 text-gray-700 hover:text-white rounded-xl font-medium transition-all duration-200 group-hover:shadow-md cursor-pointer"
>
<Rocket size={18} className="transition-transform group-hover:-translate-y-0.5 group-hover:translate-x-0.5" />
{t('dashboard:actions.launch')}
{isSuperAdmin ? (
<>
<Settings size={18} className="transition-transform group-hover:rotate-45 duration-200" />
Manage Module
</>
) : (
<>
<Rocket size={18} className="transition-transform group-hover:-translate-y-0.5 group-hover:translate-x-0.5" />
{t('dashboard:actions.launch')}
</>
)}
</button>
</div>
</div>
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Plus, Edit, Trash2, Settings, Shield, Eye, EyeOff } from 'lucide-react';
import { useModuleApi } from '../hooks/useModuleApi';
@@ -11,6 +11,8 @@ import CustomButton from '../../../../components/custom/CustomButton';
const ModuleList = () => {
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const editId = searchParams.get('edit');
const { t } = useTranslation(['modules', 'common']);
const { listModules, deleteModule, loading } = useModuleApi();
const [modules, setModules] = useState<Module[]>([]);
@@ -30,6 +32,16 @@ const ModuleList = () => {
fetchModules();
}, []);
useEffect(() => {
if (editId && modules.length > 0) {
const found = modules.find(m => m.id === editId || m.module_id === editId);
if (found) {
setSelectedModule(found);
setShowForm(true);
}
}
}, [editId, modules]);
const handleCreate = () => {
setSelectedModule(null);
setShowForm(true);
@@ -56,6 +68,9 @@ const ModuleList = () => {
const handleFormClose = (saved: boolean) => {
setShowForm(false);
setSelectedModule(null);
if (searchParams.get('edit')) {
setSearchParams({}, { replace: true });
}
if (saved) {
fetchModules();
}
-12
View File
@@ -7,7 +7,6 @@ import type {
} from "../application/authentication/AuthTypes";
import {
setAuthCookies,
getAccessToken,
clearAuthCookies,
} from "../lib/authCookies";
import i18n, { loadLanguage } from "../i18n/config";
@@ -33,17 +32,6 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({
useEffect(() => {
const bootstrapAuth = async () => {
if (typeof window !== "undefined" && window.location.pathname.startsWith("/signin")) {
setIsLoading(false);
return;
}
const token = getAccessToken();
if (!token) {
setIsLoading(false);
return;
}
try {
const userData = await authApi.me();
setUser(userData);
+6 -9
View File
@@ -17,15 +17,12 @@ const API_TOAST_OPTIONS = { autoClose: 2000 };
const hardLogout = () => {
clearAuthCookies();
if (typeof window !== "undefined") {
const currentPath = window.location.pathname || window.location.href || "";
if (!currentPath.startsWith("/signin")) {
toast.error(
"Your session has expired. Please sign in again.",
API_TOAST_OPTIONS
);
window.location.href = "/signin";
}
if (typeof window !== "undefined" && !window.location.pathname.startsWith("/signin")) {
toast.error(
"Your session has expired. Please sign in again.",
API_TOAST_OPTIONS
);
window.location.href = "/signin";
}
};