Skip to content

Commit aa20561

Browse files
authored
Merge pull request #80 from Hack4Impact-UMD/zod-schema-refactor
Add Zod schemas to common; infer types from schemas; compose schemas in app
2 parents e82aeb9 + 9a798d6 commit aa20561

28 files changed

Lines changed: 410 additions & 366 deletions

app/.oxlintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@
116116
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
117117
"@typescript-eslint/no-unsafe-function-type": "error",
118118
"@typescript-eslint/no-wrapper-object-types": "error",
119+
"@typescript-eslint/consistent-type-assertions": "error",
120+
"@typescript-eslint/no-non-null-assertion": "error",
121+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
122+
"@typescript-eslint/no-unsafe-type-assertion": "error",
119123
"@typescript-eslint/prefer-as-const": "error",
120124
"@typescript-eslint/prefer-for-of": "warn",
121125
"@typescript-eslint/triple-slash-reference": "error",

app/src/components/auth/ReauthAlertDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function ReauthAlertDialog({
4040
if (!auth.currentUser || !authCtx.authUser.email)
4141
throw new Error("not authenticated");
4242
await reauthenticateWithCredential(
43-
auth.currentUser!,
43+
auth.currentUser,
4444
EmailAuthProvider.credential(authCtx.authUser.email, pass),
4545
);
4646
setErr(false);

app/src/components/donor/home/ChildBlock.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function ChildBlock({ child }: { child: CommittedChild }) {
2121
const set = useCallback((id: string, patch: Partial<GiftFormState>) => {
2222
setGiftStates((p) => ({
2323
...p,
24-
[id]: { ...p[id]!, ...patch, changesSaved: false },
24+
[id]: { ...p[id], ...patch, changesSaved: false },
2525
}));
2626
}, []);
2727

@@ -55,9 +55,9 @@ export function ChildBlock({ child }: { child: CommittedChild }) {
5555
setGiftStates((p) => ({
5656
...p,
5757
[id]: {
58-
...p[id]!,
58+
...p[id],
5959
changesSaved: true,
60-
unclaimed: p[id]!.pendingUnclaim, // promote pending to actual
60+
unclaimed: p[id]?.pendingUnclaim, // promote pending to actual
6161
},
6262
}));
6363
}, []);

app/src/components/donor/home/ChildDetailSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function ChildDetailSection({
6262
<GiftInformationCard
6363
key={gift.id}
6464
gift={gift}
65-
state={giftStates[gift.id]!}
65+
state={giftStates[gift.id]}
6666
onOrdered={() => onOrdered(gift.id)}
6767
onDelivered={() => onDelivered(gift.id)}
6868
onUndoDelivery={() => onUndoDelivery(gift.id)}

app/src/lib/formSchemas.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import { z } from "zod";
2+
import { ChildStatusSchema } from "common";
23
import type { ChildStatus } from "common";
34

45
// Ordered to match display order in the form.
5-
export const CHILD_STATUS_VALUES = [
6-
"recently_diagnosed_relapse",
7-
"diagnosed_in_treatment_1yr+",
8-
"recently_off_treatment",
9-
"off_treatment_5yr+",
10-
"sibling_in_treatment",
11-
"bereaved_sibling",
12-
"bereaved_sibling_5yr+",
13-
] as const satisfies ReadonlyArray<ChildStatus>;
6+
export const CHILD_STATUS_VALUES = ChildStatusSchema.options;
147

158
export const CHILD_STATUS_LABELS: Record<ChildStatus, string> = {
169
recently_diagnosed_relapse:

app/src/queries/publishedGifts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const publishedGiftsQueries = createQueryKeys("publishedGifts", {
99
queryKey: ["byDrive", driveId],
1010
queryFn: () => getPublishedGifts({ data: { driveId } }),
1111
}),
12-
tableRowsByDrive: (driveId?: string) => ({
12+
tableRowsByDrive: (driveId: string) => ({
1313
queryKey: ["tableRowsByDrive", driveId],
14-
queryFn: () => getPublishedGiftsTableRows({ data: { driveId: driveId! } }),
14+
queryFn: () => getPublishedGiftsTableRows({ data: { driveId } }),
1515
}),
1616
});
1717

app/src/routes/_authenticated/staff/gifts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const Route = createFileRoute("/_authenticated/staff/gifts")({
1212
function RouteComponent() {
1313
const { activeDriveId } = useDrive();
1414
const tableRowsByDriveQuery = publishedGiftsQueries.tableRowsByDrive(
15-
activeDriveId ?? undefined,
15+
activeDriveId ?? "",
1616
);
1717
const { data: tableRows = [], isLoading } = useQuery({
1818
...tableRowsByDriveQuery,

app/src/routes/_authenticated/staff/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ function RouteComponent() {
6262
<main className="flex min-w-0 flex-1 flex-col">
6363
<div className="w-full bg-accent border-b block md:hidden">
6464
<SidebarTrigger
65-
openIcon={<XIcon />}
66-
closeIcon={<MenuIcon />}
65+
closeIcon={<XIcon />}
66+
openIcon={<MenuIcon />}
6767
/>
6868
</div>
6969
<div className="flex min-h-0 flex-1 flex-col p-4">

app/src/server/functions/cart.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ export const getCartGiftsGroupedByFamily = createServerFn({ method: "GET" })
3232
);
3333

3434
const gifts = giftDocs.flatMap((doc) => {
35-
if (!doc.exists) return [];
36-
const gift = doc.data()!;
37-
if (!gift.active) return [];
35+
const gift = doc.data();
36+
if (!gift?.active) return [];
3837
return [
3938
{
4039
id: gift.id,
@@ -56,8 +55,8 @@ export const getCartGiftsGroupedByFamily = createServerFn({ method: "GET" })
5655

5756
const familyById: Record<string, StorefrontFamily> = {};
5857
for (const doc of familyDocs) {
59-
if (!doc.exists) continue;
60-
const family = doc.data()!;
58+
const family = doc.data();
59+
if (!family) continue;
6160
familyById[family.id] = {
6261
id: family.id,
6362
contactName: family.contactName,

0 commit comments

Comments
 (0)