Skip to content

Commit

Permalink
Fixed some types in front
Browse files Browse the repository at this point in the history
  • Loading branch information
antonisdev committed Dec 12, 2024
1 parent 79ad020 commit 1829478
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
22 changes: 14 additions & 8 deletions frontend/src/components/ReservationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { Card, Divider } from "antd";
import ValidateReservationButton from "./ValidateReservationButton";
import { ReservationData } from "../interface/types";

export const ReservationCard = ( {reservationData} : {reservationData: ReservationData}) => {
const formattedStartDate = new Date(reservationData.reservation.startDate).toLocaleDateString(
"fr-FR"
);
const formattedEndDate = new Date(reservationData.reservation.endDate).toLocaleDateString(
"fr-FR"
);
export const ReservationCard = ({
reservationData,
}: {
reservationData: ReservationData;
}) => {
const formattedStartDate = new Date(
reservationData.reservation.startDate
).toLocaleDateString("fr-FR");
const formattedEndDate = new Date(
reservationData.reservation.endDate
).toLocaleDateString("fr-FR");
const reservationId = reservationData.reservation.id;
return (
<>
Expand All @@ -19,7 +23,9 @@ export const ReservationCard = ( {reservationData} : {reservationData: Reservati
<p>Prix : {reservationData.totalPrice} euros</p>
<p>Status : {reservationData.reservation.status}</p>
{reservationData.reservation.status === "pending" && (
<ValidateReservationButton reservation={reservationData.reservation} />
<ValidateReservationButton
reservation={reservationData.reservation}
/>
)}
</Card>
<Divider dashed />
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/components/ValidateReservationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import {
GetReservationsByUserIdDocument,
} from "../generated/graphql-types";

function ValidateReservationButton({ reservation }: Reservation) {
type ValidateReservationButtonProps = {
reservation: Reservation;
};

const ValidateReservationButton = ({
reservation,
}: ValidateReservationButtonProps) => {
const [updateReservationStatus] = useMutation(UPDATE_RESERVATION_STATUS, {
onCompleted: () => {
message.success("La réservation a bien été validée.");
Expand Down Expand Up @@ -40,6 +46,6 @@ function ValidateReservationButton({ reservation }: Reservation) {
</Popconfirm>
</>
);
}
};

export default ValidateReservationButton;
19 changes: 9 additions & 10 deletions frontend/src/interface/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,19 @@ export interface NewProductFormValues {
export type Article = {
id: number;
product?: ProductCard;
reservations?: Reservation[] | null
reservations?: Reservation[] | null;
};

export type Reservation = {
reservation: {
id: number;
startDate: string;
endDate: string;
articles: Article[];
status: string;
createdAt?: string;
};
id: number;
startDate: string;
endDate: string;
articles: Article[];
status: string;
createdAt?: string;
};

export type ReservationData = Reservation & {
export type ReservationData = {
reservation: Reservation;
totalPrice?: number;
};

0 comments on commit 1829478

Please sign in to comment.