11import { MagnifyingGlassIcon } from "@heroicons/react/20/solid" ;
22import { Form } from "@remix-run/react" ;
3- import type { ActionFunctionArgs , LoaderFunctionArgs } from "@remix-run/server-runtime" ;
4- import { redirect } from "@remix-run/server-runtime" ;
3+ import type { LoaderFunctionArgs } from "@remix-run/server-runtime" ;
54import { typedjson , useTypedLoaderData } from "remix-typedjson" ;
65import { z } from "zod" ;
76import { Button , LinkButton } from "~/components/primitives/Buttons" ;
87import { CopyableText } from "~/components/primitives/CopyableText" ;
9- import { Header1 } from "~/components/primitives/Headers" ;
108import { Input } from "~/components/primitives/Input" ;
119import { PaginationControls } from "~/components/primitives/Pagination" ;
1210import { Paragraph } from "~/components/primitives/Paragraph" ;
@@ -19,9 +17,7 @@ import {
1917 TableHeaderCell ,
2018 TableRow ,
2119} from "~/components/primitives/Table" ;
22- import { useUser } from "~/hooks/useUser" ;
23- import { adminGetUsers , redirectWithImpersonation } from "~/models/admin.server" ;
24- import { commitImpersonationSession , setImpersonationId } from "~/services/impersonation.server" ;
20+ import { adminGetUsers } from "~/models/admin.server" ;
2521import { requireUserId } from "~/services/session.server" ;
2622import { createSearchParams } from "~/utils/searchParams" ;
2723
@@ -32,7 +28,7 @@ export const SearchParams = z.object({
3228
3329export type SearchParams = z . infer < typeof SearchParams > ;
3430
35- export const loader = async ( { request, params } : LoaderFunctionArgs ) => {
31+ export const loader = async ( { request } : LoaderFunctionArgs ) => {
3632 const userId = await requireUserId ( request ) ;
3733
3834 const searchParams = createSearchParams ( request . url , SearchParams ) ;
@@ -44,21 +40,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
4440 return typedjson ( result ) ;
4541} ;
4642
47- const FormSchema = z . object ( { id : z . string ( ) } ) ;
48-
49- export async function action ( { request } : ActionFunctionArgs ) {
50- if ( request . method . toLowerCase ( ) !== "post" ) {
51- return new Response ( "Method not allowed" , { status : 405 } ) ;
52- }
53-
54- const payload = Object . fromEntries ( await request . formData ( ) ) ;
55- const { id } = FormSchema . parse ( payload ) ;
56-
57- return redirectWithImpersonation ( request , id , "/" ) ;
58- }
59-
6043export default function AdminDashboardRoute ( ) {
61- const user = useUser ( ) ;
6244 const { users, filters, page, pageCount } = useTypedLoaderData < typeof loader > ( ) ;
6345
6446 return (
@@ -136,7 +118,7 @@ export default function AdminDashboardRoute() {
136118 </ TableCell >
137119 < TableCell > { user . admin ? "✅" : "" } </ TableCell >
138120 < TableCell isSticky = { true } >
139- < Form method = "post" reloadDocument >
121+ < Form method = "post" action = "/admin/impersonate" reloadDocument >
140122 < input type = "hidden" name = "id" value = { user . id } />
141123 < Button
142124 type = "submit"
0 commit comments