Skip to content

Commit

Permalink
check deposits!
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdenio committed Mar 22, 2024
1 parent 2223f15 commit 2c9965c
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ module.exports = {
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
],
overrides: [],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
plugins: ["react", "@typescript-eslint", "import"],
plugins: ["react", "@typescript-eslint", "import", "react-hooks"],
rules: {
"import/no-duplicates": "error",
"import/order": [
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"eslint": "^8.49.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^3.0.3",
"typescript": "^5.3.0"
},
Expand Down
57 changes: 57 additions & 0 deletions src/components/transaction/types/CheckDepositTransaction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useTheme } from "@react-navigation/native";
import { Image } from "expo-image";
import { View } from "react-native";

import { TransactionCheckDeposit } from "../../../lib/types/Transaction";
import { renderMoney, statusColor } from "../../../util";
import Badge from "../../Badge";
import UserMention from "../../UserMention";
import TransactionDetails, { descriptionDetail } from "../TransactionDetails";
import TransactionTitle, { Muted } from "../TransactionTitle";

import { TransactionViewProps } from "./TransactionViewProps";

export default function CheckDepositTransaction(
props: TransactionViewProps<TransactionCheckDeposit>,
) {
const { colors: themeColors } = useTheme();

return (
<View>
<TransactionTitle
badge={
<Badge color={statusColor(props.transaction.check_deposit.status)}>
{props.transaction.check_deposit.status}
</Badge>
}
>
Check deposit <Muted>of</Muted>{" "}
{renderMoney(props.transaction.amount_cents)}
</TransactionTitle>

<Image
source={{ uri: props.transaction.check_deposit.front_url }}
style={{
width: "100%",
height: 150,
borderRadius: 8,
marginBottom: 30,
backgroundColor: themeColors.card,
}}
contentFit="cover"
/>

<TransactionDetails
details={[
descriptionDetail(props.orgId, props.transaction, props.navigation),
{
label: "Deposited by",
value: (
<UserMention user={props.transaction.check_deposit.submitter} />
),
},
]}
/>
</View>
);
}
4 changes: 4 additions & 0 deletions src/components/transaction/types/TransactionViewProps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { NativeStackNavigationProp } from "@react-navigation/native-stack";

import { StackParamList } from "../../../lib/NavigatorParamList";
import { TransactionBase } from "../../../lib/types/Transaction";

export type TransactionViewProps<T extends TransactionBase = TransactionBase> =
{
transaction: T;
orgId: string;
navigation: NativeStackNavigationProp<StackParamList, "Transaction">;
};
2 changes: 1 addition & 1 deletion src/lib/types/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import HcbApiObject from "./HcbApiObject";
import Organization from "./Organization";
import User from "./User";

export default interface Invitation extends HcbApiObject<"inv"> {
export default interface Invitation extends HcbApiObject<"ivt"> {
sender?: User; // Field is optional for future-proofing reasons
accepted: boolean;
organization: Organization;
Expand Down
32 changes: 32 additions & 0 deletions src/lib/types/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,45 @@ export interface TransactionAchTransfer extends TransactionBase {
ach_transfer: AchTransfer;
}

export interface Invoice extends HcbApiObject<"inv"> {
amount_cents: number;
send_at: string;
paid_at?: string;
description: string;
due_date: string;
sponsor: {
id: string;
name: string;
email: string;
};
}

export interface TransactionInvoice extends TransactionBase {
code: TransactionType.Invoice;
invoice: Invoice;
}

export interface CheckDeposit {
status: "pending" | "rejected" | "returned" | "deposited";
front_url: string;
back_url: string;
submitter: User;
}

export interface TransactionCheckDeposit extends TransactionBase {
code: TransactionType.CheckDeposit;
check_deposit: CheckDeposit;
}

// |
// |
// v this is cool, i should finish this
//
// type SpecificTransaction<Code extends TransactionType, Key extends string, Obj> = TransactionBase & {code: Code; } & {[k in Key]: Obj}

type Transaction =
| TransactionCheckDeposit
| TransactionInvoice
| TransactionAchTransfer
| TransactionTransfer
| TransactionCheck
Expand Down
18 changes: 11 additions & 7 deletions src/pages/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import AchTransferTransaction from "../components/transaction/types/AchTransferT
import BankAccountTransaction from "../components/transaction/types/BankAccountTransaction";
import BankFeeTransaction from "../components/transaction/types/BankFeeTransaction";
import CardChargeTransaction from "../components/transaction/types/CardChargeTransaction";
import CheckDepositTransaction from "../components/transaction/types/CheckDepositTransaction";
import CheckTransaction from "../components/transaction/types/CheckTransaction";
import DonationTransaction from "../components/transaction/types/DonationTransaction";
import { TransactionViewProps } from "../components/transaction/types/TransactionViewProps";
Expand All @@ -34,6 +35,7 @@ export default function TransactionPage({
route: {
params: { transactionId, transaction: _transaction, orgId },
},
navigation,
}: Props) {
const { data: transaction } = useSWR<
Transaction & { organization?: Organization }
Expand Down Expand Up @@ -63,6 +65,7 @@ export default function TransactionPage({

const transactionViewProps: Omit<TransactionViewProps, "transaction"> = {
orgId: orgId || transaction.organization!.id,
navigation,
};

return (
Expand All @@ -87,13 +90,14 @@ export default function TransactionPage({
{
/* prettier-ignore */
match(transaction)
.with({ card_charge: P.any }, (tx) => <CardChargeTransaction transaction={tx} {...transactionViewProps} />)
.with({ check: P.any }, (tx) => <CheckTransaction transaction={tx} {...transactionViewProps} />)
.with({ transfer: P.any }, (tx) => <TransferTransaction transaction={tx} {...transactionViewProps} />)
.with({ donation: P.any }, (tx) => <DonationTransaction transaction={tx} {...transactionViewProps} />)
.with({ ach_transfer: P.any }, (tx) => <AchTransferTransaction transaction={tx} {...transactionViewProps} />)
.with({ code: TransactionType.BankFee }, (tx) => <BankFeeTransaction transaction={tx} {...transactionViewProps} />)
.otherwise( (tx) => <BankAccountTransaction transaction={tx} {...transactionViewProps} />)
.with({ card_charge: P.any }, (tx) => <CardChargeTransaction transaction={tx} {...transactionViewProps} />)
.with({ check: P.any }, (tx) => <CheckTransaction transaction={tx} {...transactionViewProps} />)
.with({ transfer: P.any }, (tx) => <TransferTransaction transaction={tx} {...transactionViewProps} />)
.with({ donation: P.any }, (tx) => <DonationTransaction transaction={tx} {...transactionViewProps} />)
.with({ ach_transfer: P.any }, (tx) => <AchTransferTransaction transaction={tx} {...transactionViewProps} />)
.with({ check_deposit: P.any }, (tx) => <CheckDepositTransaction transaction={tx} {...transactionViewProps} />)
.with({ code: TransactionType.BankFee }, (tx) => <BankFeeTransaction transaction={tx} {...transactionViewProps} />)
.otherwise( (tx) => <BankAccountTransaction transaction={tx} {...transactionViewProps} />)
}

{comments && comments.length > 0 && (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function CardsPage({ navigation }: Props) {
</MenuView>
),
});
}, [navigation, frozenCardsShown]);
}, [navigation, frozenCardsShown, scheme]);

if (cards) {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/organization/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ export default function OrganizationSettingsPage({
);
const { data: currentUser } = useSWR<User>("/user");

if (!organization) return null;

const tabBarHeight = useBottomTabBarHeight();
const { colors: themeColors } = useTheme();

if (!organization) return null;

return (
<ScrollView
contentContainerStyle={{ padding: 20, paddingBottom: tabBarHeight + 20 }}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/organization/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ export default function OrganizationPage({
),
});
}
}, [organization]);
}, [organization, scheme, navigation]);

const tabBarSize = useBottomTabBarHeight();
const { colors: themeColors } = useTheme();

const transactions = useMemo(
() => addPendingFeeToTransactions(_transactions, organization),
[_transactions],
[_transactions, organization],
);

const sections: { title: string; data: TransactionWithoutId[] }[] = useMemo(
Expand Down

0 comments on commit 2c9965c

Please sign in to comment.