Skip to content

Commit

Permalink
fix: typing and enumming status options
Browse files Browse the repository at this point in the history
  • Loading branch information
arfamomin committed Apr 21, 2024
1 parent 720333f commit 6eeced0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/app/(BottomTabNavigation)/AllCases/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import {
getCaseIdsFromUserId,
getCasesByIds,
} from '../../../supabase/queries/cases';
import { Case, UserUid } from '../../../types/types';
import {
Case,
GreenStatusOptions,
YellowStatusOptions,
RedStatusOptions,
UserUid,
StatusOptions,
} from '../../../types/types';

/**
* Fetches all Cases associated with a specific `userUid` from supabase. Formats Case data and returns an array of `Case` objects.
Expand Down Expand Up @@ -61,13 +68,14 @@ export function formatDate(dateObject: Date) {
}

export function getStatusColor(status: string) {
if (!StatusOptions.includes(status)) {
throw new Error(`Invalid status: ${status}`);
}

if (
status === 'In Progress' ||
status === 'New Case' ||
status === 'Settled' ||
status === 'Appeal' ||
status === 'Payment Processing' ||
status === 'Payment Distributed'
Object.values(GreenStatusOptions).includes(
status as unknown as GreenStatusOptions,
)
) {
return {
background: {
Expand All @@ -77,7 +85,11 @@ export function getStatusColor(status: string) {
},
text: { color: colors.darkGreen },
};
} else if (status === 'Pending') {
} else if (
Object.values(YellowStatusOptions).includes(
status as unknown as YellowStatusOptions,
)
) {
return {
background: {
backgroundColor: colors.lightYellow,
Expand All @@ -86,7 +98,11 @@ export function getStatusColor(status: string) {
},
text: { color: colors.darkYellow },
};
} else if (status === 'Action Required') {
} else if (
Object.values(RedStatusOptions).includes(
status as unknown as RedStatusOptions,
)
) {
return {
background: {
backgroundColor: colors.lightRed,
Expand Down
23 changes: 23 additions & 0 deletions src/types/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,26 @@ export interface Update {
summary: string;
lawFirm: string;
}

export enum GreenStatusOptions {
'In Progress',
'New Case',
'Settled',
'Appeal',
'Payment Processing',
'Payment Distributed',
}

export enum YellowStatusOptions {
'Pending',
}

export enum RedStatusOptions {
'Action Required',
}

export const StatusOptions: string[] = [
...(Object.values(GreenStatusOptions) as string[]),
...(Object.values(YellowStatusOptions) as string[]),
...(Object.values(RedStatusOptions) as string[]),
];

0 comments on commit 6eeced0

Please sign in to comment.