Skip to content

Commit

Permalink
Merge branch 'infra/refactor' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlr committed Oct 4, 2023
2 parents ff2c5e4 + 461665d commit 20a1762
Showing 1 changed file with 89 additions and 55 deletions.
144 changes: 89 additions & 55 deletions ui/pages/espace-pro/offre/[jobId]/[option].tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,111 @@
import { Box, Flex, Spinner, Text, useToast } from "@chakra-ui/react"
import { Box, Container, Flex, Image, Link, Spinner, Text } from "@chakra-ui/react"
import { useRouter } from "next/router"
import { useEffect } from "react"
import { useEffect, useState } from "react"

import Footer from "@/components/footer"
import Navigation from "@/components/navigation"

import { redirect } from "../../../../common/utils/router"
import { cancelOffre, fillOffre } from "../../../../utils/api"

export default function MailActionsOnOffre() {
const router = useRouter()
const { jobId, option } = router.query
const toast = useToast()

const redirectFn = () => {
setTimeout(() => {
redirect("/", true)
}, 5000)
}
const [result, setResult] = useState("")

const error = () => {
toast({
title: "Une erreur est survenue",
description: "Merci de vous connecter.",
status: "error",
position: "top",
isClosable: false,
duration: 5000,
})
redirectFn()
setResult("Une erreur s'est produite. Merci de contacter le support de La Bonne Alternance")
}

useEffect(() => {
if (!jobId || !option) {
error()
}

if (option === "cancel") {
cancelOffre(jobId)
.then(() => {
toast({
title: "Offre annulée.",
description: "L'offre a bien été mise à jour.",
position: "top",
status: "success",
isClosable: true,
duration: 5000,
if (jobId && option) {
if (option === "cancel") {
cancelOffre(jobId)
.then(() => {
setResult("ok")
})
redirectFn()
})
.catch(() => error())
}
.catch(() => error())
}

if (option === "provided") {
fillOffre(jobId)
.then(() => {
toast({
title: "Offre pourvue.",
description: "L'offre a bien été mise à jour",
position: "top",
status: "success",
isClosable: true,
duration: 5000,
if (option === "provided") {
fillOffre(jobId)
.then(() => {
setResult("ok")
})
redirectFn()
})
.catch(() => error())
.catch(() => error())
}
}
})
}, [jobId, option])

const cssParameters = {
background: "#fff1e5",
borderRadius: "10px",
fontWeight: 700,
margin: "10px",
marginTop: "32px",
padding: "5px",
}

return (
<Box>
<Flex justify="center" align="center" h="100vh" direction="column">
<Spinner thickness="4px" speed="0.5s" emptyColor="gray.200" color="bluefrance.500" size="xl" />
<Text>Verification en cours...</Text>
</Flex>
<Navigation />
<Container p={12} my={0} mb={[0, 12]} variant="pageContainer">
<Box margin="auto">
{option === "cancel" && (
<Text as="h1" variant="homeEditorialH1">
Annulation de l'offre déposée sur La Bonne Alternance
</Text>
)}
{option === "provided" && (
<Text as="h1" variant="homeEditorialH1">
Modification de l'offre déposée sur La Bonne Alternance
</Text>
)}

{!result && (
<Box my={8}>
<Spinner thickness="4px" speed="0.5s" emptyColor="gray.200" color="bluefrance.500" size="xl" />
<Text>Chargement en cours...</Text>
</Box>
)}
{result && result !== "ok" && (
<Flex alignItems="center" {...cssParameters} color="grey.650">
<Image width="32px" mr={2} src="/images/icons/errorAlert.svg" alt="" />
{result}
</Flex>
)}
{result && result === "ok" && <Text variant="homeEditorialH2">Votre offre a été modifiée</Text>}

<Box mt={8}>
Aller sur le site{" "}
<Link href="/" aria-label="Accès au site La Bonne Alternace" textDecoration="underline" fontWeight={700}>
La Bonne Alternance
</Link>
<br />
<br />
Se connecter à votre{" "}
<Link href="/espace-pro/authentification" aria-label="Accès à la page de connexion" textDecoration="underline" fontWeight={700}>
espace recruteur
</Link>
<br />
<br />
{jobId && (
<>
Voir{" "}
<Link
href={`/recherche-apprentissage?&display=list&page=fiche&type=matcha&itemId=${jobId}`}
aria-label="Visualiser l'offre en ligne"
textDecoration="underline"
fontWeight={700}
>
l'offre
</Link>{" "}
sur le site La Bonne Alternance
</>
)}
</Box>
</Box>
</Container>
<Footer />
</Box>
)
}

0 comments on commit 20a1762

Please sign in to comment.