Skip to content

Commit

Permalink
move chapter rendering to page
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesq23 committed Nov 19, 2024
1 parent deb8731 commit 894914c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
23 changes: 21 additions & 2 deletions src/app/(management-portal)/patient/search/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { useSelector } from "react-redux";
import Search from "@src/components/Search/Search";

Expand All @@ -12,6 +12,7 @@ import {
HttpMethod,
IPatientTableEntry,
SearchResponseBody,
IChapter,
} from "@/common_utils/types";
import LoadingBox from "@src/components/LoadingBox/LoadingBox";
import Modal from "@src/components/Modal/Modal";
Expand Down Expand Up @@ -47,6 +48,8 @@ export default function Page() {
const [pageCount, setPageCount] = useState(0);
const [loading, setLoading] = useState(false);

const [chapters, setChapters] = useState<IChapter[] | null>([]);

useEffect(() => {
setLoading(true);
internalRequest<SearchResponseBody<IPatientTableEntry>>({
Expand Down Expand Up @@ -110,6 +113,22 @@ export default function Page() {
sortField,
]);

const loadChapters = useCallback(() => {
setLoading(true);
internalRequest<IChapter[] | null>({
url: "/api/chapter/get-chapters",
method: HttpMethod.GET,
body: {},
}).then((res) => {
setChapters(res);
setLoading(false);
});
}, []);

useEffect(() => {
loadChapters();
}, [loadChapters]);

return (
<div className={styles.container}>
<title>Patient Search | Brain Exercise Initiative</title>
Expand All @@ -124,7 +143,7 @@ export default function Page() {
<div className={classes(styles["search-container"])}>
<p className={styles["intro-text"]}>Here are Your Patient Finds!</p>
<div className={styles["search-wrapper"]}>
<Search />
<Search chapters={chapters} />
</div>
</div>
<div
Expand Down
2 changes: 0 additions & 2 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ const Pagination = (params: DataParams) => {
return [...backwardPages, ...forwardPages];
}, [params.currentPage, params.pageCount]);

console.log(pages);

const goToPreviousPage = () => {
if (params.currentPage > 0) {
params.setCurrentPage(params.currentPage - 1);
Expand Down
37 changes: 10 additions & 27 deletions src/components/Search/AdvancedSearch/AdvancedSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use client";

import React, {
useState,
useCallback,
Expand All @@ -16,12 +14,7 @@ import { classes, transformDate, transformPhoneNumber } from "@src/utils/utils";
import { ClearTagIcon } from "@src/app/icons";
import { useDispatch, useSelector } from "react-redux";
import { RootState } from "@src/redux/rootReducer";
import {
IPatientSearchReducer,
IChapter,
HttpMethod,
} from "@/common_utils/types";
import { internalRequest } from "@src/utils/requests";
import { IPatientSearchReducer, IChapter } from "@/common_utils/types";

import { update, clear } from "@src/redux/reducers/patientSearchReducer";
import Dropdown, {
Expand Down Expand Up @@ -96,6 +89,7 @@ interface UpdateParamProp {
style?: CSSProperties;
onSubmit?: () => void;
className?: string;
chapters: IChapter[] | null;
}

export const AdvancedSearch = (props: UpdateParamProp) => {
Expand Down Expand Up @@ -309,26 +303,15 @@ export const AdvancedSearch = (props: UpdateParamProp) => {

const [chapters, setChapters] = useState<DropdownOption<string>[]>([]);

const loadChapters = useCallback(() => {
internalRequest<IChapter[] | null>({
url: "/api/chapter/get-chapters",
method: HttpMethod.GET,
body: {},
}).then((res) => {
const chapterDropdown = res
? res.map((chapter) => ({
value: chapter.name,
displayValue: chapter.name,
}))
: [];
setChapters(chapterDropdown);
console.log(chapters);
});
}, []);

useEffect(() => {
loadChapters();
}, [loadChapters]);
const chapterDropdown = props.chapters
? props.chapters.map((chapter) => ({
value: chapter.name,
displayValue: chapter.name,
}))
: [];
setChapters(chapterDropdown);
}, []);

return (
<div className={styles.body} style={props.style}>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import FilterAltIcon from "@mui/icons-material/FilterAlt";
import FilterAltOffIcon from "@mui/icons-material/FilterAltOff";
import { classes } from "@src/utils/utils";
import { IChapter } from "@/common_utils/types";
import styles from "./Search.module.css";
import { AdvancedSearch } from "./AdvancedSearch/AdvancedSearch";
import InputField from "../InputField/InputField";

interface SearchProps {
className?: string;
onSubmit?: () => void;
chapters: IChapter[] | null;
}

export default function Search({ className, onSubmit }: SearchProps) {
export default function Search({ className, onSubmit, chapters }: SearchProps) {
const dispatch = useDispatch();

const { fullName } = useSelector((state: RootState) => state.patientSearch);
Expand Down Expand Up @@ -105,7 +107,7 @@ export default function Search({ className, onSubmit }: SearchProps) {
showAdvancedSearch && styles["advanced-search-container-show"],
)}
>
<AdvancedSearch />
<AdvancedSearch chapters={chapters} />
</div>
</div>
</div>
Expand Down

0 comments on commit 894914c

Please sign in to comment.