1
1
import { Field , NumberInput } from "@ark-ui/react" ;
2
2
import { Icon } from "@iconify/react" ;
3
- import { createFileRoute } from "@tanstack/react-router" ;
3
+ import { createFileRoute , useNavigate } from "@tanstack/react-router" ;
4
4
import { useSetAtom } from "jotai" ;
5
5
import { Grid , styled as p , VStack } from "panda/jsx" ;
6
6
import { useState , type ReactElement } from "react" ;
7
+ import useSWRImmutable from "swr/immutable" ;
7
8
import { z } from "zod" ;
8
9
import { IconText } from "@/components/IconText" ;
9
10
import { Button } from "@/components/cva/Button" ;
@@ -13,6 +14,7 @@ import { svaTextArea } from "@/components/sva/textArea";
13
14
import { User } from "@/lib/classes/user" ;
14
15
import { $redirectTo } from "@/lib/stores/redirect" ;
15
16
import { notifyTableErrorInToast } from "@/lib/utils/table" ;
17
+ import { toaster } from "@/lib/utils/toast" ;
16
18
17
19
export const Route = createFileRoute ( "/user/" ) ( {
18
20
validateSearch : ( s ) =>
@@ -36,16 +38,23 @@ export const Route = createFileRoute("/user/")({
36
38
} ) ;
37
39
38
40
function Authenticated ( { user } : { user : User } ) : ReactElement {
39
- const [ selected , setSelected ] = useState < "sower" | "sponsor" | null > ( ) ;
40
41
const [ age , setAge ] = useState ( 0 ) ;
42
+ const [ selected , setSelected ] = useState < "sower" | "sponsor" | null > ( null ) ;
41
43
const [ description , setDescription ] = useState ( "" ) ;
44
+ const navigate = useNavigate ( ) ;
42
45
const numberInput = svaNumberInput ( ) ;
43
46
const textArea = svaTextArea ( ) ;
44
47
48
+ const swrUserKindOf = useSWRImmutable ( "userKindOf" , async ( ) =>
49
+ (
50
+ await user . fetchKindOf ( ) . mapErr ( notifyTableErrorInToast ( "swrUserKindOf" ) )
51
+ ) . _unsafeUnwrap ( ) ,
52
+ ) ;
53
+
45
54
return (
46
55
< Expanded items = "center" >
47
56
< VStack gap = "10" p = "10" >
48
- { selected == null && (
57
+ { swrUserKindOf . data ?. type === "UNKNOWN" && (
49
58
< >
50
59
< p . span fontSize = "xl" fontWeight = "bold" >
51
60
アカウントタイプを選択して下さい
@@ -149,7 +158,15 @@ function Authenticated({ user }: { user: User }): ReactElement {
149
158
name : user . metadata . name ?? "名無し" ,
150
159
birthday : `${ new Date ( ) . getFullYear ( ) - age } -10-05T14:48:00.000Z` ,
151
160
} )
152
- . mapErr ( notifyTableErrorInToast ( "User.registerAsASower" ) ) ;
161
+ . mapErr ( notifyTableErrorInToast ( "User.registerAsASower" ) )
162
+ . andTee ( ( ) => {
163
+ void navigate ( { to : "/" } ) ;
164
+ } ) ;
165
+ toaster . success ( {
166
+ id : "register-as-sower" ,
167
+ title : "市民としてログインしました" ,
168
+ description : "ようこそ!" ,
169
+ } ) ;
153
170
} }
154
171
variant = "outlined"
155
172
w = "300px"
@@ -179,11 +196,21 @@ function Authenticated({ user }: { user: User }): ReactElement {
179
196
< Button
180
197
h = "100px"
181
198
onClick = { ( ) => {
182
- void user . registerAsASponsor ( {
183
- user_id : user . id ,
184
- name : user . metadata . name ,
185
- icon : user . metadata . picture ,
186
- description,
199
+ void user
200
+ . registerAsASponsor ( {
201
+ user_id : user . id ,
202
+ name : user . metadata . name ,
203
+ icon : user . metadata . picture ,
204
+ description,
205
+ } )
206
+ . mapErr ( notifyTableErrorInToast ( "Button.企業としてログイン" ) )
207
+ . andTee ( ( ) => {
208
+ void navigate ( { to : "/" } ) ;
209
+ } ) ;
210
+ toaster . success ( {
211
+ id : "register-as-sponsor" ,
212
+ title : "企業としてログインしました" ,
213
+ description : "ようこそ!" ,
187
214
} ) ;
188
215
} }
189
216
variant = "outlined"
0 commit comments