11import type { FormProps } from "antd" ;
22import {
3- Form ,
4- Input ,
5- Select ,
6- Space ,
73 Button ,
8- Result ,
94 Card ,
105 Divider ,
116 Flex ,
7+ Form ,
8+ Input ,
9+ Result ,
10+ Select ,
11+ Space ,
1212 Typography ,
1313} from "antd" ;
14+ import { useState } from "react" ;
15+ import { useAppDispatch } from "../../hooks" ;
16+ import type { Register201ResponseData } from "../../spaceTraderAPI/api" ;
17+ import { FactionSymbol } from "../../spaceTraderAPI/api" ;
18+ import { addAgent , setMyAgent } from "../../spaceTraderAPI/redux/agentSlice" ;
19+ import { setAgentSymbol } from "../../spaceTraderAPI/redux/configSlice" ;
20+ import { putContract } from "../../spaceTraderAPI/redux/contractSlice" ;
21+ import { setShips } from "../../spaceTraderAPI/redux/fleetSlice" ;
22+ import spaceTraderClient from "../../spaceTraderAPI/spaceTraderClient" ;
1423import AgentDisp from "../disp/AgentDisp" ;
1524import ContractDisp from "../disp/ContractDisp" ;
1625import FactionDisp from "../disp/FactionDisp" ;
1726import ShipDisp from "../disp/ship/ShipDisp" ;
18- import { addAgent , setMyAgent } from "../../spaceTraderAPI/redux/agentSlice" ;
19- import { putContract } from "../../spaceTraderAPI/redux/contractSlice" ;
20- import { setShip } from "../../spaceTraderAPI/redux/fleetSlice" ;
21- import spaceTraderClient from "../../spaceTraderAPI/spaceTraderClient" ;
22- import { useState } from "react" ;
23- import type {
24- FactionSymbol ,
25- Register201ResponseData ,
26- } from "../../spaceTraderAPI/api" ;
27- import { useAppDispatch } from "../../hooks" ;
28- import { setAgentSymbol } from "../../spaceTraderAPI/redux/configSlice" ;
2927
3028type createAgentType = {
3129 callsign : string ;
3230 email ?: string ;
3331 faction : FactionSymbol ;
32+ accountToken : string ;
3433} ;
3534
3635const tailLayout = {
@@ -55,15 +54,15 @@ function CreateAgent() {
5554 const onCreate : FormProps < createAgentType > [ "onFinish" ] = ( values ) => {
5655 console . log ( "Success:" , values ) ;
5756
58- spaceTraderClient . DefaultClient . register (
57+ spaceTraderClient . GlobalClient . register (
5958 {
6059 symbol : values . callsign ,
6160 faction : values . faction ,
6261 email : values . email ,
6362 } ,
6463 {
6564 transformRequest : ( data , headers ) => {
66- delete headers [ "Authorization" ] ;
65+ headers [ "Authorization" ] = `Bearer ${ values . accountToken } ` ;
6766 return data ;
6867 } ,
6968 } ,
@@ -84,7 +83,7 @@ function CreateAgent() {
8483 agentSymbol : answer . data . data . agent . symbol ,
8584 } ) ,
8685 ) ;
87- dispatch ( setShip ( answer . data . data . ship ) ) ;
86+ dispatch ( setShips ( answer . data . data . ships || [ ] ) ) ;
8887 } ) ;
8988 } ;
9089
@@ -98,6 +97,13 @@ function CreateAgent() {
9897 name = "createAgent"
9998 style = { { maxWidth : 600 } }
10099 >
100+ < Form . Item
101+ name = "accountToken"
102+ label = "AccountToken"
103+ rules = { [ { required : true } ] }
104+ >
105+ < Input placeholder = "Enter a AccountToken" />
106+ </ Form . Item >
101107 < Form . Item
102108 name = "callsign"
103109 label = "Callsign"
@@ -121,27 +127,12 @@ function CreateAgent() {
121127 < Select
122128 placeholder = "Select a faction"
123129 allowClear
124- options = { [
125- { value : "COSMIC" , label : "COSMIC" } ,
126- { value : "VOID" , label : "VOID" } ,
127- { value : "GALACTIC" , label : "GALACTIC" } ,
128- { value : "QUANTUM" , label : "QUANTUM" } ,
129- { value : "DOMINION" , label : "DOMINION" } ,
130- { value : "ASTRO" , label : "ASTRO" } ,
131- { value : "CORSAIRS" , label : "CORSAIRS" } ,
132- { value : "OBSIDIAN" , label : "OBSIDIAN" } ,
133- { value : "AEGIS" , label : "AEGIS" } ,
134- { value : "UNITED" , label : "UNITED" } ,
135- { value : "SOLITARY" , label : "SOLITARY" } ,
136- { value : "COBALT" , label : "COBALT" } ,
137- { value : "OMEGA" , label : "OMEGA" } ,
138- { value : "ECHO" , label : "ECHO" } ,
139- { value : "LORDS" , label : "LORDS" } ,
140- { value : "CULT" , label : "CULT" } ,
141- { value : "ANCIENTS" , label : "ANCIENTS" } ,
142- { value : "SHADOW" , label : "SHADOW" } ,
143- { value : "ETHEREAL" , label : "ETHEREAL" } ,
144- ] }
130+ options = { Object . values ( FactionSymbol ) . map ( ( value ) => {
131+ return {
132+ label : value ,
133+ value : value ,
134+ } ;
135+ } ) }
145136 > </ Select >
146137 </ Form . Item >
147138 < Form . Item { ...tailLayout } >
@@ -172,7 +163,9 @@ function CreateAgent() {
172163 < Flex wrap gap = "middle" align = "center" justify = "space-evenly" >
173164 < AgentDisp agent = { newAgent . agent } > </ AgentDisp >
174165 < FactionDisp faction = { newAgent . faction } > </ FactionDisp >
175- < ShipDisp ship = { newAgent . ship } > </ ShipDisp >
166+ { ( newAgent . ships || [ ] ) . map ( ( ship ) => (
167+ < ShipDisp ship = { ship } > </ ShipDisp >
168+ ) ) }
176169 < ContractDisp contract = { newAgent . contract } > </ ContractDisp >
177170 </ Flex >
178171 </ Card > ,
0 commit comments