|
6 | 6 |
|
7 | 7 | import { queryOptions } from "@tanstack/react-query"; |
8 | 8 | import { createFileRoute, redirect } from "@tanstack/react-router"; |
9 | | -import { zodSearchValidator } from "@tanstack/router-zod-adapter"; |
10 | | -import * as z from "zod"; |
| 9 | +import * as v from "valibot"; |
11 | 10 | import { query as userEmailListQuery } from "../components/UserProfile/UserEmailList"; |
12 | 11 | import { graphql } from "../gql"; |
13 | 12 | import { graphqlRequest } from "../graphql"; |
@@ -38,39 +37,39 @@ export const query = queryOptions({ |
38 | 37 | queryFn: ({ signal }) => graphqlRequest({ query: QUERY, signal }), |
39 | 38 | }); |
40 | 39 |
|
41 | | -const actionSchema = z |
42 | | - .discriminatedUnion("action", [ |
43 | | - z.object({ |
44 | | - action: z.enum(["profile", "org.matrix.profile"]), |
| 40 | +const actionSchema = v.variant("action", [ |
| 41 | + v.object({ |
| 42 | + action: v.picklist(["profile", "org.matrix.profile"]), |
| 43 | + }), |
| 44 | + v.object({ |
| 45 | + action: v.picklist(["sessions_list", "org.matrix.sessions_list"]), |
| 46 | + }), |
| 47 | + v.object({ |
| 48 | + action: v.picklist(["session_view", "org.matrix.session_view"]), |
| 49 | + device_id: v.optional(v.string()), |
| 50 | + }), |
| 51 | + v.object({ |
| 52 | + action: v.picklist(["session_end", "org.matrix.session_end"]), |
| 53 | + device_id: v.optional(v.string()), |
| 54 | + }), |
| 55 | + v.object({ |
| 56 | + action: v.literal("org.matrix.cross_signing_reset"), |
| 57 | + }), |
| 58 | + v.partial( |
| 59 | + v.looseObject({ |
| 60 | + action: v.never(), |
45 | 61 | }), |
46 | | - z.object({ |
47 | | - action: z.enum(["sessions_list", "org.matrix.sessions_list"]), |
48 | | - }), |
49 | | - z.object({ |
50 | | - action: z.enum(["session_view", "org.matrix.session_view"]), |
51 | | - device_id: z.string().optional(), |
52 | | - }), |
53 | | - z.object({ |
54 | | - action: z.enum(["session_end", "org.matrix.session_end"]), |
55 | | - device_id: z.string().optional(), |
56 | | - }), |
57 | | - z.object({ |
58 | | - action: z.literal("org.matrix.cross_signing_reset"), |
59 | | - }), |
60 | | - z.object({ |
61 | | - action: z.undefined(), |
62 | | - }), |
63 | | - ]) |
64 | | - .catch({ action: undefined }); |
| 62 | + ), |
| 63 | +]); |
65 | 64 |
|
66 | 65 | export const Route = createFileRoute("/_account/")({ |
67 | | - validateSearch: zodSearchValidator(actionSchema), |
| 66 | + validateSearch: actionSchema, |
68 | 67 |
|
69 | 68 | beforeLoad({ search }) { |
70 | 69 | switch (search.action) { |
71 | 70 | case "profile": |
72 | 71 | case "org.matrix.profile": |
73 | | - throw redirect({ to: "/" }); |
| 72 | + throw redirect({ to: "/", search: {} }); |
74 | 73 |
|
75 | 74 | case "sessions_list": |
76 | 75 | case "org.matrix.sessions_list": |
|
0 commit comments