Skip to content

Commit 7c3fa18

Browse files
nickbar01234wkim10johnny-t06
authored
Deprecate unused components (#157)
Co-authored-by: Won Kim <[email protected]> Co-authored-by: Johnny Tan <[email protected]>
1 parent 96449f3 commit 7c3fa18

File tree

12 files changed

+56
-408
lines changed

12 files changed

+56
-408
lines changed

src/app/api/emails/route.client.ts

+2-49
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,10 @@
11
import { z } from "zod";
22
import { Email, EmailResponse } from "./route.schema";
3+
import { TypedRequest } from "@server/type";
34

4-
/**
5-
* Describe the interface of SignInRequest.
6-
*/
7-
type IEmail = z.infer<typeof Email>;
8-
9-
type IEmailResponse = z.infer<typeof EmailResponse>;
10-
11-
/**
12-
* Extract all the values of "code".
13-
*/
14-
type EmailResponseCode = z.infer<typeof EmailResponse>["code"];
15-
16-
/**
17-
* Extends the parameters of fetch() function to give types to the RequestBody.
18-
*/
19-
interface IRequest extends Omit<RequestInit, "body"> {
20-
body: IEmail;
21-
}
22-
23-
const MOCK_SUCCESS: IEmailResponse = {
24-
code: "SUCCESS",
25-
message: "Email successfully submitted",
26-
};
27-
28-
const MOCK_DUPLICATE_EMAIL: IEmailResponse = {
29-
code: "DUPLICATE_EMAIL",
30-
message: "This email already exists",
31-
};
32-
33-
const MOCK_INVALID_EMAIL: IEmailResponse = {
34-
code: "INVALID_EMAIL",
35-
message: "Invalid email submission",
36-
};
37-
38-
/**
39-
* If "mock" is given as a parameter, the function can return mocked data for a specific case. This
40-
* pattern allows frontend developers to use your API before you finished implementing it!
41-
*
42-
* In addition, using Zod schemas to parse the response will make the input/output well-typed, making the code cleaner.
43-
*/
445
export const createEmailRequest = async (
45-
request: IRequest,
46-
mock?: EmailResponseCode
6+
request: TypedRequest<z.infer<typeof Email>>
477
) => {
48-
if (mock === "SUCCESS") {
49-
return EmailResponse.parse(MOCK_SUCCESS);
50-
} else if (mock === "INVALID_EMAIL") {
51-
return EmailResponse.parse(MOCK_INVALID_EMAIL);
52-
} else if (mock === "DUPLICATE_EMAIL") {
53-
return EmailResponse.parse(MOCK_DUPLICATE_EMAIL);
54-
}
558
const { body, ...options } = request;
569
const response = await fetch("/api/emails", {
5710
method: "POST",

src/app/private/admin/home/chapters/[chapterId]/users/[userId]/seniors/[seniorId]/page.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PathNav from "@components/PathNav";
2-
import FileTile from "@components/TileGrid/FileTile";
32
import { CardGrid } from "@components/container";
43
import { prisma } from "@server/db/client";
4+
import { File } from "@components/file";
55

66
interface Params {
77
params: {
@@ -53,13 +53,7 @@ const SeniorPage = async ({ params }: Params) => {
5353
</>
5454
}
5555
tiles={senior.Files.map((file) => (
56-
<FileTile
57-
key={file.id}
58-
id={file.id}
59-
date={file.date}
60-
url={file.url}
61-
Tags={file.Tags}
62-
/>
56+
<File key={file.id} file={file} />
6357
))}
6458
/>
6559
</div>

src/components/FilterDropdown.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ type FilterDropdownProps<T extends Named> = {
3232
setSelectedItems: Dispatch<SetStateAction<T[]>>;
3333
};
3434

35+
/**
36+
* @deprecated In favour of Dropdown which implements a more generic version.
37+
*/
3538
export default function FilterDropdown<T extends Named>({
3639
items,
3740
filterMatch,

src/components/LandingFooter.tsx

+47-47
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,45 @@
11
"use client";
22
import React, { FormEvent, FocusEvent, useState } from "react";
3-
import { EmailResponse } from "@api/emails/route.schema";
3+
import { useApiThrottle } from "@hooks";
4+
import { createEmailRequest } from "@api/emails/route.client";
5+
import { Spinner } from "./skeleton";
46

57
const LandingFooter = () => {
68
const [email, setEmail] = useState<string>("");
7-
const [eList, setEList] = useState<Set<string>>(new Set<string>());
89

910
const [buttonText, setButtonText] = useState<string>("Join E-List");
1011
const [buttonStyle, setButtonStyle] = useState<string>(
1112
"bg-dark-teal hover:-translate-y-0.5"
1213
);
1314

14-
function resetButton(target: FocusEvent<HTMLInputElement>) {
15-
setButtonStyle("bg-dark-teal hover:-translate-y-0.5");
16-
setButtonText("Join E-List");
17-
}
18-
19-
const onEmailSubmit = async (event: FormEvent) => {
20-
event.preventDefault();
21-
22-
// if box isn't empty and content is a valid email, add it to the set
23-
24-
if (email) {
25-
eList.add(email);
26-
setEList(eList);
27-
28-
// use SendGrid 'subscribe' route to send a test email
29-
const res = await fetch("/api/emails", {
30-
body: JSON.stringify({ email: email }),
31-
method: "POST",
32-
});
33-
34-
const responseObject = EmailResponse.parse(await res.json());
35-
if (responseObject.code == "INVALID_EMAIL") {
15+
const { fetching, fn: throttleCreateEmailRequest } = useApiThrottle({
16+
fn: createEmailRequest,
17+
callback: (responseObject) => {
18+
if (responseObject.code === "INVALID_EMAIL") {
3619
setButtonText("Invalid Email");
3720
setButtonStyle("bg-tag-rust"); // no hover
3821
return;
39-
} else if (responseObject.code == "DUPLICATE_EMAIL") {
22+
} else if (responseObject.code === "DUPLICATE_EMAIL") {
4023
setButtonText("Duplicate Email");
4124
setButtonStyle("bg-tag-rust"); // no hover
4225
return;
4326
}
4427

4528
setButtonText("Subscribed!");
4629
setButtonStyle("bg-dark-teal"); // no hover
30+
},
31+
});
32+
33+
function resetButton(target: FocusEvent<HTMLInputElement>) {
34+
setButtonStyle("bg-dark-teal hover:-translate-y-0.5");
35+
setButtonText("Join E-List");
36+
}
37+
38+
const onEmailSubmit = async (event: FormEvent) => {
39+
event.preventDefault();
40+
41+
if (email !== "") {
42+
await throttleCreateEmailRequest({ body: { email: email } });
4743
} else {
4844
setButtonText("Invalid Email");
4945
setButtonStyle("bg-tag-rust"); // no hover
@@ -66,29 +62,33 @@ const LandingFooter = () => {
6662
is doing:
6763
</p>
6864
</div>
69-
<form
70-
className="mx-auto flex w-3/4 flex-col justify-center gap-[20px] md:flex-row"
71-
method="post"
72-
onSubmit={onEmailSubmit}
73-
autoComplete="off"
74-
>
75-
<input
76-
className="text-gray relative h-[60px] rounded-xl bg-white px-4
77-
placeholder-dark-gray shadow-md focus:border-dark-teal focus:outline-none md:w-3/4"
78-
name="email"
79-
placeholder="Enter your e-mail address"
80-
onFocus={resetButton}
81-
onChange={(event) => {
82-
setEmail(event.target.value);
83-
}}
84-
/>
85-
<button
86-
className={`${buttonStyle} w-auto rounded-xl px-4 py-4 duration-150`}
87-
type="submit"
65+
{!fetching ? (
66+
<form
67+
className="mx-auto flex w-3/4 flex-col justify-center gap-[20px] md:flex-row"
68+
method="post"
69+
onSubmit={onEmailSubmit}
70+
autoComplete="off"
8871
>
89-
<span className="align-center text-white">{buttonText}</span>
90-
</button>
91-
</form>
72+
<input
73+
className="text-gray relative h-[60px] rounded-xl bg-white px-4
74+
placeholder-dark-gray shadow-md focus:border-dark-teal focus:outline-none md:w-3/4"
75+
name="email"
76+
placeholder="Enter your e-mail address"
77+
onFocus={resetButton}
78+
onChange={(event) => {
79+
setEmail(event.target.value);
80+
}}
81+
/>
82+
<button
83+
className={`${buttonStyle} w-auto rounded-xl px-4 py-4 duration-150`}
84+
type="submit"
85+
>
86+
<span className="align-center text-white">{buttonText}</span>
87+
</button>
88+
</form>
89+
) : (
90+
<Spinner />
91+
)}
9292
</div>
9393
);
9494
};

src/components/PhotoHeader.tsx

-46
This file was deleted.

src/components/SortDropdown.tsx

-61
This file was deleted.

src/components/TileGrid/ChapterTile.tsx

-58
This file was deleted.

0 commit comments

Comments
 (0)