Skip to content

Commit

Permalink
Merge branch 'adminV2' into SPV-1107/RemoveDeleteOption
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain authored Oct 23, 2024
2 parents aa1e2d0 + ba0a468 commit c99cbcd
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 73 deletions.
9 changes: 4 additions & 5 deletions src/components/ContactAcceptDialog/ContactAcceptDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ export const ContactAcceptDialog = ({ row }: ContactAcceptDialogProps) => {
</DialogTrigger>
<DialogContent className="max-w-xl">
<DialogHeader>
<DialogTitle>Accept Contact</DialogTitle>
<DialogDescription>
Are you sure you want to accept <span className="font-bold text-black">{row.getValue('paymail')}</span> as a
contact ?
</DialogDescription>
<DialogTitle>
Are you sure you want to <u>accept</u> the contact?
</DialogTitle>
<DialogDescription className="break-all font-bold">{row.getValue('paymail')}</DialogDescription>
</DialogHeader>
<div className="grid grid-cols-2 gap-4">
<Button onClick={handleAcceptContact} disabled={isPending}>
Expand Down
5 changes: 4 additions & 1 deletion src/components/ContactDeleteDialog/ContactDeleteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export const ContactDeleteDialog = ({ row }: ContactDeleteDialogProps) => {
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure you want to delete {row.original.paymail} contact?</DialogTitle>
<DialogTitle>
Are you sure you want to <u>delete</u> the contact?
</DialogTitle>
<DialogDescription className="break-all font-bold">{row.original.paymail}</DialogDescription>
<DialogDescription>This action cannot be undone. Please confirm your decision to proceed.</DialogDescription>
</DialogHeader>
<div className="grid grid-cols-2 gap-4">
Expand Down
9 changes: 4 additions & 5 deletions src/components/ContactRejectDialog/ContactRejectDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ export const ContactRejectDialog = ({ row }: ContactRejectDialogProps) => {
</DialogTrigger>
<DialogContent className="max-w-xl">
<DialogHeader>
<DialogTitle>Reject Contact</DialogTitle>
<DialogDescription>
Are you sure you want to reject <span className="font-bold text-black">{row.getValue('paymail')}</span> as a
contact ?
</DialogDescription>
<DialogTitle>
Are you sure you want to <u>reject</u> the contact?
</DialogTitle>
<DialogDescription className="break-all font-bold">{row.getValue('paymail')}</DialogDescription>
</DialogHeader>
<div className="grid grid-cols-2 gap-4">
<Button variant="destructive" onClick={handleRejectContact} disabled={isPending}>
Expand Down
34 changes: 34 additions & 0 deletions src/components/PageRefreshButton/PageRefreshButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useQueryClient } from '@tanstack/react-query';
import { useState } from 'react';
import { toast } from 'sonner';
import logger from '@/logger';
import { RefreshCw } from 'lucide-react';
import { cn } from '@/lib/utils.ts';
import { Button } from '@/components';

export const PageRefreshButton = () => {
const queryClient = useQueryClient();
const [isRefreshing, setIsRefreshing] = useState(false);

const onRefreshClick = async () => {
setIsRefreshing(true);
try {
// Wait for all queries invalidation (data refetching)
// and a minimum delay of 0.5sec before proceeding to make sure the UI doesn't flicker
await Promise.all([queryClient.invalidateQueries(), new Promise((resolve) => setTimeout(resolve, 500))]);
toast.success('Data refreshed');
} catch {
logger.error('Failed to refresh');
toast.error('Failed to refresh');
} finally {
setIsRefreshing(false);
}
};

return (
<Button variant="ghost" className="ml-auto" disabled={isRefreshing} onClick={onRefreshClick}>
<RefreshCw className={cn('h-4 w-4 mr-2', isRefreshing && 'animate-spin')} />
Refresh
</Button>
);
};
1 change: 1 addition & 0 deletions src/components/PageRefreshButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PageRefreshButton.tsx';
47 changes: 28 additions & 19 deletions src/components/PaymailDeleteDialog/PaymailDeleteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DialogTrigger,
DropdownMenuItem,
LoadingSpinner,
TooltipProvider,
} from '@/components';

import { useSpvWalletClient } from '@/contexts';
Expand Down Expand Up @@ -59,24 +60,32 @@ export const PaymailDeleteDialog = ({ row }: PaymailDeleteDialogProps) => {
const { isPending } = deletePaymailMutation;

return (
<Dialog open={isDeleteDialogOpen} onOpenChange={handleDeleteDialogOpen}>
<DialogTrigger className="w-full">
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>Delete</DropdownMenuItem>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure you want to delete {address} paymail?</DialogTitle>
<DialogDescription>This action cannot be undone. Please confirm your decision to proceed.</DialogDescription>
</DialogHeader>
<div className="grid grid-cols-2 gap-4">
<Button variant="destructive" onClick={handleDelete} disabled={isPending}>
Delete {isPending && <LoadingSpinner className="ml-2" />}
</Button>
<Button variant="ghost" onClick={handleDeleteDialogOpen}>
Cancel
</Button>
</div>
</DialogContent>
</Dialog>
<TooltipProvider>
<Dialog open={isDeleteDialogOpen} onOpenChange={handleDeleteDialogOpen}>
<DialogTrigger className="w-full">
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>Delete</DropdownMenuItem>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>
Are you sure you want to delete the paymail?
<br />
</DialogTitle>
<DialogDescription className="break-all font-bold">{address}</DialogDescription>
<DialogDescription>
This action cannot be undone. Please confirm your decision to proceed.
</DialogDescription>
</DialogHeader>
<div className="grid grid-cols-2 gap-4">
<Button variant="destructive" onClick={handleDelete} disabled={isPending}>
Delete {isPending && <LoadingSpinner className="ml-2" />}
</Button>
<Button variant="ghost" onClick={handleDeleteDialogOpen}>
Cancel
</Button>
</div>
</DialogContent>
</Dialog>
</TooltipProvider>
);
};
11 changes: 8 additions & 3 deletions src/components/RevokeKeyDialog/RevokeKeyDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ export const RevokeKeyDialog = ({ row }: RevokeKeyDialogProps) => {
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>Revoke</DropdownMenuItem>
</DialogTrigger>
<DialogContent className="">
<DialogHeader className="min-w-0">
<DialogTitle className="min-w-0 break-words">
Are you sure you want to revoke {row.original.id} access key?
<DialogHeader>
<DialogTitle>
Are you sure you want to <u>revoke</u> selected access key?
</DialogTitle>
<DialogDescription className="break-all font-bold text-xs">
Access key ID:
<br />
{row.original.id}
</DialogDescription>
<DialogDescription>This action cannot be undone. Please confirm your decision to proceed.</DialogDescription>
</DialogHeader>
<div className="grid grid-cols-2 gap-4">
Expand Down
5 changes: 3 additions & 2 deletions src/components/UnsubscribeWebhook/UnsubscribeWebhook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ export const UnsubscribeWebhook = ({ row }: UnsubscribeWebhookProps) => {
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Unsubscribe webhook</DialogTitle>
<DialogTitle>Are you sure you want to unsubscribe a webhook ?</DialogTitle>
</DialogHeader>
<DialogDescription>Are you sure you want to unsubscribe a webhook ?</DialogDescription>
<DialogDescription className="break-all font-bold text-xs">{row.original.url}</DialogDescription>
<DialogDescription>This action cannot be undone. Please confirm your decision to proceed.</DialogDescription>
<div className="grid grid-cols-2 gap-4">
<Button onClick={onRemove}>Unsubscribe</Button>
<Button variant="ghost" onClick={handleIsOpenToggle}>
Expand Down
41 changes: 5 additions & 36 deletions src/routes/admin/_admin.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import { Button, Logo, ModeToggle, Profile, Sheet, Tooltip, TooltipContent, TooltipTrigger } from '@/components';
import { cn } from '@/lib/utils.ts';
import logger from '@/logger';
import { useQueryClient } from '@tanstack/react-query';
import { Logo, ModeToggle, Profile, Sheet, Tooltip, TooltipContent, TooltipTrigger } from '@/components';
import { createFileRoute, Link, Outlet, redirect, useLocation } from '@tanstack/react-router';
import {
ArrowLeftRight,
KeyRound,
KeySquare,
Mail,
RefreshCw,
Route as RouteIcon,
UsersRound,
Webhook,
} from 'lucide-react';
import { ArrowLeftRight, KeyRound, KeySquare, Mail, Route as RouteIcon, UsersRound, Webhook } from 'lucide-react';

import { useEffect, useState } from 'react';
import { toast } from 'sonner';
import { PageRefreshButton } from '@/components/PageRefreshButton';

export const Route = createFileRoute('/admin/_admin')({
beforeLoad: ({ context, location }) => {
Expand All @@ -29,23 +17,6 @@ export const Route = createFileRoute('/admin/_admin')({
function LayoutComponent() {
const [route, setRoute] = useState<string>('/admin/xpub');
const { pathname } = useLocation();
const queryClient = useQueryClient();
const [isRefreshing, setIsRefreshing] = useState(false);

const onRefreshClick = async () => {
setIsRefreshing(true);
try {
// Wait for all queries invalidation (data refetching)
// and a minimum delay of 0.5sec before proceeding to make sure the UI doesn't flicker
await Promise.all([queryClient.invalidateQueries(), new Promise((resolve) => setTimeout(resolve, 500))]);
toast.success('Data refreshed');
} catch {
logger.error('Failed to refresh');
toast.error('Failed to refresh');
} finally {
setIsRefreshing(false);
}
};

useEffect(() => {
setRoute(pathname);
Expand All @@ -56,6 +27,7 @@ function LayoutComponent() {
return 'bg-accent text-accent-foreground';
}
};

return (
<div className="flex min-h-screen w-full flex-col bg-muted/40">
<aside className="fixed inset-y-0 left-0 z-10 hidden w-14 flex-col border-r bg-background sm:flex">
Expand Down Expand Up @@ -158,10 +130,7 @@ function LayoutComponent() {
<Sheet>
<h1>SPV Wallet Admin</h1>
</Sheet>
<Button variant="ghost" className="ml-auto" disabled={isRefreshing} onClick={onRefreshClick}>
<RefreshCw className={cn('h-4 w-4 mr-2', isRefreshing && 'animate-spin')} />
Refresh
</Button>
<PageRefreshButton />
<ModeToggle />
<Profile />
</header>
Expand Down
6 changes: 4 additions & 2 deletions src/routes/user/_user.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Outlet, createFileRoute, Link, useLocation, redirect } from '@tanstack/react-router';
import { createFileRoute, Link, Outlet, redirect, useLocation } from '@tanstack/react-router';

import { KeySquare, Route as RouteIcon, ArrowLeftRight } from 'lucide-react';
import { ArrowLeftRight, KeySquare, Route as RouteIcon } from 'lucide-react';

import { useEffect, useState } from 'react';

import { Logo, ModeToggle, Profile, Sheet, Tooltip, TooltipContent, TooltipTrigger } from '@/components';
import { PageRefreshButton } from '@/components/PageRefreshButton';

export const Route = createFileRoute('/user/_user')({
beforeLoad: ({ context, location }) => {
Expand Down Expand Up @@ -82,6 +83,7 @@ function LayoutComponent() {
<Sheet>
<h1>SPV Wallet Admin</h1>
</Sheet>
<PageRefreshButton />
<ModeToggle />
<Profile />
</header>
Expand Down

0 comments on commit c99cbcd

Please sign in to comment.