-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39a6ceb
commit 0da140d
Showing
2 changed files
with
69 additions
and
8 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
66 changes: 66 additions & 0 deletions
66
...ges/code-du-travail-frontend/src/modules/outils/simulateur-embauche/SimulateurEmbauche.js
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,66 @@ | ||
"use client"; | ||
import React from "react"; | ||
|
||
class SimulateurEmbauche extends React.PureComponent { | ||
simRef = React.createRef(); | ||
state = { | ||
simulator: "loading", | ||
}; | ||
|
||
onError = (error) => { | ||
this.setState({ error, simulator: "error" }); | ||
}; | ||
|
||
onLoad = () => { | ||
this.setState({ simulator: "success" }); | ||
if ( | ||
!this.simRef.current || | ||
!this.simRef.current.querySelector("#simulateurEmbauche") | ||
) { | ||
this.setState({ error: "empty child", simulator: "error" }); | ||
} | ||
}; | ||
|
||
componentDidMount() { | ||
const script = document.createElement("script"); | ||
script.src = | ||
"https://mon-entreprise.urssaf.fr/simulateur-iframe-integration.js"; | ||
script.async = true; | ||
script.dataset.couleur = "#2975D1"; | ||
script.id = "script-simulateur-embauche"; | ||
script.onload = this.onLoad; | ||
script.onerror = this.onError; | ||
|
||
if (this.simRef.current) { | ||
this.simRef.current.appendChild(script); | ||
} | ||
} | ||
|
||
render() { | ||
const { simulator } = this.state; | ||
return ( | ||
<> | ||
{simulator === "loading" && <p>Chargement de l’outil</p>} | ||
{simulator === "error" ? ( | ||
<> | ||
<p>Le simulateur d’embauche n’est pas disponible actuellement.</p> | ||
<p> | ||
Retrouvez les autres simulateurs autour du thème de l’entreprise, | ||
sur le site:{" "} | ||
<a | ||
title="Voir les simulateurs" | ||
href="https://mon-entreprise.urssaf.fr/" | ||
> | ||
https://mon-entreprise.urssaf.fr/ | ||
</a> | ||
</p> | ||
</> | ||
) : ( | ||
<div ref={this.simRef} /> | ||
)} | ||
</> | ||
); | ||
} | ||
} | ||
|
||
export { SimulateurEmbauche }; |