Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landlord Listing Form + Unit Details Updates #106

Merged
merged 4 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/src/models/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const unitSchema = new Schema(
numBeds: { type: Number, required: true },
numBaths: { type: Number, required: true },
appliances: { type: [String], required: true },
utilities: { type: [String], required: true },
communityFeatures: { type: [String], required: true },
parking: { type: [String], required: true },
accessibility: { type: [String], required: true },
Expand Down
1 change: 1 addition & 0 deletions backend/src/validators/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const createUnitSchema = [
body("numBeds").exists().withMessage("is required").isNumeric().withMessage("must be a number"),
body("numBaths").exists().withMessage("is required").isNumeric().withMessage("must be a number"),
body("appliances").exists().withMessage("is required").isArray().withMessage("must be an array"),
body("utilities").exists().withMessage("is required").isArray().withMessage("must be an array"),
Azhou2023 marked this conversation as resolved.
Show resolved Hide resolved
body("communityFeatures")
.exists()
.withMessage("is required")
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Unit = {
numBeds: number;
numBaths: number;
appliances: string[];
utilities: string[];
communityFeatures: string[];
parking: string[];
accessibility: string[];
Expand Down
84 changes: 84 additions & 0 deletions frontend/src/components/ListingForm/Utilities.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {
CustomCheckboxRadio,
FieldHeader,
Margin32,
OptionLabel,
RadioCheckBoxContainer,
RadioCheckboxCol,
Required,
} from "@/components/ListingForm/CommonStyles";

type UtilitiesProps = {
utilities: string[];
setUtilities: React.Dispatch<React.SetStateAction<string[]>>;
handleCheckBoxNA: (
option: string,
getter: string[],
setter: React.Dispatch<React.SetStateAction<string[]>>,
) => void;
};

export const Utilities = (props: UtilitiesProps) => {
return (
<Margin32>
<FieldHeader>
Utilities Included <Required>*</Required>
</FieldHeader>
<RadioCheckBoxContainer>
<RadioCheckboxCol>
<OptionLabel>
<CustomCheckboxRadio
type="checkbox"
name="Electricity"
value="Electricity"
checked={props.utilities.includes("Electricity")}
onChange={() => {
props.handleCheckBoxNA("Electricity", props.utilities, props.setUtilities);
}}
/>
Electricity
</OptionLabel>

<OptionLabel>
<CustomCheckboxRadio
type="checkbox"
name="Water"
value="Water"
checked={props.utilities.includes("Water")}
onChange={() => {
props.handleCheckBoxNA("Water", props.utilities, props.setUtilities);
}}
/>
Water
</OptionLabel>

<OptionLabel>
<CustomCheckboxRadio
type="checkbox"
name="Gas"
value="Gas"
checked={props.utilities.includes("Gas")}
onChange={() => {
props.handleCheckBoxNA("Gas", props.utilities, props.setUtilities);
}}
/>
Gas
</OptionLabel>

<OptionLabel>
<CustomCheckboxRadio
type="checkbox"
name="Trash"
value="Trash"
checked={props.utilities.includes("Trash")}
onChange={() => {
props.handleCheckBoxNA("Trash", props.utilities, props.setUtilities);
}}
/>
Trash
</OptionLabel>
</RadioCheckboxCol>
</RadioCheckBoxContainer>
</Margin32>
);
};
8 changes: 8 additions & 0 deletions frontend/src/components/ListingFormComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Pets } from "@/components/ListingForm/Pets";
import { SharingHousing } from "@/components/ListingForm/SharingHousing";
import { Textbox } from "@/components/ListingForm/Textbox";
import { ThirdPartyPayment } from "@/components/ListingForm/ThirdPartyPayment";
import { Utilities } from "@/components/ListingForm/Utilities";

const ErrorMessage = styled.div`
color: #b64201;
Expand Down Expand Up @@ -89,6 +90,7 @@ export function ListingFormComponents(props: ListingFormComponentsProps) {
);
const [numberOfBathsOther, setNumberOfBathsOther] = useState<string | undefined>();
const [appliances, setAppliances] = useState<string[]>(props.initialValues?.appliances ?? []);
const [utilities, setUtilities] = useState<string[]>(props.initialValues?.utilities ?? []);
const [communityAndNeighborInfo, setCommunityAndNeighborInfo] = useState<string[]>(
props.initialValues?.communityFeatures ?? [],
);
Expand Down Expand Up @@ -296,6 +298,7 @@ export function ListingFormComponents(props: ListingFormComponentsProps) {
numBeds: numberOfBedrooms ?? parseInt(numberOfBedroomsOther ?? ""),
numBaths: numberOfBaths ?? parseFloat(numberOfBathsOther ?? ""),
appliances,
utilities,
communityFeatures:
communityAndNeighborInfo[0] === ""
? [communityAndNeighborInfoOther]
Expand Down Expand Up @@ -480,6 +483,11 @@ export function ListingFormComponents(props: ListingFormComponentsProps) {
setAppliances={setAppliances}
handleCheckBoxNA={handleCheckBoxNA}
/>
<Utilities
utilities={utilities}
setUtilities={setUtilities}
handleCheckBoxNA={handleCheckBoxNA}
/>
<CommunityInfo
communityAndNeighborInfo={communityAndNeighborInfo}
handleCommunityAndNeighborInfo={handleCommunityAndNeighborInfo}
Expand Down
42 changes: 24 additions & 18 deletions frontend/src/components/ReferralTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum ReferralUpdateType {
}

export const ReferralTable = (props: ReferralTableProps) => {
const { allHousingLocators, allReferringStaff } = useContext(DataContext);
const { currentUser, allReferringStaff } = useContext(DataContext);
const [referrals, setReferrals] = useState<Referral[]>([]);
const [popup, setPopup] = useState<boolean>(false);

Expand Down Expand Up @@ -148,6 +148,27 @@ export const ReferralTable = (props: ReferralTableProps) => {
});
};

const HLSection = (referral: Referral) => {
if (currentUser?.isHousingLocator) {
return (
<UserDropdown
width="100%"
placeholder="Search"
onSelect={(value) => {
handleUpdate(referral, value as User, ReferralUpdateType.ReferringStaff);
}}
initialSelection={referral.assignedHousingLocator}
options={allReferringStaff}
/>
);
}
return (
<>
{referral.assignedHousingLocator.firstName + " " + referral.assignedHousingLocator.lastName}
</>
);
};

return (
<ReferralTableContainer>
<ReferralTableTitleSection>
Expand All @@ -173,13 +194,7 @@ export const ReferralTable = (props: ReferralTableProps) => {
<Table
columns={TABLE_COLUMN_NAMES}
rows={referrals.map((referral, idx) => {
const {
status,
renterCandidate,
assignedReferringStaff,
assignedHousingLocator,
updatedAt,
} = referral;
const { status, renterCandidate, assignedReferringStaff, updatedAt } = referral;
// Generate a list of cells for each row
return [
<RenterCandidateLink
Expand All @@ -201,16 +216,7 @@ export const ReferralTable = (props: ReferralTableProps) => {
initialSelection={assignedReferringStaff}
options={allReferringStaff}
/>,
<UserDropdown
key={`hl-select-${idx}`}
width="100%"
placeholder="Search"
onSelect={(value) => {
handleUpdate(referral, value as User, ReferralUpdateType.HousingLocator);
}}
initialSelection={assignedHousingLocator}
options={allHousingLocators}
/>,
HLSection(referral),
<ReferralTableDropDown
key={`status-select-${idx}`}
onSelect={(value) => {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/pages/UnitDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ export function UnitDetails() {
const appliances = unit.appliances.map((appliance, i) => (
<ListText key={appliance + i}>{appliance}</ListText>
));
const utilities = unit.utilities.map((utility, i) => (
<ListText key={utility + i}>{utility}</ListText>
));
const parkingRequirements = unit.parking.map((parking, i) => (
<ListText key={parking + i}>{parking}</ListText>
));
Expand Down Expand Up @@ -731,6 +734,8 @@ export function UnitDetails() {
{pets}
<StrongText>Appliances: </StrongText>
{appliances}
<StrongText>Utilities: </StrongText>
{utilities}
<StrongText>Housing Authority: </StrongText>
<ListText> {unit.housingAuthority}</ListText>
<StrongText>Additional Comments from Landlord: </StrongText>
Expand Down
Loading