Skip to content

Commit

Permalink
updated Rprofile to use new queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionsluke committed Sep 18, 2024
1 parent 7e23187 commit 6a8b541
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 38 deletions.
37 changes: 23 additions & 14 deletions frontend/src/manager-components/profile_page/Rprofile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,19 @@ import { supabase } from '../../supabase';
import useSubscribeRenterCommentByRenterID from '../../subscribers/Renter Comment/useSubscribeRenterCommentByRenterID';
import useGetPropertiesByPropertyIDs from "../../queries/Property/useGetPropertiesByPropertyIDs";
import AppLoader from "../property_page/AppLoader";

// to stop linter
async function fetchApplications(rID) {

}
import useGetUserID from "../../queries/useGetUserID";

export default function RprofileForPM() {
const { rID } = useParams()
const {userID, loading: userLoading} = useGetUserID();
const navigate = useNavigate();
const fetchRenter = useGetRenterByRenterID();
const [renter, setRenter] = useState({});
//const [applications, setApplications] = useState([]);
const {renter: renterData, loading: renterLoading} = useGetRenterByRenterID(rID);
const {applications: baseApplications, loading: appLoading} = useGetApplicationsByRenterID(rID);
const fetchRenterComments = useGetRenterCommentsWithPMInfoByRenterID();
const [renterComments, setRenterComments] = useState([{}]);
const {comments: commentData, loading: commentsLoading} = useGetRenterCommentsWithPMInfoByRenterID(rID);
const fetchProperty = useGetPropertyByPropertyID();
const [dialogueOpen, setDialogueOpen] = useState(false);
const addComment = useAddRenterComment();
const [property_manager, setPropertyManager] = useState({});
const fetchPropertyManager = useGetPropertyManagerByPropertyManagerID();
const {propertyManager: pmData, loading: pmLoading} = useGetPropertyManagerByPropertyManagerID(userID);

// get all applications from renter
// get the properties from applications
Expand All @@ -46,7 +39,24 @@ export default function RprofileForPM() {
applications.push([app, address])
})
}
console.log(properties)

// get renter data
let renter = {}
if (!renterLoading) {
renter = renterData[0];
}

// get pm data
let property_manager = {};
if (!pmLoading) {
property_manager = pmData[0];
}

// setup comments
const [renterComments, setRenterComments] = useState([]);
if (!commentsLoading && renterComments.length === 0) {
setRenterComments(commentData);
}

/*
useEffect(() => {
Expand Down Expand Up @@ -104,7 +114,6 @@ export default function RprofileForPM() {
setDialogueOpen(true);
}

console.log(propLoading)

return (
<NavigationMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { supabase } from "../../supabase";
const useAddRenterComment = () =>{
const addRenterComment = async (property_manager_id, renter_id, company_id, renter_comment_contents) => {
const { data, error } = await supabase
.from("RENTER COMMENT")
.from("RENTER-COMMENT")
.insert({
property_manager_id: property_manager_id,
renter_id: renter_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {useEffect, useState} from "react";
const useGetApplicationsByRenterID = (renter_id) => {
const [applications, setApplications] = useState([]);
const [loading, setLoading] = useState(true);
console.log("apps run")

useEffect(() => {
const fetchApplications = async () => {
Expand All @@ -24,7 +23,6 @@ const useGetApplicationsByRenterID = (renter_id) => {
console.error('Error finding applications:', error);
setApplications([]); // Handle the error case by setting applications to an empty array
} else {
console.log(data)
setApplications(data || []); // Ensure data is always an array
}
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { supabase } from "../../supabase";
import {useEffect, useState} from "react";

const useGetPropertyManagerByPropertyManagerID = () =>{
const fetchPropertyManager = async (account_id) => {
const { data, error } = await supabase
.from("PROPERTY MANAGER")
.select("*")
.eq("property_manager_id", account_id);
const useGetPropertyManagerByPropertyManagerID = (pm_id) =>{
const [propertyManager, setPropertyManager] = useState([]);
const [loading, setLoading] = useState(true);

return {data, error}
};
return fetchPropertyManager
useEffect(() => {
const fetchPropertyManager = async () => {
if (pm_id) {
setLoading(true);
const { data, error } = await supabase
.from("PROPERTY MANAGER")
.select("*")
.eq("property_manager_id", pm_id);

if (error) {
setLoading(false);
setPropertyManager([]);
} else {
setLoading(false);
setPropertyManager(data || []);
}
} else {
setLoading(false);
setPropertyManager([]);
}
}
fetchPropertyManager();
}, [pm_id]);
return {propertyManager, loading};
};

export default useGetPropertyManagerByPropertyManagerID;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useState, useEffect } from 'react';
const useGetPropertiesByPropertyIDs = (property_ids) => {
const [properties, setProperties] = useState([]);
const [loading, setLoading] = useState(true);
console.log("props run")

useEffect(() => {
const fetchProperties = async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import { supabase } from "../../supabase";
import {useEffect, useState} from "react";

const useGetRenterCommentsWithPMInfoByRenterID = () =>{
const fetchComments = async (renter_id) => {
const { data, error } = await supabase
.from("RENTER COMMENT")
.select(
'*, "PROPERTY MANAGER"(*)'
)
.eq("renter_id", renter_id);
const useGetRenterCommentsWithPMInfoByRenterID = (renter_id) =>{
const [comments, setComments] = useState([]);
const [loading, setLoading] = useState(true);

return {data, error}
};
return fetchComments
useEffect(() => {
const fetchComments = async () => {
if (renter_id) {
setLoading(true);
const { data, error } = await supabase
.from("RENTER-COMMENT")
.select(
'*, "PROPERTY MANAGER"(*)'
)
.eq("renter_id", renter_id);

if (error) {
setLoading(false);
setComments([]);
} else {
setLoading(false);
setComments(data || []);
}
} else {
setLoading(false);
setComments([]);
}
}
fetchComments()
}, [renter_id]);
return {comments, loading};
};

export default useGetRenterCommentsWithPMInfoByRenterID;

0 comments on commit 6a8b541

Please sign in to comment.