diff --git a/src/deskstar-frontend/components/AddResourceModal.tsx b/src/deskstar-frontend/components/AddResourceModal.tsx index c880e5f4..2bcf68c3 100644 --- a/src/deskstar-frontend/components/AddResourceModal.tsx +++ b/src/deskstar-frontend/components/AddResourceModal.tsx @@ -6,6 +6,8 @@ import { createDeskType, createFloor, createRoom, + getAllDesks, + getDesks, getFloors, getRooms, } from "../lib/api/ResourceService"; @@ -17,13 +19,29 @@ import { IRoom } from "../types/room"; import { toast } from "react-toastify"; import FilterListbox from "./FilterListbox"; import Input from "./forms/Input"; +import { classes } from "../lib/helpers"; +import { IDesk } from "../types/desk"; const AddResourceModal = ({ buildings: origBuildings, deskTypes: origDeskTypes, + setLocations: setParentLocations, + setBuildings: setParentBuildings, + desks, + setDesks: setParentDesks, + setDeskTypes: setParentDeskTypes, + setFloors: setParentFloors, + setRooms: setParentRooms, }: { buildings: IBuilding[]; deskTypes: IDeskType[]; + setLocations: (locations: ILocation[]) => void; + setBuildings: (buildings: IBuilding[]) => void; + desks: IDesk[]; + setDesks: (desks: IDesk[]) => void; + setDeskTypes: (deskTypes: IDeskType[]) => void; + setFloors: (floors: IFloor[]) => void; + setRooms: (rooms: IRoom[]) => void; }) => { let { data: session } = useSession(); @@ -93,7 +111,9 @@ const AddResourceModal = ({ if (!session) return []; try { - const resFloors = await getFloors(session, selectedBuilding.buildingId); + const resFloors = ( + await getFloors(session, selectedBuilding.buildingId) + ).filter((floor) => !floor.isMarkedForDeletion); setFloors(resFloors); } catch (error) { toast.error(`${error}`); @@ -112,7 +132,10 @@ const AddResourceModal = ({ if (!session) return []; try { - const resRooms = await getRooms(session, selectedFloor.floorId); + const resRooms = await ( + await getRooms(session, selectedFloor.floorId) + ).filter((room) => !room.isMarkedForDeletion); + setRooms(resRooms); } catch (error) { toast.error(`${error}`); @@ -146,7 +169,8 @@ const AddResourceModal = ({ }); if (res.message.toLowerCase().includes("success")) { origBuildings.push(res.data as IBuilding); - setBuildings([...buildings, res.data as IBuilding]); + setBuildings(origBuildings); + setParentBuildings(origBuildings); const tmp = new Map(); [ ...locations, @@ -155,6 +179,7 @@ const AddResourceModal = ({ tmp.set(element.locationName, { locationName: element.locationName }) ); setLocations(Array.from(tmp.values())); + setParentLocations(Array.from(tmp.values())); toast.success(res.message); } else { toast.error(res.message); @@ -186,6 +211,7 @@ const AddResourceModal = ({ if (res.message.toLowerCase().includes("success")) { setFloors([...floors, res.data as IFloor]); + setParentFloors([...floors, res.data as IFloor]); toast.success(res.message); } else { toast.error(res.message); @@ -219,6 +245,7 @@ const AddResourceModal = ({ }); if (res.message.toLowerCase().includes("success")) { setRooms([...rooms, res.data as IRoom]); + setParentRooms([...rooms, res.data as IRoom]); toast.success(res.message); } else { toast.error(res.message); @@ -238,6 +265,7 @@ const AddResourceModal = ({ if (res.message.toLowerCase().includes("success")) { setDeskTypes([...deskTypes, res.data as IDeskType]); + setParentDeskTypes([...deskTypes, res.data as IDeskType]); toast.success(res.message); } else { toast.error(res.message); @@ -279,6 +307,10 @@ const AddResourceModal = ({ roomId: room?.roomId, }); if (res.message.toLowerCase().includes("success")) { + const desk = (await getDesks(session)).find( + (d) => d.deskId === (res.data as any).deskId + ); + if (desk) setParentDesks([...desks, desk]); toast.success(res.message); } else { toast.error(res.message); @@ -565,7 +597,10 @@ const AddResourceModal = ({ placeholder="Desk Type Name" /> addDeskType()} > Confirm diff --git a/src/deskstar-frontend/lib/api/ResourceService.ts b/src/deskstar-frontend/lib/api/ResourceService.ts index 66e02866..9b6e2ec1 100644 --- a/src/deskstar-frontend/lib/api/ResourceService.ts +++ b/src/deskstar-frontend/lib/api/ResourceService.ts @@ -307,7 +307,6 @@ export async function updateBuilding( message: body || "An error occured.", }; } else { - console.log(body); result = { response: ResourceResponse.Success, data: JSON.parse(body) as IBuilding, @@ -343,7 +342,6 @@ export async function updateFloor( message: body || "An error occured.", }; } else { - console.log(body); result = { response: ResourceResponse.Success, data: JSON.parse(body) as IFloor, @@ -379,7 +377,6 @@ export async function updateRoom( message: body || "An error occured.", }; } else { - console.log(body); const parsed = JSON.parse(body); const room = parsed as IRoom; room.building = parsed["buildingName"]; @@ -419,7 +416,6 @@ export async function updateDesk( message: body || "An error occured.", }; } else { - console.log(body); const parsed = JSON.parse(body); const desk = parsed as IDesk; desk.deskTyp = parsed["deskTypeName"]; @@ -458,7 +454,6 @@ export async function updateDeskType( message: body || "An error occured.", }; } else { - console.log(body); result = { response: ResourceResponse.Success, data: JSON.parse(body) as IDeskType, diff --git a/src/deskstar-frontend/pages/resources/index.tsx b/src/deskstar-frontend/pages/resources/index.tsx index 897361c8..5992f7d7 100644 --- a/src/deskstar-frontend/pages/resources/index.tsx +++ b/src/deskstar-frontend/pages/resources/index.tsx @@ -65,9 +65,11 @@ const ResourceOverview = ({ }) => { let { data: session } = useSession(); - const locations: ILocation[] = origBuildings.map((building) => ({ - locationName: building.location, - })); + const [locations, setLocations] = useState( + origBuildings.map((building) => ({ + locationName: building.location, + })) + ); const router = useRouter(); @@ -484,6 +486,13 @@ const ResourceOverview = ({ @@ -737,11 +746,21 @@ export const getServerSideProps: GetServerSideProps = async (context) => { }; try { - const buildings = await getBuildings(session); - const floors = await getFloors(session); - const rooms = await getRooms(session); - const desks = await getDesks(session); - const deskTypes = await getDeskTypes(session); + const buildings = await ( + await getBuildings(session) + ).filter((b) => !b.isMarkedForDeletion); + const floors = await ( + await getFloors(session) + ).filter((b) => !b.isMarkedForDeletion); + const rooms = await ( + await getRooms(session) + ).filter((b) => !b.isMarkedForDeletion); + const desks = await ( + await getDesks(session) + ).filter((d) => !d.isMarkedForDeletion); + const deskTypes = await ( + await getDeskTypes(session) + ).filter((d) => !d.isMarkedForDeletion); return { props: { buildings,