@@ -11,6 +11,7 @@ import {
11
11
TouchableOpacity ,
12
12
Pressable ,
13
13
ScrollView ,
14
+ Alert
14
15
} from "react-native" ;
15
16
import Icon from "react-native-vector-icons/FontAwesome" ;
16
17
import { ThemeContext } from "@/ctx/ThemeContext" ;
@@ -28,10 +29,12 @@ const PatientDetails = () => {
28
29
const [ text , setText ] = useState ( "" ) ;
29
30
const [ height , setHeight ] = useState ( 40 ) ;
30
31
const { theme, changeTheme } = useContext ( ThemeContext ) ;
31
- const { Doctor_id, hour, date, packageTitle, packagePrice} = useLocalSearchParams ( )
32
+ const { Doctor_id, hour, date, packageTitle, packagePrice, duration } = useLocalSearchParams ( )
32
33
const [ loggeduser , setLoggedUser ] = useState < string > ( )
33
34
const [ profile , setProfile ] = useState < any > ( null )
34
- const [ patient_id , setPatient_id ] = useState < string > ( )
35
+ const [ patient_id , setPatient_id ] = useState < string > ( )
36
+ const [ selectedGender , setSelectedGender ] = useState < string > ( )
37
+ const [ selectedAge , setSelectedAge ] = useState < string > ( "" )
35
38
36
39
useEffect ( ( ) => {
37
40
const fetchUser = async ( ) => {
@@ -59,7 +62,15 @@ const PatientDetails = () => {
59
62
} else {
60
63
setProfile ( data )
61
64
setPatient_id ( data . id )
62
- console . log ( data )
65
+ if ( ! data . age && data . date_of_birth ) {
66
+ const age = calculateAge ( data . date_of_birth )
67
+ setProfile ( ( prevProfile :Date ) => ( {
68
+ ...prevProfile ,
69
+ age :age
70
+ } ) )
71
+ setSelectedAge ( age . toString ( ) || '' )
72
+ }
73
+
63
74
64
75
}
65
76
@@ -68,11 +79,35 @@ const PatientDetails = () => {
68
79
}
69
80
fetchUserProfile ( )
70
81
} , [ loggeduser ] )
71
- console . log ( "this is profile:" , profile )
72
- console . log ( "this is logged user:" , loggeduser )
73
- console . log ( "this is patient_id:" , patient_id )
82
+
83
+
84
+ const calculateAge = ( dob : string ) => {
85
+ const birthDate = new Date ( dob ) ;
86
+ const today = new Date ( ) ;
87
+ const age = today . getFullYear ( ) - birthDate . getFullYear ( ) ;
88
+ const monthDifference = today . getMonth ( ) - birthDate . getMonth ( ) ;
89
+ if ( monthDifference < 0 || ( monthDifference === 0 && today . getDate ( ) < birthDate . getDate ( ) ) ) {
90
+ return age - 1 ;
91
+ }
92
+ return age ;
93
+ } ;
94
+
74
95
const handleInputChange = ( name : string , value : string ) => {
75
96
setProfile ( { ...profile , [ name ] : value } ) ;
97
+ } ;
98
+
99
+
100
+ const handleNextPress = ( ) => {
101
+ if ( ! text ) {
102
+ Alert . alert ( "Please select all required data" )
103
+
104
+ return ;
105
+ }
106
+
107
+ router . push ( {
108
+ pathname : "/(app)/ActionMenu/Booking/SelectPayment" ,
109
+ params :{ doctor_id :Doctor_id , hour :hour , date :date , packageTitle :packageTitle , packagePrice :packagePrice , problem :text , user_id :loggeduser , patient_id :patient_id , duration :duration } ,
110
+ } ) ;
76
111
}
77
112
78
113
return (
@@ -121,14 +156,8 @@ const PatientDetails = () => {
121
156
>
122
157
Gender
123
158
</ Text >
124
- < DropDown
125
- data = { [
126
- { value : `${ profile ?. gender } ` , label :`${ profile ?. gender } ` } ,
127
- { value : "Male" , label : "Male" } ,
128
- { value : "Female" , label : "Female" } ,
129
- ] }
130
- defaultvalue = { profile ?. Gender }
131
- />
159
+ < Input onChange = { handleInputChange } placeholder = "Gender" value = { `${ profile ?. gender } ` } />
160
+
132
161
</ View >
133
162
134
163
< View style = { { flexDirection : "column" , gap : 10 } } >
@@ -145,15 +174,8 @@ const PatientDetails = () => {
145
174
>
146
175
Your Age
147
176
</ Text >
148
- < DropDown
149
- data = { [
150
- { value : `${ profile ?. age } Years` , label :`${ profile ?. age } Years` } ,
151
- { value : "27 years" , label : "27 years" } ,
152
- { value : "28 years" , label : "28 years" } ,
153
-
154
- ] }
155
- defaultvalue = { profile ?. age }
156
- />
177
+ < Input onChange = { value => handleInputChange ( 'age' , value ) } placeholder = "Age" value = { selectedAge } />
178
+
157
179
</ View >
158
180
159
181
< View style = { { flexDirection : "column" , gap : 10 } } >
@@ -170,7 +192,7 @@ const PatientDetails = () => {
170
192
>
171
193
Write Your Problem
172
194
</ Text >
173
- { /* <Input placeholder="Describe how you are feeling here ..." /> */ }
195
+
174
196
< TextArea text = { text } onChangeText = { setText } />
175
197
</ View >
176
198
@@ -182,9 +204,10 @@ const PatientDetails = () => {
182
204
>
183
205
< Button
184
206
title = "Next"
185
- onPress = { ( ) => {
186
- router . push ( { pathname : "/(app)/ActionMenu/Booking/SelectPayment" , params :{ doctor_id :Doctor_id , hour :hour , date :date , packageTitle :packageTitle , packagePrice :packagePrice , problem :text , user_id :loggeduser , patient_id :patient_id } } ) ;
187
- } }
207
+ onPress = { handleNextPress }
208
+ // onPress={() => {
209
+ // router.push({ pathname: "/(app)/ActionMenu/Booking/SelectPayment",params:{doctor_id:Doctor_id,hour:hour,date:date,packageTitle:packageTitle,packagePrice:packagePrice,problem:text,user_id:loggeduser,patient_id:patient_id,duration:duration} });
210
+ // }}
188
211
/>
189
212
</ View >
190
213
</ ScrollView >
0 commit comments