-
Notifications
You must be signed in to change notification settings - Fork 38
feat: soft deletes, lastActiveAt tracking, and admin trail search #2371
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
Changes from 6 commits
11c8830
c29c02d
5d6ab27
a1c810f
8c46de1
ddba1cc
652f155
b20b465
6ba096f
955ffc2
66b93be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,9 @@ import { SearchInput } from 'admin-app/components/search-input'; | |||||
| import { type AdminPack, deletePack, getPacks } from 'admin-app/lib/api'; | ||||||
| import { formatDate } from 'admin-app/lib/date'; | ||||||
| import { queryKeys } from 'admin-app/lib/queryKeys'; | ||||||
| import { cn } from 'admin-app/lib/utils'; | ||||||
| import { useSearchParams } from 'next/navigation'; | ||||||
| import { useState } from 'react'; | ||||||
|
|
||||||
| function TableSkeleton() { | ||||||
| return ( | ||||||
|
|
@@ -41,6 +43,7 @@ function TableSkeleton() { | |||||
|
|
||||||
| function PackRow({ pack }: { pack: AdminPack }) { | ||||||
| const queryClient = useQueryClient(); | ||||||
| const isDeleted = pack.deleted; | ||||||
|
|
||||||
| const { mutateAsync: handleDelete } = useMutation({ | ||||||
| mutationFn: () => deletePack(pack.id), | ||||||
|
|
@@ -50,13 +53,18 @@ function PackRow({ pack }: { pack: AdminPack }) { | |||||
| }); | ||||||
|
|
||||||
| return ( | ||||||
| <TableRow className="hover:bg-muted/20"> | ||||||
| <TableRow className={cn('hover:bg-muted/20', isDeleted && 'opacity-50')}> | ||||||
| <TableCell> | ||||||
| <div> | ||||||
| <p className="text-sm font-medium">{pack.name}</p> | ||||||
| {pack.description && ( | ||||||
| <p className="text-xs text-muted-foreground line-clamp-1">{pack.description}</p> | ||||||
| )} | ||||||
| {isDeleted && ( | ||||||
| <p className="text-xs text-destructive"> | ||||||
| Deleted {pack.deletedAt ? formatDate(new Date(pack.deletedAt)) : ''} | ||||||
| </p> | ||||||
| )} | ||||||
| </div> | ||||||
| </TableCell> | ||||||
| <TableCell> | ||||||
|
|
@@ -69,7 +77,10 @@ function PackRow({ pack }: { pack: AdminPack }) { | |||||
| </TableCell> | ||||||
| <TableCell> | ||||||
| <span | ||||||
| className={`text-xs font-medium ${pack.isPublic ? 'text-green-500' : 'text-muted-foreground'}`} | ||||||
| className={cn( | ||||||
| 'text-xs font-medium', | ||||||
| pack.isPublic ? 'text-green-500' : 'text-muted-foreground', | ||||||
| )} | ||||||
| > | ||||||
| {pack.isPublic ? 'Public' : 'Private'} | ||||||
| </span> | ||||||
|
|
@@ -80,13 +91,15 @@ function PackRow({ pack }: { pack: AdminPack }) { | |||||
| </span> | ||||||
| </TableCell> | ||||||
| <TableCell> | ||||||
| <DeleteButton | ||||||
| label={pack.name} | ||||||
| description="The pack will be soft-deleted and hidden from all users." | ||||||
| onConfirm={async () => { | ||||||
| await handleDelete(); | ||||||
| }} | ||||||
| /> | ||||||
| {!isDeleted && ( | ||||||
| <DeleteButton | ||||||
| label={pack.name} | ||||||
| description="The pack will be soft-deleted and hidden from all users." | ||||||
| onConfirm={async () => { | ||||||
| await handleDelete(); | ||||||
| }} | ||||||
| /> | ||||||
| )} | ||||||
| </TableCell> | ||||||
| </TableRow> | ||||||
| ); | ||||||
|
|
@@ -95,16 +108,20 @@ function PackRow({ pack }: { pack: AdminPack }) { | |||||
| export default function PacksPage() { | ||||||
| const searchParams = useSearchParams(); | ||||||
| const q = searchParams?.get('q') ?? undefined; | ||||||
| const [includeDeleted, setIncludeDeleted] = useState(false); | ||||||
|
|
||||||
| const { | ||||||
| data: packs = [], | ||||||
| data: result, | ||||||
| isLoading, | ||||||
| isError, | ||||||
| } = useQuery({ | ||||||
| queryKey: queryKeys.admin.packs(q), | ||||||
|
||||||
| queryKey: queryKeys.admin.packs(q), | |
| queryKey: [...queryKeys.admin.packs(q), { includeDeleted }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
invalidateQuerieskey here usesqueryKeys.admin.packs()(=>['admin','packs', undefined]) but the list query is keyed byqueryKeys.admin.packs(q)(and should also includeincludeDeleted). As written, the cache invalidation may not refresh the list the user is viewing. Invalidate using a stable prefix like['admin','packs'], and includeincludeDeletedin the list query key.