diff --git a/src/app/private/[uid]/user/seniors/SeniorsHomePage.tsx b/src/app/private/[uid]/user/seniors/SeniorsHomePage.tsx index 5cf90d18..05e9afdc 100644 --- a/src/app/private/[uid]/user/seniors/SeniorsHomePage.tsx +++ b/src/app/private/[uid]/user/seniors/SeniorsHomePage.tsx @@ -1,17 +1,18 @@ "use client"; import { UserTile } from "@components/TileGrid"; -import { Senior, User } from "@prisma/client"; +import { Prisma, Senior, User } from "@prisma/client"; import SearchableContainer from "@components/SearchableContainer"; import { seniorFullName } from "@utils"; +type UserWithSeniors = Prisma.UserGetPayload<{ include: { Seniors: true } }>; + type SeniorsHomePageProps = { - seniors: Senior[]; - user: User; + user: UserWithSeniors; }; -const SeniorsHomePage = ({ seniors, user }: SeniorsHomePageProps) => { - const displaySeniors = (elem: Senior, index: number) => ( +const SeniorsHomePage = ({ user }: SeniorsHomePageProps) => { + const displaySeniors = (elem: Senior) => ( { return ( <>

- {`My Assigned Seniors (${seniors.length})`} + {`My Assigned Seniors (${user.Seniors.length})`}

{"You haven't been assigned a Senior yet."} diff --git a/src/app/private/[uid]/user/seniors/page.tsx b/src/app/private/[uid]/user/seniors/page.tsx index 2730a169..e4c86a0c 100644 --- a/src/app/private/[uid]/user/seniors/page.tsx +++ b/src/app/private/[uid]/user/seniors/page.tsx @@ -12,9 +12,7 @@ const UserSeniorsPage = async ({ params }: { params: { uid: string } }) => { }, }); - const seniors = user.Seniors; - - return ; + return ; }; export default UserSeniorsPage; diff --git a/src/components/container/Popup.tsx b/src/components/container/Popup.tsx index 05c2f2cd..53e02a83 100644 --- a/src/components/container/Popup.tsx +++ b/src/components/container/Popup.tsx @@ -6,9 +6,9 @@ interface PopupProps { const Popup = (props: PopupProps) => { return ( -
+
{ students.filter((student) => senior.StudentIDs.includes(student.id)); const [assigned, setAssigned] = React.useState(() => getAssignments()); - console.log(assigned); const onSave = async () => { await patchSenior({ body: { @@ -62,7 +61,9 @@ const DisplaySenior = (props: DisplayProps) => { /> } - elements={senior.Files} + elements={senior.Files.sort( + (fileA, fileB) => fileA.date.getTime() - fileB.date.getTime() + )} search={(file, filter) => formatFileDate(file.date).includes(filter)} addElementComponent={ canAddFile ? ( diff --git a/src/components/user/AddFile.tsx b/src/components/user/AddFile.tsx index b3c72202..52894f57 100644 --- a/src/components/user/AddFile.tsx +++ b/src/components/user/AddFile.tsx @@ -9,6 +9,7 @@ import { File as PrismaFile } from "@prisma/client"; import { Popup } from "@components/container"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCalendar } from "@fortawesome/free-solid-svg-icons"; +import { useRouter } from "next/navigation"; type AddFileProps = { showAddFilePopUp: boolean; @@ -32,7 +33,7 @@ const TagOptions = ({ { if (!selectedTags.includes(tag) && selectedTags.length < 3) { setSelectedTags([...selectedTags, tag]); @@ -41,22 +42,17 @@ const TagOptions = ({ } }} /> - {!selectedTags.includes(tag) && ( - - )} - {selectedTags.includes(tag) && ( - - )} +
))}
@@ -91,7 +87,6 @@ const AddFile = ({ setShowAddFilePopUp, seniorId, files, - folder, }: AddFileProps) => { const currFiles = Object.values(files); const excludeDates = currFiles.map((fileObj) => fileObj.date); @@ -99,15 +94,10 @@ const AddFile = ({ dateObj.toDateString() ); - const startDate_ = new Date(); + const [startDate, setStartDate] = useState(new Date()); - while (excludedDatesString.includes(startDate_.toDateString())) { - startDate_.setDate(startDate_.getDate() + 1); - } - - const [startDate, setStartDate] = useState(startDate_); - - const [confirm, setConfirm] = useState(false); + const router = useRouter(); + const [fetching, setFetching] = React.useState(false); const [error, setError] = useState(false); const [selectedTags, setSelectedTags] = useState([]); @@ -116,6 +106,11 @@ const AddFile = ({ }; const callAddFile = async () => { + if (fetching) { + return; + } + + setFetching(true); const response = await createFile({ body: { date: startDate, @@ -125,102 +120,88 @@ const AddFile = ({ seniorId: seniorId, }, }); + setFetching(false); - if (response.code == "SUCCESS") { - setConfirm(true); + if (response.code === "SUCCESS") { + router.refresh(); } else { setError(true); } }; - return ( - <> - {showAddFilePopUp && ( - - {!confirm && !error ? ( -
-
- {" "} - Create New File{" "} -
-
- Select Date -
-
-
- - } - wrapperClassName="w-full relative" - calendarIconClassname="text-3xl text-blue-600 mt-[7px] absolute right-2" - className="mb-4 h-16 w-full cursor-pointer rounded-lg pl-4" - selected={startDate} - onChange={(date) => date && setStartDate(date)} - dateFormat="dd MMMM yyyy" - excludeDates={excludeDates} - /> -
-
- -
- - -
-
- ) : ( - <> - {confirm ? ( -
- File added successfully! -
- -
-
- ) : ( -
- - There was an error adding your file. Please reach out to - your club administrator for assistance. - -
- -
-
- )} - - )} -
- )} - + if (!showAddFilePopUp) { + return null; + } + + return !error ? ( + +
+
Create New File
+
+ Select Date +
+
+
+ + } + wrapperClassName="w-full relative" + calendarIconClassname="text-3xl text-blue-600 mt-[7px] absolute right-2" + className="mb-4 h-16 w-full cursor-pointer rounded-lg pl-4" + selected={startDate} + onChange={(date) => date && setStartDate(date)} + dateFormat="dd MMMM yyyy" + excludeDates={excludeDates} + /> + {excludedDatesString.includes(startDate.toDateString()) ? ( +

+ ***ERROR: Please pick a date that you have not created a file + for*** +

+ ) : null} +
+
+ +
+ + +
+
+
+ ) : ( + +
+ + There was an error adding your file. Please reach out to your club + administrator for assistance. + + +
+
); };