Skip to content

Commit

Permalink
PIMS-2036: Map Filter - ERP Projects (#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
LawrenceLau2020 authored Oct 22, 2024
1 parent 6c9077c commit 62411d0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions express-api/src/controllers/properties/propertiesSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const MapFilterSchema = z.object({
AdministrativeAreaIds: arrayFromString(numberSchema),
ClassificationIds: arrayFromString(numberSchema),
PropertyTypeIds: arrayFromString(numberSchema),
ProjectStatusId: z.coerce.number().optional(),
Name: z.string().optional(),
RegionalDistrictIds: arrayFromString(numberSchema),
UserAgencies: z.array(z.number().int()).optional(),
Expand Down
1 change: 1 addition & 0 deletions express-api/src/services/properties/propertiesServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ const getPropertiesForMap = async (filter?: MapFilter) => {
: undefined,
PID: filter.PID,
PIN: filter.PIN,
ProjectStatusId: filter.ProjectStatusId,
Address1: filter.Address ? ILike(`%${filter.Address}%`) : undefined,
Name: filter.Name ? ILike(`%${filter.Name}%`) : undefined,
PropertyTypeId: filter.PropertyTypeIds ? In(filter.PropertyTypeIds) : undefined,
Expand Down
55 changes: 55 additions & 0 deletions react-app/src/components/form/ToggleSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { SxProps, Typography, Box, useTheme, Switch } from '@mui/material';
import { Controller, useFormContext } from 'react-hook-form';

interface ToggleSwitchProps {
name: string;
label: string;
sx?: SxProps;
required?: boolean;
}

const ToggleSwitch = (props: ToggleSwitchProps) => {
const { control } = useFormContext();
const theme = useTheme();
const { name, label, required } = props;
return (
<Controller
name={name}
control={control}
rules={{ validate: (value) => !required || value || 'Required field.' }}
render={({ field: { onChange, value, onBlur }, fieldState: { error } }) => (
<>
<Box
sx={{
display: 'flex',
alignItems: 'center',
}}
>
<Switch
id={`single-checkbox-${name}`}
onChange={(_, data) => onChange(data)}
onBlur={onBlur}
checked={!!value}
required={required}
/>
<Typography>
{label} {required ? <sup>{'*'}</sup> : <></>}
</Typography>
</Box>
{!!error && !!error.message ? (
<Box>
<Typography ml={'3.2em'} fontSize={'smaller'} color={theme.palette.error.main}>
{error.message}
</Typography>
</Box>
) : (
<></>
)}
</>
)}
/>
);
};

export default ToggleSwitch;
5 changes: 5 additions & 0 deletions react-app/src/components/map/controls/FilterControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import usePimsApi from '@/hooks/usePimsApi';
import { Box, Typography, Grid, Button } from '@mui/material';
import React, { Dispatch, SetStateAction, useContext } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { ProjectStatus } from '@/constants/projectStatuses';
import ToggleSwitch from '@/components/form/ToggleSwitch';

interface FilterControlProps {
setFilter: Dispatch<SetStateAction<MapFilter>>;
Expand Down Expand Up @@ -51,6 +53,7 @@ const FilterControl = (props: FilterControlProps) => {
PropertyTypes: [],
RegionalDistricts: [],
Name: '',
InERP: false,
},
});

Expand Down Expand Up @@ -131,6 +134,7 @@ const FilterControl = (props: FilterControlProps) => {
})) ?? []
}
/>
<ToggleSwitch name={'InERP'} label="In ERP" />
<Grid item xs={12} justifyContent={'space-between'} display={'inline-flex'} gap={1}>
<Button
variant="outlined"
Expand Down Expand Up @@ -167,6 +171,7 @@ const FilterControl = (props: FilterControlProps) => {
(option) => option.value,
),
RegionalDistrictIds: formValues.RegionalDistricts.map((option) => option.value),
ProjectStatusId: formValues.InERP ? ProjectStatus.APPROVED_FOR_ERP : undefined,
};
setFilter({
Polygon: filter.Polygon,
Expand Down
1 change: 1 addition & 0 deletions react-app/src/hooks/api/usePropertiesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface MapFilter {
RegionalDistrictIds?: number[];
Name?: string;
Polygon?: string;
ProjectStatusId?: number;
}

export interface PropertyUnion {
Expand Down

0 comments on commit 62411d0

Please sign in to comment.