fix: resolve variable declaration order, modal state and lint errors
Deploy Canina / deploy (push) Successful in 41s
Deploy Canina / deploy (push) Successful in 41s
This commit is contained in:
1 parent
fc324aacaf
commit
b2b80849ea
11 files changed
+353
-302
No files matched your search
@@ -103,50 +103,6 @@ export default function Users() {
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
const [isAdjustingWallet, setIsAdjustingWallet] = useState(false);
|
||||
|
||||
const fetchUsers = useCallback(async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const params = new URLSearchParams();
|
||||
params.append('page', page.toString());
|
||||
params.append('limit', '10');
|
||||
if (search) params.append('search', search);
|
||||
if (role) params.append('role', role);
|
||||
|
||||
const response = await api.get(`/admin/users?${params.toString()}`);
|
||||
if (response.data?.success) {
|
||||
const userList = response.data.data || [];
|
||||
setUsers(userList);
|
||||
setTotalPages(response.data.meta?.lastPage || 1);
|
||||
setTotalCount(response.data.meta?.total || 0);
|
||||
|
||||
const modalParam = searchParams.get('modal');
|
||||
const userId = searchParams.get('userId');
|
||||
if (modalParam === 'create') {
|
||||
handleOpenCreate();
|
||||
} else if (userId && userList.length > 0) {
|
||||
const found = userList.find((u: UserRecord) => u.id === userId);
|
||||
if (found) {
|
||||
if (modalParam === 'view') handleOpenView(found);
|
||||
else if (modalParam === 'edit') handleOpenEdit(found);
|
||||
else if (modalParam === 'wallet') handleOpenWallet(found);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch users', err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [page, search, role, searchParams]);
|
||||
|
||||
useEffect(() => {
|
||||
const delayDebounceFn = setTimeout(() => {
|
||||
fetchUsers();
|
||||
}, 400);
|
||||
|
||||
return () => clearTimeout(delayDebounceFn);
|
||||
}, [fetchUsers]);
|
||||
|
||||
// Open View Modal
|
||||
const handleOpenView = (user: UserRecord) => {
|
||||
setViewUser(user);
|
||||
@@ -209,7 +165,49 @@ export default function Users() {
|
||||
setUserToDelete(null);
|
||||
};
|
||||
|
||||
const fetchUsers = useCallback(async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const params = new URLSearchParams();
|
||||
params.append('page', page.toString());
|
||||
params.append('limit', '10');
|
||||
if (search) params.append('search', search);
|
||||
if (role) params.append('role', role);
|
||||
|
||||
const response = await api.get(`/admin/users?${params.toString()}`);
|
||||
if (response.data?.success) {
|
||||
const userList = response.data.data || [];
|
||||
setUsers(userList);
|
||||
setTotalPages(response.data.meta?.lastPage || 1);
|
||||
setTotalCount(response.data.meta?.total || 0);
|
||||
|
||||
const modalParam = searchParams.get('modal');
|
||||
const userId = searchParams.get('userId');
|
||||
if (modalParam === 'create') {
|
||||
handleOpenCreate();
|
||||
} else if (userId && userList.length > 0) {
|
||||
const found = userList.find((u: UserRecord) => u.id === userId);
|
||||
if (found) {
|
||||
if (modalParam === 'view') handleOpenView(found);
|
||||
else if (modalParam === 'edit') handleOpenEdit(found);
|
||||
else if (modalParam === 'wallet') handleOpenWallet(found);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch users', err);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [page, search, role, searchParams]);
|
||||
|
||||
useEffect(() => {
|
||||
const delayDebounceFn = setTimeout(() => {
|
||||
fetchUsers();
|
||||
}, 400);
|
||||
|
||||
return () => clearTimeout(delayDebounceFn);
|
||||
}, [fetchUsers]);
|
||||
|
||||
// Create User
|
||||
const handleCreateUser = async (e: React.FormEvent) => {
|
||||
|
||||
Reference in new issue
Block a user