'use client'; import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card" import strings from "@/strings.json" import { UserPlus, CircleAlert } from "lucide-react" export default function Users() { const [totalUsers, setTotalUsers] = useState(0); const [userCtCardError, setUserCtCardError] = useState(false); const [userCtCardLoading, setUserCtCardLoading] = useState(true); useEffect(() => { console.log(strings.logsCalculatingUserCt); (async () => { try { const username = document.cookie.split('; ').find(row => row.startsWith('username='))?.split('=')[1] || ''; const key = document.cookie.split('; ').find(row => row.startsWith('key='))?.split('=')[1] || ''; const res = await fetch(`http://localhost:3001/api/admin/users/totalUsers`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username, key }), cache: 'no-store', }); if (!res.ok) { alert(strings.errorsFetchTotalUserCtErr); setUserCtCardError(true); throw new Error(`${strings.errorsFetchTotalUserCtErr}: ${res.status}`); } const data = await res.json(); if (data.success === false) { if (data.message) { alert(data.message); setUserCtCardError(true); setUserCtCardLoading(false); throw new Error(data.message); } else { alert(strings.errorsUnknownError); setUserCtCardError(true); setUserCtCardLoading(false); throw new Error(strings.errorsUnknownError); } } else if (data.count) { console.log(strings.logsTotalUsers, data.count); setTotalUsers(data.count); setUserCtCardLoading(false); } } catch (error) { alert(strings.errorsFetchTotalUserCtErr); setUserCtCardError(true); setUserCtCardLoading(false); console.error(strings.errorsFetchTotalUserCtErrFancy, error); } })(); }, []); return (
{strings.errorsSuperGeneric}