-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from WildCodeSchool/feature/57/validate-reser…
…vation feature/57/validate-reservation: updated reservation status to valida…
- Loading branch information
Showing
6 changed files
with
263 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
import { Reservation } from "../interface/types"; | ||
import { Card, Divider } from "antd"; | ||
import ValidateReservationButton from "./ValidateReservationButton"; | ||
|
||
export const ReservationCard = ({ reservation }: Reservation) => { | ||
const formattedStartDate = new Date(reservation.startDate).toLocaleDateString( | ||
"fr-FR" | ||
); | ||
const formattedEndDate = new Date(reservation.endDate).toLocaleDateString( | ||
"fr-FR" | ||
); | ||
|
||
const reservationId = reservation.id; | ||
console.log(reservation, "rser"); | ||
return ( | ||
<div> | ||
<div>id de la réservation : {reservation.id} </div> | ||
<div>date de début : {reservation.startDate} </div> | ||
<div>date de fin : {reservation.endDate} </div> | ||
<div>nombre d'articles : {reservation.articles.length}</div> | ||
<div>prix : </div> | ||
<div>status: {reservation.status}</div> | ||
<div>détails</div> | ||
<div>-------</div> | ||
</div> | ||
<> | ||
<Card title={`Réservation numéro ${reservationId}`}> | ||
<p>Date de début : {formattedStartDate} </p> | ||
<p>Date de fin : {formattedEndDate} </p> | ||
<p>Nombre d'articles : {reservation.articles.length}</p> | ||
<p>Prix : </p> | ||
<p>Status : {reservation.status}</p> | ||
{reservation.status === "pending" && ( | ||
<ValidateReservationButton reservation={reservation} /> | ||
)} | ||
</Card> | ||
<Divider dashed /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useMutation } from "@apollo/client"; | ||
import { Button, message, Popconfirm } from "antd"; | ||
import { UPDATE_RESERVATION_STATUS } from "../graphql/mutations"; | ||
import { Reservation } from "../interface/types"; | ||
import { | ||
GetAllArticlesDocument, | ||
GetAllProductsDocument, | ||
} from "../generated/graphql-types"; | ||
|
||
function ValidateReservationButton({ reservation }: Reservation) { | ||
const [updateReservationStatus] = useMutation(UPDATE_RESERVATION_STATUS, { | ||
onCompleted: () => { | ||
message.success("La réservation a bien été validée."); | ||
setTimeout(function () { | ||
window.location.reload(); | ||
}, 2000); | ||
}, | ||
onError: () => { | ||
message.error("Une erreur est survenue lors de la validation."); | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<Popconfirm | ||
title="Valider cette réservation ?" | ||
description="La réservation ne pourra plus être annulée." | ||
okText="Oui" | ||
cancelText="Non" | ||
onConfirm={() => | ||
updateReservationStatus({ | ||
variables: { | ||
reservationId: reservation.id.toString(), | ||
refetchQueries: [GetAllProductsDocument, GetAllArticlesDocument], | ||
}, | ||
}) | ||
} | ||
> | ||
<Button type="primary" style={{ marginTop: "10px" }}> | ||
Valider | ||
</Button> | ||
</Popconfirm> | ||
</> | ||
); | ||
} | ||
|
||
export default ValidateReservationButton; |
Oops, something went wrong.