From 047ff8812467d79c1f823e7b570a69c5c8f7a46c Mon Sep 17 00:00:00 2001 From: Philip Ye <97428041+philipye314@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:21:22 -0700 Subject: [PATCH] [wip] + minor qrcodescanner fix --- .../EligibilityCard/EligibilityCard.tsx | 2 +- .../CaseScreen/EligibilityForm/index.tsx | 4 ++-- .../Cases/CaseScreen/index.tsx | 16 +++++++++++++--- src/supabase/queries/cases.ts | 19 ++++++++++++++++++- src/types/types.tsx | 6 +++--- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/Components/EligibilityCard/EligibilityCard.tsx b/src/Components/EligibilityCard/EligibilityCard.tsx index dcb1589d..856ad7d5 100644 --- a/src/Components/EligibilityCard/EligibilityCard.tsx +++ b/src/Components/EligibilityCard/EligibilityCard.tsx @@ -15,7 +15,7 @@ export default function EligibilityCard({ status, }: EligibilityCardProps) { const router = useRouter(); - if (status === Eligibility.ELIGIBLE) { + if (status === Eligibility.ELIGIBLE || status === Eligibility.UNDETERMINED) { return ( { // Not sure why this is happening - updateCaseStatus(caseId, Eligibility.ELIGIBLE); + updateCaseStatus(caseId, Eligibility.INELIGIBLE); }} > Yes, I am Eligible @@ -44,7 +44,7 @@ export default function EligibilityForm() { router.back()} + onPress={() => router.push('/Cases/CaseScreen/')} > No, I'm not Eligible X diff --git a/src/app/(BottomTabNavigation)/Cases/CaseScreen/index.tsx b/src/app/(BottomTabNavigation)/Cases/CaseScreen/index.tsx index 01462493..db87a5e6 100644 --- a/src/app/(BottomTabNavigation)/Cases/CaseScreen/index.tsx +++ b/src/app/(BottomTabNavigation)/Cases/CaseScreen/index.tsx @@ -1,5 +1,5 @@ import { router, useLocalSearchParams } from 'expo-router'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import styles from './styles'; @@ -9,11 +9,20 @@ import EducationalBar from '../../../../Components/EducationalBar/EducationalBar import EligibilityCard from '../../../../Components/EligibilityCard/EligibilityCard'; import FormsCard from '../../../../Components/FormsCard/FormsCard'; import { Case, Eligibility } from '../../../../types/types'; +import { getCaseStatus } from '../../../../supabase/queries/cases'; function CasesScreen() { const caseData = useLocalSearchParams() as unknown as Case; const [status, setStatus] = useState(Eligibility.ELIGIBLE); - console.log(caseData); + + useEffect(() => { + const getStatus = async () => { + const caseStatus = await getCaseStatus(caseData.id); + setStatus(caseStatus); + console.log(caseStatus); + }; + getStatus(); + }, []); return ( @@ -27,7 +36,8 @@ function CasesScreen() { )} - {status === Eligibility.ELIGIBLE && ( + {(status === Eligibility.ELIGIBLE || + status === Eligibility.UNDETERMINED) && ( )} diff --git a/src/supabase/queries/cases.ts b/src/supabase/queries/cases.ts index bbc431a8..8e7d9c50 100644 --- a/src/supabase/queries/cases.ts +++ b/src/supabase/queries/cases.ts @@ -93,7 +93,7 @@ export async function containsDuplicateCase(caseId: CaseUid) { .select() .eq('userId', userId) .eq('caseId', caseId); - return data?.length === 0; + return data?.length !== 0; } catch (error) { throw error; } @@ -148,6 +148,23 @@ export async function updateCaseStatus( } } +export async function getCaseStatus(caseId: CaseUid) { + try { + const { + data: { user }, + } = await supabase.auth.getUser(); + const userId = user?.id; + const { data, error } = await supabase + .from('status') + .select() + .eq('userId', userId) + .eq('caseId', caseId); + return data[0].eligibility; //bruhhhh + } catch (error) { + throw error; + } +} + // export async function addCase() { // const dummyCase = { // approved: false, diff --git a/src/types/types.tsx b/src/types/types.tsx index 80c2e456..eb0d3ddb 100644 --- a/src/types/types.tsx +++ b/src/types/types.tsx @@ -33,7 +33,7 @@ export type Status = { }; export enum Eligibility { - ELIGIBLE, - INELIGIBLE, - UNDETERMINED, + ELIGIBLE = 'ELIGIBLE', + INELIGIBLE = 'INELIGIBLE', + UNDETERMINED = 'UNDETERMINED', }