diff --git a/public/product_assets/images/congrats.svg b/public/icons/congrats.svg similarity index 100% rename from public/product_assets/images/congrats.svg rename to public/icons/congrats.svg diff --git a/public/icons/smiley-sad.svg b/public/icons/smiley-sad.svg new file mode 100644 index 0000000..64c7c5f --- /dev/null +++ b/public/icons/smiley-sad.svg @@ -0,0 +1 @@ + diff --git a/src/components/ui/FinalPage/FailureComponent.tsx b/src/components/ui/FinalPage/FailureComponent.tsx new file mode 100644 index 0000000..945fe35 --- /dev/null +++ b/src/components/ui/FinalPage/FailureComponent.tsx @@ -0,0 +1,45 @@ +import { List, ListItem, Typography } from "@mui/material"; +import { Container } from "@mui/system"; +import Image from "next/image"; + +interface IFailureComponent { + missingCartTitles: string[]; +} + +const FailureComponent: React.FC = ({ + missingCartTitles, +}) => { + return ( + + + + Dommage, + + + Tu as oublié d'ajouter les ingrédients suivants à ton panier : + + {missingCartTitles.map((title) => ( + + {title} + + ))} + + + + ); +}; + +export default FailureComponent; diff --git a/src/components/ui/FinalPage/SucessComponent.tsx b/src/components/ui/FinalPage/SucessComponent.tsx new file mode 100644 index 0000000..89f1645 --- /dev/null +++ b/src/components/ui/FinalPage/SucessComponent.tsx @@ -0,0 +1,30 @@ +import { Typography } from "@mui/material"; +import { Container } from "@mui/system"; +import Image from "next/image"; + +const SuccessComponent = ( + + + + Félicitations, + + + tu as réussi à commander les ingrédients pour réaliser ta tarte aux pommes + + +); + +export default SuccessComponent; diff --git a/src/pages/final.tsx b/src/pages/final.tsx index 48a2a39..050cd38 100644 --- a/src/pages/final.tsx +++ b/src/pages/final.tsx @@ -1,12 +1,28 @@ -import { Typography } from "@mui/material"; import { Container } from "@mui/system"; +import { useAtom } from "jotai"; import type { NextPage } from "next"; -import Image from "next/image"; import AppLink from "src/components/ui/Buttons/AppLink"; +import FailureComponent from "src/components/ui/FinalPage/FailureComponent"; +import SuccessComponent from "src/components/ui/FinalPage/SucessComponent"; import PageTextTemplate from "src/components/ui/PageTextTemplate/PageTextTemplate"; +import { cartAtom } from "src/store/cart"; const FinalPage: NextPage = () => { + const [cart] = useAtom(cartAtom); + const expectedCartTitles = ["Pomme", "Oeuf", "Farine de blé"]; + const missingCartTitles = []; + for (const expectedCartTitle of expectedCartTitles) { + if ( + !Object.values(cart).find( + (cartItem) => cartItem.product.title === expectedCartTitle + ) + ) { + missingCartTitles.push(expectedCartTitle); + } + } + + const isCartValid = missingCartTitles.length == 0; const content = ( { flexDirection: "column", }} > - - - Félicitations, - - - tu as réussi à commander les ingrédients pour réaliser ta tarte aux - pommes - + {isCartValid ? SuccessComponent : FailureComponent({ missingCartTitles })} );