https://dev.kronoz.win/r/marzneshin.git
| 1 |
4708fcb |
Dawsh |
2y ago |
import { |
| 2 |
4708fcb |
Dawsh |
2y ago |
createFileRoute, |
| 3 |
4708fcb |
Dawsh |
2y ago |
Outlet, |
| 4 |
4708fcb |
Dawsh |
2y ago |
} from "@tanstack/react-router"; |
| 5 |
4708fcb |
Dawsh |
2y ago |
import { useSuspenseQuery } from "@tanstack/react-query"; |
| 6 |
d636f3f |
Dawsh |
2y ago |
import { queryClient } from "@marzneshin/common/utils"; |
| 7 |
4708fcb |
Dawsh |
2y ago |
import { |
| 8 |
4708fcb |
Dawsh |
2y ago |
RouterAdminContext, |
| 9 |
4708fcb |
Dawsh |
2y ago |
adminQueryOptions, |
| 10 |
7738ec1 |
Mardin |
2y ago |
} from "@marzneshin/modules/admins"; |
| 11 |
4708fcb |
Dawsh |
2y ago |
import { Suspense, useMemo } from "react"; |
| 12 |
4708fcb |
Dawsh |
2y ago |
import { |
| 13 |
4708fcb |
Dawsh |
2y ago |
AlertDialog, |
| 14 |
4708fcb |
Dawsh |
2y ago |
AlertDialogContent, |
| 15 |
7389ad0 |
Mardin |
2y ago |
} from "@marzneshin/common/components"; |
| 16 |
4708fcb |
Dawsh |
2y ago |
|
| 17 |
4708fcb |
Dawsh |
2y ago |
const AdminProvider = () => { |
| 18 |
4708fcb |
Dawsh |
2y ago |
const { username } = Route.useLoaderData() |
| 19 |
4708fcb |
Dawsh |
2y ago |
const { data: admin, isPending } = useSuspenseQuery(adminQueryOptions({ username })) |
| 20 |
4708fcb |
Dawsh |
2y ago |
const value = useMemo(() => ({ admin, isPending }), [admin, isPending]) |
| 21 |
4708fcb |
Dawsh |
2y ago |
return ( |
| 22 |
4708fcb |
Dawsh |
2y ago |
<RouterAdminContext.Provider value={value}> |
| 23 |
4708fcb |
Dawsh |
2y ago |
<Suspense> |
| 24 |
4708fcb |
Dawsh |
2y ago |
<Outlet /> |
| 25 |
4708fcb |
Dawsh |
2y ago |
</Suspense> |
| 26 |
4708fcb |
Dawsh |
2y ago |
</RouterAdminContext.Provider> |
| 27 |
4708fcb |
Dawsh |
2y ago |
) |
| 28 |
4708fcb |
Dawsh |
2y ago |
} |
| 29 |
4708fcb |
Dawsh |
2y ago |
|
| 30 |
4708fcb |
Dawsh |
2y ago |
export const Route = createFileRoute('/_dashboard/admins/$adminId')({ |
| 31 |
4708fcb |
Dawsh |
2y ago |
loader: async ({ params }) => { |
| 32 |
4708fcb |
Dawsh |
2y ago |
queryClient.ensureQueryData(adminQueryOptions({ username: params.adminId })) |
| 33 |
4708fcb |
Dawsh |
2y ago |
return { username: params.adminId }; |
| 34 |
4708fcb |
Dawsh |
2y ago |
}, |
| 35 |
4708fcb |
Dawsh |
2y ago |
errorComponent: () => ( |
| 36 |
4708fcb |
Dawsh |
2y ago |
<AlertDialog open={true}> |
| 37 |
4708fcb |
Dawsh |
2y ago |
<AlertDialogContent>Admin not found</AlertDialogContent> |
| 38 |
4708fcb |
Dawsh |
2y ago |
</AlertDialog> |
| 39 |
4708fcb |
Dawsh |
2y ago |
), |
| 40 |
4708fcb |
Dawsh |
2y ago |
component: AdminProvider, |
| 41 |
4708fcb |
Dawsh |
2y ago |
}) |