Skip to content

Commit

Permalink
merged with main again
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-ada committed Mar 15, 2024
2 parents 5ca0084 + fd6660f commit 2f30a50
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 63 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "18.x"

Expand All @@ -25,4 +25,4 @@ jobs:
uses: creyD/[email protected]
with:
prettier_options: "--write **/*.tsx **/*.ts **/*.mjs"
prettier_version: '2.x.x'
prettier_version: "2.x.x"
35 changes: 17 additions & 18 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ name: Unit Testing

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -21,18 +20,18 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run test
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run test
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
85 changes: 54 additions & 31 deletions src/components/AddSenior.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { Dispatch, SetStateAction, useState } from "react";
import React, {
Dispatch,
SetStateAction,
useEffect,
useMemo,
useState,
} from "react";
import Image, { StaticImageData } from "next/legacy/image";
import cn from "classnames";
import FilterDropdown from "@components/FilterDropdown";
Expand All @@ -25,6 +31,18 @@ type AddSeniorTileProps = {
setSeniorPatch: Dispatch<SetStateAction<string>>;
};

type SeniorData = Pick<
z.infer<typeof seniorSchema>,
"firstname" | "lastname" | "location" | "description"
>;

const EMPTY_SENIOR: SeniorData = {
firstname: "",
lastname: "",
location: "",
description: "",
};

export const AddSeniorTile = ({
showAddSeniorPopUp,
setShowAddSeniorPopUp,
Expand Down Expand Up @@ -86,16 +104,6 @@ const StudentSelector = ({
);
};

// type SeniorData = Omit<
// Extract<z.infer<typeof seniorPostResponse>, { code: "SUCCESS" }>["data"],
// "StudentIDs"
// >;

type SeniorData = Pick<
z.infer<typeof seniorSchema>,
"firstname" | "lastname" | "location" | "description"
>;

const AddSenior = ({
seniors,
students,
Expand All @@ -105,25 +113,45 @@ const AddSenior = ({
seniorPatch,
setSeniorPatch,
}: AddSeniorProps) => {
const emptySenior: SeniorData = {
firstname: "",
lastname: "",
location: "",
description: "",
};
const [seniorData, setSeniorData] = useState<SeniorData>(emptySenior);
const [seniorData, setSeniorData] = useState<SeniorData>(EMPTY_SENIOR);
const [selectedStudents, setSelectedStudents] = useState<User[]>([]);
const [currentImage, setCurrentImage] = useState<string | StaticImageData>(
ImageIcon
);
const [confirm, setConfirm] = useState<boolean>(false);
const [error, setError] = useState<boolean>(false);

const initialSenior: Senior | undefined = useMemo(() => {
const senior = seniors.find((senior) => senior.id === seniorPatch);
return senior;
}, [seniorPatch, seniors]);

useEffect(() => {
if (initialSenior)
setSeniorData({
firstname: initialSenior.firstname,
lastname: initialSenior.lastname,
location: initialSenior.location,
description: initialSenior.description,
});
}, [initialSenior]);

useEffect(() => {
if (initialSenior) {
setSelectedStudents(
students.filter((student) =>
initialSenior.StudentIDs.includes(student.id)
)
);
}
}, [students, initialSenior]);

const handlePopUp = () => {
setShowAddSeniorPopUp(!showAddSeniorPopUp);
setSeniorData(emptySenior);
setSeniorData(EMPTY_SENIOR);
setSelectedStudents([]);
setCurrentImage(ImageIcon);
setSeniorPatch(""); // empty string used as falsey value to indicate update or patch
};

const handleConfirm = () => {
Expand Down Expand Up @@ -151,14 +179,9 @@ const AddSenior = ({
setConfirm(true);
const newSeniors = seniors.filter((i) => i.id !== newerSeniorObj.id);
setSeniors([...newSeniors, newerSeniorObj]);
}
// check after both API calls
if (currRes.code != "SUCCESS") {
} else {
setError(true);
}

setSeniorData(emptySenior);
setSeniorPatch(""); // empty string used as falsey value to indicate update or patch
};

const postAddSenior = async () => {
Expand All @@ -177,9 +200,6 @@ const AddSenior = ({
} else {
setError(true);
}
setSeniorData(emptySenior);
setSelectedStudents([]);
return null;
});
};

Expand Down Expand Up @@ -248,6 +268,7 @@ const AddSenior = ({
<input
className="mb-3 h-[36px] w-full rounded-md border-2 border-solid border-tan px-3 text-sm text-black"
type="text"
value={seniorData.firstname}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSeniorData({
...seniorData,
Expand All @@ -265,6 +286,7 @@ const AddSenior = ({
<input
className="mb-3 h-[36px] w-full rounded-md border-2 border-solid border-tan px-3 text-sm text-black"
type="text"
value={seniorData.lastname}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSeniorData((seniorData) => ({
...seniorData,
Expand Down Expand Up @@ -296,6 +318,7 @@ const AddSenior = ({
<textarea
className="h-25 mb-3 min-h-[20px] w-full rounded-md border-2 border-solid border-tan bg-white p-[10px] text-start text-sm text-black"
placeholder="Write a brief description about the senior"
value={seniorData.description}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) =>
setSeniorData({
...seniorData,
Expand Down Expand Up @@ -332,11 +355,11 @@ const AddSenior = ({
<>
{confirm ? (
<div className="flex flex-col items-center">
<div className="mb-8 text-center text-3xl">
<div className="mb-8 text-center text-xl">
{seniorPatch ? "Updated" : "Added"} successfully!
</div>
<button
className="font-large mx-1 w-full max-w-[10rem] rounded bg-white p-3 text-lg text-dark-teal drop-shadow-md hover:bg-off-white"
className="mx-1 w-full max-w-[10rem] rounded bg-white p-3 text-lg text-dark-teal drop-shadow-md"
onClick={handleConfirm}
>
Confirm
Expand All @@ -349,7 +372,7 @@ const AddSenior = ({
your club administrator for help.
</div>
<button
className="mx-1 w-full max-w-[10rem] rounded bg-off-white p-3 text-lg font-normal drop-shadow-md hover:bg-offer-white"
className="mx-1 w-full max-w-[10rem] rounded bg-white p-3 text-lg text-dark-teal drop-shadow-md"
onClick={handleConfirm}
>
Confirm
Expand Down
23 changes: 23 additions & 0 deletions src/components/LandingFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,32 @@ const LandingFooter = () => {
className={`${buttonStyle} w-auto rounded-xl px-4 py-4 duration-150`}
type="submit"
>
<<<<<<< HEAD
<span className="align-center text-white">{buttonText}</span>
</button>
</form>
=======
<input
className="text-dark \ relative h-[40px] rounded border-2 border-offer-white bg-off-white
px-[10px] focus:border-light-teal focus:outline-none sm:w-3/4"
name="email"
placeholder="[email protected]"
onFocus={resetButton}
onChange={(event) => {
setEmail(event.target.value);
}}
/>
<button
className={`h-[40px] w-auto ${buttonStyle} rounded duration-150`}
type="submit"
>
<span className="align-center text-md m-[10px] w-auto tracking-easy text-white">
{buttonText}
</span>
</button>
</form>
</FlowerBox>
>>>>>>> main
</div>
);
};
Expand Down
52 changes: 43 additions & 9 deletions src/components/SeniorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import { Senior, User } from "@prisma/client";
import SearchableContainer from "./SearchableContainer";
import { UserTile } from "./TileGrid";
import { UserTile, TileEdit } from "./TileGrid";
import AddSenior from "./AddSenior";
import { useContext, useState } from "react";
import { UserContext } from "@context/UserProvider";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faPencil, faTrashCan } from "@fortawesome/free-solid-svg-icons";

type SeniorViewProps = {
seniors: Senior[];
Expand All @@ -32,14 +34,46 @@ export const SeniorView = ({ seniors, students }: SeniorViewProps) => {
setSeniorPatch={setSeniorPatch}
/>
}
elements={seniorsState ? seniorsState : []}
display={(senior, index) => (
<UserTile
senior={senior}
link={`/private/${context.user.id}/chapter-leader/seniors/${senior.id}`}
key={senior.id}
/>
)}
elements={seniorsState}
display={(senior) => {
const options: Parameters<typeof TileEdit>[0]["options"] = [];

options.push({
name: "Edit",
onClick: (e) => {
e.stopPropagation();
e.preventDefault();
setSeniorPatch(senior.id);
setShowAddSeniorPopUp(true);
},
color: "#22555A",
icon: <FontAwesomeIcon icon={faPencil} />,
});

options.push({
name: "Delete",
onClick: (e) => {
e.stopPropagation();
e.preventDefault();
fetch(`/api/senior/${senior.id}`, {
method: "DELETE",
}).then(() => {
window.location.reload();
});
},
color: "#EF6767",
icon: <FontAwesomeIcon icon={faTrashCan} />,
});
return (
// TODO(nickbar01234) - Fix link
<UserTile
senior={senior}
link={`/private/${context.user.id}/chapter-leader/seniors/${senior.id}`}
key={senior.id}
dropdownComponent={<TileEdit options={options} />}
/>
);
}}
search={(senior, key) =>
(senior.firstname + " " + senior.lastname)
.toLowerCase()
Expand Down
8 changes: 8 additions & 0 deletions src/components/TileGrid/UserTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,23 @@ export function UserTile({
</div>
<div className="flex items-center justify-between p-2">
<div className="overflow-hidden">
<<<<<<< HEAD
<p className="overflow-hidden text-ellipsis whitespace-nowrap text-sm text-dark-teal">
=======
<p className="overflow-hidden text-ellipsis whitespace-nowrap text-sm text-dark-teal before:invisible before:content-['\200B']">
>>>>>>> main
{student && student.name
? student.name + (student.admin ? " (Admin)" : "")
: senior && `${senior.firstname} ${senior.lastname}`
? `${senior.firstname} ${senior.lastname}`
: null}
</p>
{/* @TODO: Add pronouns once we add to student field */}
<<<<<<< HEAD
<p className="text-md font-base text-neutral-600 mt-[5px] truncate text-[10px] text-dark-teal">
=======
<p className="text-md font-base text-neutral-600 mt-[5px] truncate text-[10px] text-dark-teal before:invisible before:content-['\200B']">
>>>>>>> main
{senior && senior.location}
</p>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/components/TileGrid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
export { default } from "./TileGrid";
export * from "./UserTile";
export * from "./SeniorTile";
export * from "./TileEdit";
4 changes: 2 additions & 2 deletions src/components/senior/DisplaySenior.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { formatFileDate } from "@utils";
import { File } from "@components/file";
import AddFile from "@components/file/AddFile";
import { v4 as uuid } from "uuid";
import Assigment from "./assignment";
import Assignment from "./assignment";

interface DisplayProps {
editable: boolean;
Expand Down Expand Up @@ -53,7 +53,7 @@ const DisplaySenior = (props: DisplayProps) => {
{/* @TODO - Firstname + lastname */}
<h1 className="text-4xl font-bold text-[#000022]">{`${senior.firstname} ${senior.lastname}`}</h1>
<p>{senior.description}</p>
<Assigment editable={editable} senior={senior} />
<Assignment editable={editable} senior={senior} />
<SearchableContainer
display={(file) => <File key={file.id} file={file} />}
elements={FILES} // TODO(nickbar01234) - Replace with real data
Expand Down

0 comments on commit 2f30a50

Please sign in to comment.