Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/SPV-1010/WebhookView' into SPV-1…
Browse files Browse the repository at this point in the history
…010/WebhookView
  • Loading branch information
Nazarii-4chain committed Sep 25, 2024
2 parents 6ae7df0 + 51d7f72 commit 6c89b44
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
71 changes: 58 additions & 13 deletions src/components/DateRangeFilter/DateRangeFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { useNavigate } from '@tanstack/react-router';
import { addDays, format, subDays } from 'date-fns';
import { Calendar as CalendarIcon, ListFilter } from 'lucide-react';

import React, { useState } from 'react';

import { DateRange } from 'react-day-picker';

import { Button } from '@/components/ui';
import { Calendar } from '@/components/ui/calendar.tsx';
import { Label } from '@/components/ui/label.tsx';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover.tsx';

import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group.tsx';
import { cn } from '@/lib/utils.ts';
import { Route } from '@/routes/admin/_admin.access-keys.tsx';
import { useLocation, useNavigate } from '@tanstack/react-router';
import { addDays, format, subDays } from 'date-fns';
import { Calendar as CalendarIcon, ListFilter } from 'lucide-react';

import React, { useState } from 'react';

import { DateRange } from 'react-day-picker';
import { toast } from 'sonner';

export interface DateRangeFilterProps {
withRevokedRange?: boolean;
Expand All @@ -32,14 +31,25 @@ export const DateRangeFilter = ({ withRevokedRange, className }: DateRangeFilter
const [dateRangeOption, setDateRangeOption] = useState<string>('createdRange');
const [date, setDate] = React.useState<DateRange | undefined>(initialTimeRange);

const navigate = useNavigate({ from: Route.fullPath });
const {
search: { updatedRange, createdRange, revokedRange },
} = useLocation();

const navigate = useNavigate();

const onApplyDateRange = () => {
navigate({
search: (old) => {

Check failure on line 42 in src/components/DateRangeFilter/DateRangeFilter.tsx

View workflow job for this annotation

GitHub Actions / compile

Type '(old: { id?: string | undefined; address?: string | undefined; page?: number | undefined; createdRange?: { from: string; to: string; } | { from: string; to: string; } | { from: string; to: string; } | { ...; } | { ...; } | { ...; } | undefined; ... 9 more ...; lockingScript?: string | undefined; }) => { ...; }' is not assignable to type 'true | ParamsReducerFn<Router<RootRoute<undefined, RouterContext, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes>, TrailingSlashOption, Record<...>, Record<...>>, "SEARCH", string, string | undefined> | undefined'.
delete old?.createdRange;
delete old?.updatedRange;
delete old?.revokedRange;
if ('createdRange' in old) {
delete old.createdRange;
}
if ('updatedRange' in old) {
delete old.updatedRange;
}
if ('revokedRange' in old) {
delete old.revokedRange;
}

return {
...old,
[dateRangeOption]: {
Expand All @@ -50,6 +60,28 @@ export const DateRangeFilter = ({ withRevokedRange, className }: DateRangeFilter
},
replace: true,
});
toast.success('Date range applied');
};

const onClearDateRange = () => {
navigate({
search: (old) => {
if ('createdRange' in old) {
delete old.createdRange;
}
if ('updatedRange' in old) {
delete old.updatedRange;
}
if ('revokedRange' in old) {
delete old.revokedRange;
}
return {
...old,
};
},
replace: true,
});
toast.success('Date range cleared');
};

return (
Expand All @@ -58,6 +90,11 @@ export const DateRangeFilter = ({ withRevokedRange, className }: DateRangeFilter
<Button variant="outline">
<ListFilter className="w-5 h-5" />
<span className="ml-2">Filter</span>
{createdRange || updatedRange || revokedRange ? (
<span className="ml-2 bg-black/80 rounded-full text-white h-6 w-6 text-xs flex justify-center items-center">
1
</span>
) : null}
</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
Expand Down Expand Up @@ -122,6 +159,14 @@ export const DateRangeFilter = ({ withRevokedRange, className }: DateRangeFilter
<Button onClick={onApplyDateRange} className="mt-4 w-full" variant="default">
Apply
</Button>
<Button onClick={onClearDateRange} className="mt-4 w-full" variant="secondary">
Reset
</Button>
<div className="font-medium leading-none mt-4 text-sm">
Applied Filters: {createdRange && 'Created Range'}
{updatedRange && 'Updated Range'}
{revokedRange && 'Revoked Range'}
</div>
</PopoverContent>
</Popover>
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/webhooksQueryOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export const webhooksQueryOptions = (opts: WebhooksQueryOptions) => {

return queryOptions({
queryKey: ['webhooks', opts],
queryFn: async () => await spvWalletClient.AdminGetWebhooks(),
queryFn: () => spvWalletClient.AdminGetWebhooks(),
});
};

0 comments on commit 6c89b44

Please sign in to comment.