Skip to content

Commit

Permalink
[feat] add claim filing behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronniebeggs committed May 1, 2024
1 parent 8234e2b commit c6e8013
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
12 changes: 2 additions & 10 deletions src/Components/EligibilityCard/EligibilityCard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { router } from 'expo-router';
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';
import { View } from 'react-native';

import styles from './styles';
import CheckEligibility from '../../../assets/check-eligibility.svg';
import Fileclaim from '../../../assets/file-claim.svg';
import Arrow from '../../../assets/next.svg';
import OptOut from '../../../assets/opt-out.svg';
import { openUrl } from '../../app/(BottomTabNavigation)/AllCases/utils';
import globalStyles from '../../styles/global';
import { Case, CaseUid, Eligibility } from '../../types/types';
import { CaseUid } from '../../types/types';
import EligibleFilingButton from '../EligibilityFilingButton/EligibilityFilingButton';
import ToggleOptionsButton from '../ToggleOptionsButton/ToggleOptionsButton';

Expand Down
11 changes: 7 additions & 4 deletions src/app/(BottomTabNavigation)/AllCases/CaseScreen/[caseUid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { View, ScrollView, Text } from 'react-native';

import styles from './styles';
// eslint-disable-next-line import/namespace
import CaseStatusBar from '../../../../Components/CaseStatusBar/CaseStatusBar';
import CaseSummaryCard from '../../../../Components/CaseSummaryCard/CaseSummaryCard';
import CheckEligibilityButton from '../../../../Components/CheckEligibilityButton/CheckEligibilityButton';
import EducationalBar from '../../../../Components/EducationalBar/EducationalBar';
import EligibilityCard from '../../../../Components/EligibilityCard/EligibilityCard';
import FormsCard from '../../../../Components/FormsCard/FormsCard';
import StatusUpdatesBar from '../../../../Components/StatusUpdatesBar/StatusUpdatesBar';
import ToggleOptionsButton from '../../../../Components/ToggleOptionsButton/ToggleOptionsButton';
import { getCaseStatus, getCaseById } from '../../../../supabase/queries/cases';
import { Case, Eligibility } from '../../../../types/types';

Expand All @@ -29,6 +29,7 @@ function CaseScreen() {

const getStatus = async (uid: string) => {
const caseStatus = await getCaseStatus(uid);
console.log(caseStatus);
setStatus(caseStatus);
};

Expand Down Expand Up @@ -61,9 +62,11 @@ function CaseScreen() {
</View>

{status === Eligibility.ELIGIBLE && (
<>
<EligibilityCard caseUid={caseData.id} />
</>
<EligibilityCard caseUid={caseData.id} />
)}

{status === Eligibility.CLAIM_FILED && (
<CaseStatusBar status="Claim Filed" />
)}

<CaseSummaryCard {...caseData} />
Expand Down
32 changes: 21 additions & 11 deletions src/app/(BottomTabNavigation)/AllCases/FileClaim/[caseUid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import Document from '../../../../../assets/document-add.svg';
import Checkbox from '../../../../../assets/double-checkbox.svg';
import Fileclaim from '../../../../../assets/file-claim-small.svg';
import RightWhiteArrow from '../../../../../assets/right-arrow-white.svg';
import { getCaseById } from '../../../../supabase/queries/cases';
import { Case, CaseUid } from '../../../../types/types';
import {
getCaseById,
updateCaseStatus,
} from '../../../../supabase/queries/cases';
import { Case, CaseUid, Eligibility } from '../../../../types/types';
import { openUrl } from '../utils';

const ensureURLFormat = (url: string | null | undefined) => {
Expand All @@ -24,6 +27,20 @@ export default function FileClaimScreen() {
const { caseUid } = useLocalSearchParams<{ caseUid: CaseUid }>();
const [caseData, setCaseData] = useState<Case>();

async function confirmClaimFiled() {
if (caseUid !== undefined) {
await updateCaseStatus(caseUid, Eligibility.CLAIM_FILED);
router.back();
}
}

function navigateToClaimLink() {
const claimLink = caseData?.claimLink;
if (claimLink) {
openUrl(claimLink);
}
}

async function fetchCaseData() {
if (caseUid) {
const caseData = await getCaseById(caseUid);
Expand All @@ -35,11 +52,6 @@ export default function FileClaimScreen() {
fetchCaseData();
}, []);

const claimLink = caseData?.claimLink
? ensureURLFormat(caseData.claimLink)
: null;
const onPressHandler = claimLink ? () => openUrl(claimLink) : undefined;

return (
<View style={styles.container}>
{caseData === undefined ? (
Expand Down Expand Up @@ -85,7 +97,7 @@ export default function FileClaimScreen() {
<View style={styles.buttonsContainer}>
<TouchableOpacity
style={[styles.buttonBase, styles.buttonWhite]}
onPress={onPressHandler}
onPress={() => navigateToClaimLink()}
>
<Text style={[styles.buttonText, styles.blackText]}>
Take me to claim filing site
Expand All @@ -94,9 +106,7 @@ export default function FileClaimScreen() {
</TouchableOpacity>
<TouchableOpacity
style={[styles.buttonBase, styles.buttonBlack]}
onPress={() =>
router.push(`/AllCases/OptOut/ConfirmOptOut/${caseUid}`)
}
onPress={() => confirmClaimFiled()}
>
<Text style={[styles.buttonText, styles.whiteText]}>
I’ve already filed a claim!
Expand Down
7 changes: 7 additions & 0 deletions src/app/(BottomTabNavigation)/AllCases/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export default function CasesLayout() {
headerTitle: () => <HeaderImage />,
}}
/>
<Stack.Screen
name="FileClaim/[caseUid]"
options={{
headerLeft: () => <BackButtonNoText />,
headerTitle: () => <HeaderImage />,
}}
/>
<Stack.Screen
name="Forms/[caseUid]"
options={{
Expand Down
1 change: 1 addition & 0 deletions src/supabase/queries/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export async function updateCaseStatus(
status: Eligibility,
): Promise<void> {
try {
console.log('update status to: ' + status);
const {
data: { user },
} = await supabase.auth.getUser();
Expand Down
1 change: 1 addition & 0 deletions src/types/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export enum Eligibility {
ELIGIBLE = 'ELIGIBLE',
INELIGIBLE = 'INELIGIBLE',
UNDETERMINED = 'UNDETERMINED',
CLAIM_FILED = 'CLAIM_FILED',
}

export const userInstance: User = {
Expand Down

0 comments on commit c6e8013

Please sign in to comment.