diff --git a/src/redux/reducers/gameDetailsReducer/index.ts b/src/redux/reducers/gameDetailsReducer/index.ts index 3bb1792c..d2db7e2a 100644 --- a/src/redux/reducers/gameDetailsReducer/index.ts +++ b/src/redux/reducers/gameDetailsReducer/index.ts @@ -63,6 +63,37 @@ const gameDetailsReducer = createSlice({ state.lastSessionsMetrics[0].writing.attempted = false; state.lastSessionsMetrics[0].trivia.attempted = false; }, + resetLastSessionMetrics(state) { + state.lastSessionsMetrics[0] = { + date: "", + math: { + attempted: false, + questionsAttempted: 0, + questionsCorrect: 0, + finalDifficultyScore: 0, + timePerQuestion: 0, + }, + trivia: { + attempted: false, + questionsAttempted: 0, + questionsCorrect: 0, + timePerQuestion: 0, + }, + reading: { + attempted: false, + passagesRead: 0, + timePerPassage: 0, + wordsPerMinute: 0, + skipped: false, + }, + writing: { + attempted: false, + questionsAnswered: 0, + timePerQuestion: 0, + skipped: false, + }, + }; + }, updateFullState(state, action: { payload: GameDetails; type: string }) { return { ...initialState, @@ -113,6 +144,7 @@ export default gameDetailsReducer.reducer; export const { resetAttempted, + resetLastSessionMetrics, updateFullState, completedMath, completedReading, diff --git a/src/screens/Auth/AuthGuard.tsx b/src/screens/Auth/AuthGuard.tsx index b8d346bb..17f4312b 100644 --- a/src/screens/Auth/AuthGuard.tsx +++ b/src/screens/Auth/AuthGuard.tsx @@ -12,7 +12,7 @@ import SignUpScreen from "../SignUp/SignUp"; import PersonalInfoScreen from "../SignUp/PersonalInfo"; import { RootState } from "../../redux/rootReducer"; import { getUserAnalytics } from "../../firebase/email_signin"; -import { updateFullState } from "../../redux/reducers/gameDetailsReducer"; +// import { updateFullState } from "../../redux/reducers/gameDetailsReducer"; type Props = { children: React.ReactNode }; @@ -32,7 +32,7 @@ function AuthGuard({ children }: Props) { authenticated: true, }; dispatch(login(newState)); - dispatch(updateFullState(userAnalytics.gameDetails)); + // dispatch(updateFullState(userAnalytics.gameDetails)); }); } else { dispatch(logout()); diff --git a/src/screens/Home/HomeScreen.tsx b/src/screens/Home/HomeScreen.tsx index 38d17911..d1216128 100644 --- a/src/screens/Home/HomeScreen.tsx +++ b/src/screens/Home/HomeScreen.tsx @@ -17,7 +17,7 @@ import Subject from "../../components/Home/ExerciseSubjects"; import { RootState } from "../../redux/rootReducer"; import { AuthUser } from "../../redux/reducers/authReducer/types"; -import { resetAttempted } from "../../redux/reducers/gameDetailsReducer"; +import { resetLastSessionMetrics } from "../../redux/reducers/gameDetailsReducer"; const logo = require("../../assets/bei.jpg") as AVPlaybackSource; @@ -29,7 +29,7 @@ type Props = NativeStackScreenProps; function HomeScreen({ navigation }: Props) { const dispatch = useDispatch(); useEffect(() => { - dispatch(resetAttempted()); + dispatch(resetLastSessionMetrics()); }, [dispatch]); const userInfo = useSelector((state) => state.auth) as AuthUser; diff --git a/src/screens/Profile/ProfileScreen.tsx b/src/screens/Profile/ProfileScreen.tsx index 099f07ab..43d2aeac 100644 --- a/src/screens/Profile/ProfileScreen.tsx +++ b/src/screens/Profile/ProfileScreen.tsx @@ -27,7 +27,7 @@ function ProfileScreen({ navigation }: Props) { const panelRef = useRef(null); const [name, setName] = useState("Johannes Qian"); - const [dob, setDob] = useState("01-01-2024"); + const [dob, setDob] = useState(new Date("2000-12-31T05:00:00.000Z")); const [areaCode, setAreaCode] = useState("+1"); const [phoneNumber, setPhoneNumber] = useState("1231231234"); const [email, setEmail] = useState("sample@bei.com"); @@ -37,7 +37,7 @@ function ProfileScreen({ navigation }: Props) { const [formData, setFormData] = useState({ name: "Johannes Qian", - dob: "01-01-2024", + dob: "12312000", areaCode: "+1", phoneNumber: "1231231234", email: "sample@bei.com", @@ -54,9 +54,9 @@ function ProfileScreen({ navigation }: Props) { } if (userInfo.birthDate) { - setDob(userInfo.birthDate); + setDob(new Date(userInfo.birthDate)); } else { - setDob("01-01-2024"); + setDob(new Date("2000-12-31T05:00:00.000Z")); } if (userInfo.phoneNumber) { @@ -94,11 +94,16 @@ function ProfileScreen({ navigation }: Props) { } }, [userInfo]); + const formatDOB = (unformatteddob: Date) => { + return `${unformatteddob.getMonth() + 1} / ${ + unformatteddob.getDate() + 1 + } / ${unformatteddob.getFullYear()}`; + }; + function open() { - const formatteddob = dob.replace(/-/g, ""); setFormData({ name, - dob: formatteddob, + dob: formatDOB(dob).replace(/[ /]/g, ""), areaCode, phoneNumber, email, @@ -140,7 +145,7 @@ function ProfileScreen({ navigation }: Props) { } }; - const formatDOB = (input: string) => { + const formatDOBstring = (input: string) => { const digitsOnly = input.replace(/-/g, ""); if (digitsOnly.length <= 2) { return digitsOnly; @@ -161,8 +166,10 @@ function ProfileScreen({ navigation }: Props) { dob: newDob, })); }; + const cleanInput = input.replace(/[ ./]/g, ""); - let digitsOnlyDOB = formData.dob.replace(/-/g, ""); + let digitsOnlyDOB = formData.dob; + if (cleanInput.length < digitsOnlyDOB.length) { // backspace digitsOnlyDOB = digitsOnlyDOB.slice(0, -1); @@ -225,12 +232,12 @@ function ProfileScreen({ navigation }: Props) { return false; } - const formatteddob = `${formData.dob.substring( + const formatteddob = `${formData.dob.substring(4)}-${formData.dob.substring( 0, 2, - )}-${formData.dob.substring(2, 4)}-${formData.dob.substring(4)}`; + )}-${formData.dob.substring(2, 4)}`; - if (!/^\d{2}-\d{2}-\d{4}/.test(formatteddob)) { + if (!/^\d{4}-\d{2}-\d{2}/.test(formatteddob)) { setError("Please enter a valid date of birth"); return false; } @@ -264,18 +271,24 @@ function ProfileScreen({ navigation }: Props) { ); const secondContactName = userInfo.patientDetails.secondaryContactName; const secondContactNumber = userInfo.patientDetails.secondaryContactPhone; + const newDob = new Date( + `${formData.dob.substring(4)}-${formData.dob.substring( + 0, + 2, + )}-${formData.dob.substring(2, 4)}`, + ); try { const body: Record = { email: formData.email, firstName, lastName, phoneNumber: formData.phoneNumber, - birthDate: formData.dob, + birthDate: newDob.toISOString(), secondaryContactName: secondContactName, secondaryContactPhone: secondContactNumber, }; await internalRequest({ - url: "/api/patient/auth/signup", + url: "/api/patient/auth/signup", // replace with edit user endpoint body, method: HttpMethod.POST, }); @@ -284,12 +297,7 @@ function ProfileScreen({ navigation }: Props) { return; } setName(formData.name); - setDob( - `${formData.dob.substring(0, 2)}-${formData.dob.substring( - 2, - 4, - )}-${formData.dob.substring(4)}`, - ); + setDob(newDob); setAreaCode(formData.areaCode); setPhoneNumber(formData.phoneNumber); setEmail(formData.email); @@ -660,7 +668,7 @@ function ProfileScreen({ navigation }: Props) { paddingHorizontal: "4%", paddingVertical: "2%", }} - value={formatDOB(formData.dob)} + value={formatDOBstring(formData.dob)} onChangeText={(e) => handleChange(e, "dob")} placeholder="Enter Date of Birth" accessibilityHint='The text written in this input field will be saved as the user"s date of birth'