From 008263c664e80de778ff6a77ac6f6e911714608f Mon Sep 17 00:00:00 2001 From: andyvo2004 <124488343+andyvo2004@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:59:49 -0500 Subject: [PATCH] Andy/227 finalizing (#228) * add keyboard aware scroll view to personal info * fix date validation * use edit-patient endpoint --- package-lock.json | 21 ++ package.json | 1 + src/screens/Profile/ProfileScreen.tsx | 18 +- src/screens/SignUp/PersonalInfo.tsx | 321 +++++++++++++------------- yarn.lock | 15 +- 5 files changed, 212 insertions(+), 164 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6e3f8670..827d93f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,6 +49,7 @@ "react-native-element-dropdown": "^2.12.2", "react-native-elements": "^3.4.3", "react-native-gesture-handler": "~2.16.1", + "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-modal": "^13.0.1", "react-native-pie-chart": "^3.0.2", "react-native-progress": "^5.0.0", @@ -19402,6 +19403,26 @@ "react-native": "*" } }, + "node_modules/react-native-iphone-x-helper": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz", + "integrity": "sha512-HOf0jzRnq2/aFUcdCJ9w9JGzN3gdEg0zFE4FyYlp4jtidqU03D5X7ZegGKfT1EWteR0gPBGp9ye5T5FvSWi9Yg==", + "peerDependencies": { + "react-native": ">=0.42.0" + } + }, + "node_modules/react-native-keyboard-aware-scroll-view": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/react-native-keyboard-aware-scroll-view/-/react-native-keyboard-aware-scroll-view-0.9.5.tgz", + "integrity": "sha512-XwfRn+T/qBH9WjTWIBiJD2hPWg0yJvtaEw6RtPCa5/PYHabzBaWxYBOl0usXN/368BL1XktnZPh8C2lmTpOREA==", + "dependencies": { + "prop-types": "^15.6.2", + "react-native-iphone-x-helper": "^1.0.3" + }, + "peerDependencies": { + "react-native": ">=0.48.4" + } + }, "node_modules/react-native-modal": { "version": "13.0.1", "resolved": "https://registry.npmjs.org/react-native-modal/-/react-native-modal-13.0.1.tgz", diff --git a/package.json b/package.json index 533501c3..69fe3048 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "react-native-element-dropdown": "^2.12.2", "react-native-elements": "^3.4.3", "react-native-gesture-handler": "~2.16.1", + "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-modal": "^13.0.1", "react-native-pie-chart": "^3.0.2", "react-native-progress": "^5.0.0", diff --git a/src/screens/Profile/ProfileScreen.tsx b/src/screens/Profile/ProfileScreen.tsx index 43d2aeac..8841ce4d 100644 --- a/src/screens/Profile/ProfileScreen.tsx +++ b/src/screens/Profile/ProfileScreen.tsx @@ -10,6 +10,7 @@ import { NativeStackScreenProps } from "@react-navigation/native-stack"; import { Button } from "react-native-elements"; import { useSelector } from "react-redux"; import SlidingUpPanel from "rn-sliding-up-panel"; +import { getAuth } from "firebase/auth"; import HomeIcon from "../../assets/HomeIcon"; import ProfileIcon from "../../assets/ProfileIcon"; import SettingsIcon from "../../assets/SettingsIcon"; @@ -23,9 +24,13 @@ import ContinueButton from "../../components/ContinueButton"; type Props = NativeStackScreenProps; function ProfileScreen({ navigation }: Props) { + const auth = getAuth(); + const user = auth.currentUser; const userInfo = useSelector((state) => state.auth) as AuthUser; const panelRef = useRef(null); + console.log(userInfo); + const [name, setName] = useState("Johannes Qian"); const [dob, setDob] = useState(new Date("2000-12-31T05:00:00.000Z")); const [areaCode, setAreaCode] = useState("+1"); @@ -269,8 +274,6 @@ function ProfileScreen({ navigation }: Props) { formData.name.indexOf(" ") + 1, formData.name.length, ); - const secondContactName = userInfo.patientDetails.secondaryContactName; - const secondContactNumber = userInfo.patientDetails.secondaryContactPhone; const newDob = new Date( `${formData.dob.substring(4)}-${formData.dob.substring( 0, @@ -279,16 +282,17 @@ function ProfileScreen({ navigation }: Props) { ); try { const body: Record = { - email: formData.email, + email: user.email, firstName, lastName, phoneNumber: formData.phoneNumber, - birthDate: newDob.toISOString(), - secondaryContactName: secondContactName, - secondaryContactPhone: secondContactNumber, + birthDate: `${formData.dob.substring(0, 2)}-${formData.dob.substring( + 2, + 4, + )}-${formData.dob.substring(4)}`, }; await internalRequest({ - url: "/api/patient/auth/signup", // replace with edit user endpoint + url: "/api/patient/edit-patient", body, method: HttpMethod.POST, }); diff --git a/src/screens/SignUp/PersonalInfo.tsx b/src/screens/SignUp/PersonalInfo.tsx index d3c10538..e0d9d62d 100644 --- a/src/screens/SignUp/PersonalInfo.tsx +++ b/src/screens/SignUp/PersonalInfo.tsx @@ -5,14 +5,13 @@ import { Platform, Dimensions, TextInput, - SafeAreaView, - ScrollView, } from "react-native"; import { Button } from "react-native-elements"; import { useDispatch } from "react-redux"; import { getAuth } from "firebase/auth"; import { Dropdown } from "react-native-element-dropdown"; +import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; import Text from "../../components/Text"; import { UserAnalytics, HttpMethod } from "../../types"; import { login } from "../../redux/reducers/authReducer"; @@ -193,9 +192,20 @@ function PersonalInfoScreen() { } // Following check if the date matches number of days in a month + const [month, day, year] = dateofBirth.split("-"); + const checkDate = new Date( + parseInt(year, 10), + parseInt(month, 10) - 1, + parseInt(day, 10), + ); - const checkDate = new Date(dateofBirth); - if (checkDate.toString() === "Invalid Date") { + if ( + !( + checkDate.getFullYear() === parseInt(year, 10) && + checkDate.getMonth() === parseInt(month, 10) - 1 && + checkDate.getDate() === parseInt(day, 10) + ) + ) { return false; } @@ -266,167 +276,166 @@ function PersonalInfoScreen() { return ( - - - - - Tell Us About Yourself! - - - {/* Reason on why they need to collect this information. Probably a + + + + Tell Us About Yourself! + + + {/* Reason on why they need to collect this information. Probably a sentence or two. */} - - - - First Name* - + + + + First Name* + - Last Name* - + Last Name* + - Phone Number* - - handlePhoneNumberChange(input, setPhoneNumber, phoneNumber) - } - style={styles.textInput} - value={formatPhoneNumber(phoneNumber)} - textContentType="telephoneNumber" - keyboardType="numeric" - maxLength={14} - /> + Phone Number* + + handlePhoneNumberChange(input, setPhoneNumber, phoneNumber) + } + style={styles.textInput} + value={formatPhoneNumber(phoneNumber)} + textContentType="telephoneNumber" + keyboardType="number-pad" + returnKeyType={"done"} + maxLength={14} + /> - Date of Birth* - handleDOBChange(input)} - style={styles.textInput} - value={dateofBirth} - keyboardType="numeric" - maxLength={10} - /> + Date of Birth* + handleDOBChange(input)} + style={styles.textInput} + value={dateofBirth} + keyboardType="number-pad" + returnKeyType={"done"} + maxLength={10} + /> - Choose Chapter - { - console.log("Chapter selected", item); - setChapter(item.value); - }} - /> + Choose Chapter + { + // console.log("Chapter selected", item); + setChapter(item.value); + }} + /> - Secondary Contact Name* - + Secondary Contact Name* + - Secondary Contact Phone* - - handlePhoneNumberChange( - input, - setSecondContactNumber, - secondContactNumber, - ) - } - style={styles.textInput} - textContentType="telephoneNumber" - value={formatPhoneNumber(secondContactNumber)} - keyboardType="numeric" - maxLength={14} - /> - {error} - + Secondary Contact Phone* + + handlePhoneNumberChange( + input, + setSecondContactNumber, + secondContactNumber, + ) + } + style={styles.textInput} + textContentType="telephoneNumber" + value={formatPhoneNumber(secondContactNumber)} + keyboardType="number-pad" + returnKeyType={"done"} + maxLength={14} + /> + {error} + - +