Skip to content

Commit

Permalink
[wip] + minor qrcodescanner fix
Browse files Browse the repository at this point in the history
  • Loading branch information
philipye314 committed Nov 1, 2023
1 parent d90babf commit 047ff88
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Components/EligibilityCard/EligibilityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<View style={[styles.container, styles.eligible]}>
<TouchableOpacity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function EligibilityForm() {
style={[styles.button, styles.buttonTop]}
onPress={() => {
// Not sure why this is happening
updateCaseStatus(caseId, Eligibility.ELIGIBLE);
updateCaseStatus(caseId, Eligibility.INELIGIBLE);
}}
>
<Text>Yes, I am Eligible</Text>
Expand All @@ -44,7 +44,7 @@ export default function EligibilityForm() {
<View style={styles.buttonWrapperBottom}>
<TouchableOpacity
style={[styles.button, styles.buttonBottom]}
onPress={() => router.back()}
onPress={() => router.push('/Cases/CaseScreen/')}
>
<Text style={styles.buttonBottomText}>No, I'm not Eligible</Text>
<Text style={styles.buttonBottomText}>X</Text>
Expand Down
16 changes: 13 additions & 3 deletions src/app/(BottomTabNavigation)/Cases/CaseScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<View style={styles.container}>
Expand All @@ -27,7 +36,8 @@ function CasesScreen() {
)}
<CaseStatusBar />
<CaseSummaryCard />
{status === Eligibility.ELIGIBLE && (
{(status === Eligibility.ELIGIBLE ||
status === Eligibility.UNDETERMINED) && (
<EligibilityCard caseData={caseData} status={status} />
)}
<FormsCard />
Expand Down
19 changes: 18 additions & 1 deletion src/supabase/queries/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/types/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type Status = {
};

export enum Eligibility {
ELIGIBLE,
INELIGIBLE,
UNDETERMINED,
ELIGIBLE = 'ELIGIBLE',
INELIGIBLE = 'INELIGIBLE',
UNDETERMINED = 'UNDETERMINED',
}

0 comments on commit 047ff88

Please sign in to comment.