Commit ddede32e authored by Lucia Lopuchova's avatar Lucia Lopuchova Committed by cizek
Browse files

Show reservations in my reservation tab

parent f62b4137
export type StandReservation = {
standId: string;
itemCategories: string[];
standTypeName: string;
eventName: string;
startDate: string;
}
\ No newline at end of file
import { TableColumn } from "components/table/types";
import { StandReservation } from "../../models/stand-reservation";
export const reservationColumns: TableColumn<StandReservation>[] = [
{
key: "standTypeName",
label: "Stand Type",
render: ({standTypeName}) => standTypeName,
},
{
key: "itemCategories",
label: "Item Categories",
render: ({itemCategories}) => itemCategories.join(", ")
},
{
key: "eventName",
label: "Event",
render: ({eventName}) => eventName
},
{
key: "startDate",
label: "Start Date",
render: ({startDate}) => startDate
}
];
\ No newline at end of file
import { useNotification } from "../../context/notification/notification-context";
import { useQuery } from "react-query";
import { getUserReservations } from "./stand-reservation-api";
import { Container } from "@mantine/core";
import { Table } from "components/table/table";
import { reservationColumns } from "./reservation-columns";
interface Props {
userId: string;
}
export const ReservationTable = ({ userId }: Props) => {
const { showNotification } = useNotification();
const { data, isLoading } = useQuery(["userId", userId], () => getUserReservations(userId), {
onError: () => {
showNotification({
content: "Reservations failed to load",
variant: "error",
});
},
});
return <Container sx={{margin: "2rem auto"}}>
<Table
title="My reservations"
columns={reservationColumns}
rows={data}
isLoading={isLoading}
/>
</Container>
}
\ No newline at end of file
...@@ -13,4 +13,4 @@ export const putReservation = ( args: {marketEventId: string, values: Reservatio ...@@ -13,4 +13,4 @@ export const putReservation = ( args: {marketEventId: string, values: Reservatio
axios.put(`${apiUrl}/market-events/${args.marketEventId}/reserve-stand`, args.values); axios.put(`${apiUrl}/market-events/${args.marketEventId}/reserve-stand`, args.values);
export const getUserReservations = async (userId: string) => export const getUserReservations = async (userId: string) =>
axios.get(`${apiUrl}/list/user/${userId}`).then((res) => res.data) axios.get(`${apiUrl}/stands/list/user/${userId}`).then((res) => res.data)
import { useAuth } from "../../context/auth/auth-context"; import { useAuth } from "../../context/auth/auth-context";
import { NoReservations } from "./no-reservations"; import { NoReservations } from "./no-reservations";
import { ReservationTable } from "./reservation-table";
export const UserReservations = () => { export const UserReservations = () => {
const { user } = useAuth(); const { user } = useAuth();
if (user === undefined || user.userRole !== "SELLER") if (user === undefined || user.userRole !== "SELLER")
return <NoReservations /> return <NoReservations />
else return <></> else return <ReservationTable userId={user.id} />
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment