Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet): integrate dynamic user ID fetching across wallet pages #23

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
29 changes: 0 additions & 29 deletions app/admin/user/page.tsx

This file was deleted.

42 changes: 42 additions & 0 deletions app/admin/users/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { getAllUsers } from '@/lib/actions/admin';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { UsersTable } from '@/components/shared/admin/users-table';
import { ShieldAlert } from 'lucide-react';

export default async function AdminUsersPage() {
const response = await getAllUsers();

return (
<div className="container mx-auto py-8">
<Card className="mt-10">
<CardHeader className="bg-gradient-to-r from-blue-600 to-purple-600">
<CardTitle className="text-2xl text-white">User Management</CardTitle>
<CardDescription className="text-white/90">
Manage all users across the platform
</CardDescription>
</CardHeader>
<CardContent className="p-6">
{response.error ? (
<div className="flex h-[400px] w-full items-center justify-center">
<div className="text-center">
<ShieldAlert className="mx-auto h-12 w-12 text-muted-foreground" />
<h3 className="mt-4 text-lg font-semibold">Access Denied</h3>
<p className="mt-2 text-sm text-muted-foreground">
{response.error}
</p>
</div>
</div>
) : (
<UsersTable users={response.data ?? []} />
)}
</CardContent>
</Card>
</div>
);
}
5 changes: 3 additions & 2 deletions app/faucet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Skeleton } from '@/components/ui/skeleton';
import { AlertCircle } from 'lucide-react';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { fetchUser } from '@/lib/prisma';
import { getUserId } from '@/lib/actions/user';

export default function WalletPage() {
const [wallet, setWallet] = useState<WalletDetails | null>(null);
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(true);

const userId = '7c3bb2a7-6759-415b-a3b8-9fea642c9c20';

useEffect(() => {
async function fetchWallet() {
try {
setLoading(true);
setError(null);
const userId = await getUserId();
const fetchedWallet = await getUserWallet(userId);

if (!fetchedWallet) {
Expand Down
13 changes: 9 additions & 4 deletions app/wallet/create-wallet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import type { Wallet } from '@/types/wallet';
import { toast } from 'sonner';
import { WalletDetails } from '@/components/shared/WalletDetails';
import { getUserId } from '@/lib/actions/user';

export default function WalletPage() {
const [walletDetails, setWalletDetails] = useState<Wallet | null>(null);
Expand All @@ -35,7 +36,7 @@ export default function WalletPage() {
const generateNewWallet = async () => {
try {
setLoading(true);
const userId = '7c3bb2a7-6759-415b-a3b8-9fea642c9c20';
const userId = await getUserId();

const secureInfo = await createUserWallet(userId);
const wallet = await getUserWallet(userId);
Expand All @@ -54,7 +55,9 @@ export default function WalletPage() {
description: 'New wallet generated successfully',
});
} catch (err) {
const errorMessage = `Wallet generation failed: ${err instanceof Error ? err.message : String(err)}`;
const errorMessage = `Wallet generation failed: ${
err instanceof Error ? err.message : String(err)
}`;
setError(errorMessage);
toast.error('Error', {
description: errorMessage,
Expand All @@ -74,7 +77,7 @@ export default function WalletPage() {
);
}

const userId = '7c3bb2a7-6759-415b-a3b8-9fea642c9c20';
const userId = await getUserId();
const secureInfo = await recoverUserWallet(
userId,
recoveryInput,
Expand All @@ -93,7 +96,9 @@ export default function WalletPage() {
description: 'Wallet recovered successfully',
});
} catch (err) {
const errorMessage = `Recovery failed: ${err instanceof Error ? err.message : String(err)}`;
const errorMessage = `Recovery failed: ${
err instanceof Error ? err.message : String(err)
}`;
setError(errorMessage);
toast.error('Error', {
description: errorMessage,
Expand Down
3 changes: 2 additions & 1 deletion app/wallet/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { WalletDashboard } from '@/components/shared/WalletDashboard';
import { getUserId } from '@/lib/actions/user';
import { getUsers, getUserWallet } from '@/lib/actions/wallet';
import { redirect } from 'next/navigation';

export default async function DashboardPage() {
const userId = '7c3bb2a7-6759-415b-a3b8-9fea642c9c20';
const userId = await getUserId();
const wallet = await getUserWallet(userId);
const user = await getUsers();

Expand Down
13 changes: 13 additions & 0 deletions components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ export const Header: React.FC = async () => {
</a>
</div>
<div className="flex gap-0.5">
<Link
className="px-3 py-2 hover:bg-accent hover:text-accent-foreground rounded-md transition-colors"
href="/wallet/dashboard"
>
Dashboard
</Link>
<Link
className="px-3 py-2 hover:bg-accent hover:text-accent-foreground rounded-md transition-colors"
href="/settings"
>
Settings
</Link>
{}
<Link
className="px-3 py-2 hover:bg-accent hover:text-accent-foreground rounded-md transition-colors"
href="/admin/users"
>
Users
</Link>
<ModeToggle />
<HistoryContainer location="header" />
</div>
Expand Down
Loading