Skip to content

Commit

Permalink
Release: 2023-08-16 (#1636)
Browse files Browse the repository at this point in the history
* fix: flip min rent with max rent (#1634)

* fix: format currency before filter form submit (#1635)

---------

Co-authored-by: Krzysztof Zięcina <kriss.kontakt@gmail.com>
  • Loading branch information
ludtkemorgan and KrissDrawing committed Aug 21, 2023
1 parent 8926e09 commit a5de9b2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions backend/core/src/shared/query-filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export function addFilters<FilterParams extends Array<any>, FilterFieldMap>(
addRegionFilter(qb, filterValue)
continue
case ListingFilterKeys.minRent:
addRentFilter(qb, filterValue, "<=", "minRent")
addRentFilter(qb, filterValue, ">=", "minRent")
continue
case ListingFilterKeys.maxRent:
addRentFilter(qb, filterValue, ">=", "maxRent")
addRentFilter(qb, filterValue, "<=", "maxRent")
continue
//custom user filters
case UserFilterKeys.isPortalUser:
Expand Down
3 changes: 3 additions & 0 deletions sites/public/src/lib/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import DetroitIcon from "../components/core/DetroitIcon"

export const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

export const removeCommas = (data: string | number) =>
typeof data === "string" ? data.replaceAll(",", "") : data

export const getGenericAddress = (bloomAddress: Address) => {
return bloomAddress
? {
Expand Down
11 changes: 11 additions & 0 deletions sites/public/src/pages/finder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Layout from "../layouts/application"
import FinderDisclaimer from "../components/finder/FinderDisclaimer"
import FinderMultiselect from "../components/finder/FinderMultiselect"
import FinderRentalCosts from "../components/finder/FinderRentalCosts"
import { removeCommas } from "../lib/helpers"

interface FinderField {
label: string
Expand Down Expand Up @@ -128,6 +129,16 @@ const Finder = () => {
})
}
})
if (formSelections[FrontendListingFilterStateKeys.minRent]) {
formSelections[FrontendListingFilterStateKeys.minRent] = removeCommas(
formSelections[FrontendListingFilterStateKeys.minRent]
)
}
if (formSelections[FrontendListingFilterStateKeys.maxRent]) {
formSelections[FrontendListingFilterStateKeys.maxRent] = removeCommas(
formSelections[FrontendListingFilterStateKeys.maxRent]
)
}
void router.push(
`/listings/filtered?page=${1}&limit=${8}${encodeToFrontendFilterString(formSelections)}`
)
Expand Down
10 changes: 9 additions & 1 deletion sites/public/src/pages/listings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import Layout from "../layouts/application"
import { MetaTags } from "../components/shared/MetaTags"
import { useRouter } from "next/router"
import FilterForm from "../components/filters/FilterForm"
import { getListings } from "../lib/helpers"
import { getListings, removeCommas } from "../lib/helpers"
import { fetchBaseListingData } from "../lib/hooks"
import {
ListingList,
pushGtmEvent,
encodeToFrontendFilterString,
ListingFilterState,
AuthContext,
FrontendListingFilterStateKeys,
} from "@bloom-housing/shared-helpers"
import { ListingPagination } from "../components/listing/ListingPagination"
import { UserStatus } from "../lib/constants"
Expand All @@ -35,6 +36,13 @@ const ListingsPage = ({ initialListings }) => {
const metaImage = "" // TODO: replace with hero image

const onSubmit = (page: number, limit: number, data: ListingFilterState) => {
data[FrontendListingFilterStateKeys.minRent] = removeCommas(
data[FrontendListingFilterStateKeys.minRent]
)
data[FrontendListingFilterStateKeys.maxRent] = removeCommas(
data[FrontendListingFilterStateKeys.maxRent]
)

setFilterModalVisible(false)
void router.push(
`/listings/filtered?page=${page}&limit=${limit}${encodeToFrontendFilterString(data)}`
Expand Down
12 changes: 9 additions & 3 deletions sites/public/src/pages/listings/filtered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
import { faSliders } from "@fortawesome/free-solid-svg-icons"
import DetroitIcon from "../../components/core/DetroitIcon"
import {
encodeToFrontendFilterString,
decodeFiltersFromFrontendUrl,
ListingFilterState,
encodeToFrontendFilterString,
FrontendListingFilterStateKeys,
ListingFilterState,
} from "@bloom-housing/shared-helpers"
import Layout from "../../layouts/application"
import { MetaTags } from "../../components/shared/MetaTags"
Expand All @@ -27,7 +27,7 @@ import { useListingsData } from "../../lib/hooks"
import { EnumListingFilterParamsStatus, OrderByFieldsEnum } from "@bloom-housing/backend-core/types"
import FilterForm from "../../components/filters/FilterForm"
import ListingPagination from "../../components/listing/ListingPagination"
import { getListings } from "../../lib/helpers"
import { getListings, removeCommas } from "../../lib/helpers"

const FilteredListingsPage = () => {
const router = useRouter()
Expand Down Expand Up @@ -90,6 +90,12 @@ const FilteredListingsPage = () => {
const onSubmit = (page: number, limit: number, data: ListingFilterState) => {
// hide status filter
delete data[FrontendListingFilterStateKeys.status]
data[FrontendListingFilterStateKeys.minRent] = removeCommas(
data[FrontendListingFilterStateKeys.minRent]
)
data[FrontendListingFilterStateKeys.maxRent] = removeCommas(
data[FrontendListingFilterStateKeys.maxRent]
)
setFilterModalVisible(false)
setQueryString(page, limit, data)
}
Expand Down

0 comments on commit a5de9b2

Please sign in to comment.