@@ -11,6 +11,7 @@ import {
1111 TouchableOpacity ,
1212 Pressable ,
1313 ScrollView ,
14+ Alert
1415} from "react-native" ;
1516import Icon from "react-native-vector-icons/FontAwesome" ;
1617import { ThemeContext } from "@/ctx/ThemeContext" ;
@@ -28,10 +29,12 @@ const PatientDetails = () => {
2829 const [ text , setText ] = useState ( "" ) ;
2930 const [ height , setHeight ] = useState ( 40 ) ;
3031 const { theme, changeTheme } = useContext ( ThemeContext ) ;
31- const { Doctor_id, hour, date, packageTitle, packagePrice} = useLocalSearchParams ( )
32+ const { Doctor_id, hour, date, packageTitle, packagePrice, duration } = useLocalSearchParams ( )
3233 const [ loggeduser , setLoggedUser ] = useState < string > ( )
3334 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 > ( "" )
3538
3639 useEffect ( ( ) => {
3740 const fetchUser = async ( ) => {
@@ -59,7 +62,15 @@ const PatientDetails = () => {
5962 } else {
6063 setProfile ( data )
6164 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+
6374
6475 }
6576
@@ -68,11 +79,35 @@ const PatientDetails = () => {
6879 }
6980 fetchUserProfile ( )
7081 } , [ 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+
7495 const handleInputChange = ( name : string , value : string ) => {
7596 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+ } ) ;
76111 }
77112
78113 return (
@@ -121,14 +156,8 @@ const PatientDetails = () => {
121156 >
122157 Gender
123158 </ 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+
132161 </ View >
133162
134163 < View style = { { flexDirection : "column" , gap : 10 } } >
@@ -145,15 +174,8 @@ const PatientDetails = () => {
145174 >
146175 Your Age
147176 </ 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+
157179 </ View >
158180
159181 < View style = { { flexDirection : "column" , gap : 10 } } >
@@ -170,7 +192,7 @@ const PatientDetails = () => {
170192 >
171193 Write Your Problem
172194 </ Text >
173- { /* <Input placeholder="Describe how you are feeling here ..." /> */ }
195+
174196 < TextArea text = { text } onChangeText = { setText } />
175197 </ View >
176198
@@ -182,9 +204,10 @@ const PatientDetails = () => {
182204 >
183205 < Button
184206 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+ // }}
188211 />
189212 </ View >
190213 </ ScrollView >
0 commit comments