diff --git a/frontend/src/components/StatusDropDown.tsx b/frontend/src/components/StatusDropDown.tsx new file mode 100644 index 0000000..f6f6817 --- /dev/null +++ b/frontend/src/components/StatusDropDown.tsx @@ -0,0 +1,80 @@ +import { useState } from "react"; +import styled from "styled-components"; + +import { ClickAwayListener } from "./ClickAwayListener"; + +import { REFERRAL_STATUSES, ReferralStatus } from "@/api/units"; +import { DropDownPopup, DropdownIcon, FilterSubContainer, Sort } from "@/components/FilterCommon"; + +const SortDropDown = styled(DropDownPopup)` + width: 180px; + z-index: 1; +`; + +const SortRow = styled.div` + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + padding: 10px; + background-color: #fff; + border-radius: 5px; + border: 0.5px solid #cdcaca; + box-shadow: 1px 1px 2px 0px rgba(188, 186, 183, 0.4); + min-width: 180px; +`; + +const PopupSortText = styled(Sort)` + margin: 0; + font-weight: 300; + font-size: 14px; +`; + +export type StatusDropdownProps = { + value: ReferralStatus; + setValue(status: ReferralStatus): void; +}; + +const SORT_OPTIONS = ["Any", ...REFERRAL_STATUSES]; + +export const StatusDropdown = ({ value, setValue }: StatusDropdownProps) => { + const [isActive, setIsActive] = useState(false); + + return ( + { + setIsActive(false); + }} + > + + { + setIsActive(!isActive); + }} + > + Status: {value || "Any"} + + + {isActive && ( + + {SORT_OPTIONS.map((status, idx) => ( + { + if (status === "Any") { + setValue(""); + } else { + setValue(status); + } + setIsActive(false); + }} + > + {status} + + ))} + + )} + + + ); +}; diff --git a/frontend/src/components/Table.tsx b/frontend/src/components/Table.tsx index d7b64c8..5a30332 100644 --- a/frontend/src/components/Table.tsx +++ b/frontend/src/components/Table.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import styled from "styled-components"; import { Pagination } from "./Pagination"; @@ -65,6 +65,11 @@ export const Table = (props: TableProps) => { const { columns, rows, rowsPerPage = 10 } = props; const [pageNumber, setPageNumber] = useState(1); + useEffect(() => { + // Reset page number if data changes + setPageNumber(1); + }, [rows]); + return ( diff --git a/frontend/src/pages/Referrals.tsx b/frontend/src/pages/Referrals.tsx index 4ea7e6c..cb6c9e2 100644 --- a/frontend/src/pages/Referrals.tsx +++ b/frontend/src/pages/Referrals.tsx @@ -12,6 +12,7 @@ import { CustomCheckboxRadio } from "@/components/ListingForm/CommonStyles"; import { NavBar } from "@/components/NavBar"; import { Page } from "@/components/Page"; import { ReferralPopup } from "@/components/ReferralPopup"; +import { StatusDropdown } from "@/components/StatusDropDown"; import { Table, TableCellContent } from "@/components/Table"; import { formatPhoneNumber } from "@/components/helpers"; import { DataContext } from "@/contexts/DataContext"; @@ -60,6 +61,7 @@ const AddButton = styled(Button)` const FilterContainer = styled.div` display: flex; flex-direction: row; + align-items: center; gap: 27px; `; @@ -230,6 +232,7 @@ export function Referrals() { const [popup, setPopup] = useState(false); const [showNewClientPopup, setShowNewClientPopup] = useState(false); const [successfulRemovalPopup, setSuccessfulRemovalPopup] = useState(false); + const [statusFilter, setStatusFilter] = useState(""); const fetchReferrals = () => { if (filterMode === ReferralFilterOption.MY_REFERRALS) { @@ -262,9 +265,12 @@ export function Referrals() { referral.renterCandidate.lastName.toLowerCase().includes(searchValue.toLowerCase()) ); }) + .filter((referral) => { + return statusFilter === "" || referral.status === statusFilter; + }) .sort((a, b) => a.renterCandidate.firstName.localeCompare(b.renterCandidate.firstName)), ); - }, [referrals, searchValue]); + }, [referrals, searchValue, statusFilter]); useEffect(fetchReferrals, [filterMode, dataContext.currentUser]); @@ -309,6 +315,7 @@ export function Referrals() { /> All Referrals +