@@ -29,20 +29,15 @@ import { SingleDatepicker } from "chakra-dayzed-datepicker";
29
29
import { Card , Col , Row } from "react-bootstrap" ;
30
30
import ResidentAPIClient from "../../APIClients/ResidentAPIClient" ;
31
31
import { Resident } from "../../types/ResidentTypes" ;
32
-
32
+ import BuildingAPIClient from "../../APIClients/BuildingAPIClient" ;
33
+ import { BuildingLabel } from "../../types/BuildingTypes" ;
33
34
import selectStyle from "../../theme/forms/selectStyles" ;
34
35
import { singleDatePickerStyle } from "../../theme/forms/datePickerStyles" ;
35
36
import CreateToast from "../common/Toasts" ;
36
37
import { convertToDate , convertToString } from "../../helper/dateHelpers" ;
37
38
38
- // TODO: Connect to Buidings table
39
- const BUILDINGS = [
40
- { label : "144" , value : 1 } ,
41
- { label : "362" , value : 2 } ,
42
- { label : "402" , value : 3 } ,
43
- ] ;
44
-
45
39
type Props = {
40
+ buildingOptions : BuildingLabel [ ] ,
46
41
resident : Resident ;
47
42
isOpen : boolean ;
48
43
userPageNum : number ;
@@ -51,6 +46,7 @@ type Props = {
51
46
} ;
52
47
53
48
const EditResident = ( {
49
+ buildingOptions,
54
50
resident,
55
51
isOpen,
56
52
userPageNum,
@@ -60,7 +56,7 @@ const EditResident = ({
60
56
const [ initials , setInitials ] = useState ( "" ) ;
61
57
const [ roomNumber , setRoomNumber ] = useState ( - 1 ) ;
62
58
const [ moveInDate , setMoveInDate ] = useState ( new Date ( ) ) ;
63
- const [ buildingId , setBuildingId ] = useState < number > ( - 1 ) ;
59
+ const [ buildingId , setBuildingId ] = useState < number > ( resident . building . id ) ;
64
60
const [ moveOutDate , setMoveOutDate ] = useState < Date | undefined > ( ) ;
65
61
66
62
const [ initialsError , setInitialsError ] = useState ( false ) ;
@@ -100,6 +96,7 @@ const EditResident = ({
100
96
setMoveOutDate ( undefined ) ;
101
97
} ;
102
98
99
+
103
100
const handleInitialsChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
104
101
const inputValue = e . target . value as string ;
105
102
if ( / ^ [ a - z ] { 0 , 2 } $ / i. test ( inputValue ) ) {
@@ -247,8 +244,8 @@ const EditResident = ({
247
244
< FormControl isRequired isInvalid = { buildingError } >
248
245
< FormLabel > Building</ FormLabel >
249
246
< Select
250
- options = { BUILDINGS }
251
- defaultValue = { BUILDINGS . find (
247
+ options = { buildingOptions }
248
+ defaultValue = { buildingOptions . find (
252
249
( item ) => item . value === buildingId ,
253
250
) }
254
251
onChange = { handleBuildingChange }
0 commit comments