diff --git a/site/source/locales/ui-en.yaml b/site/source/locales/ui-en.yaml index 38e27d863..eb45402b9 100644 --- a/site/source/locales/ui-en.yaml +++ b/site/source/locales/ui-en.yaml @@ -1213,6 +1213,7 @@ pages: code: description: "Here is the code to copy and paste on your site:" titre: Integration Code + copy-code: Copy the code components: CasParticuliers: '<0>Learn more about...<1><0>How to make a simulation in the past?<1>Since the end of 2021, the calculation rules of the diff --git a/site/source/locales/ui-fr.yaml b/site/source/locales/ui-fr.yaml index 973f1b6ac..50271d8c3 100644 --- a/site/source/locales/ui-fr.yaml +++ b/site/source/locales/ui-fr.yaml @@ -974,6 +974,7 @@ pages: code: description: "Voici le code à copier-coller sur votre site :" titre: Code d'intégration + copy-code: Copier le code components: CasParticuliers: "<0>En savoir plus sur...<1><0>Comment faire une simulation dans le passé ?<1>Depuis fin 2021, les règles de calculs des diff --git a/site/source/pages/integration/Iframe.tsx b/site/source/pages/integration/Iframe.tsx index 5a53f826b..6c55a8d06 100644 --- a/site/source/pages/integration/Iframe.tsx +++ b/site/source/pages/integration/Iframe.tsx @@ -18,6 +18,7 @@ import './iframe.css' import cciLogo from './_images/cci.png' import minTraLogo from './_images/min-tra.jpg' import poleEmploiLogo from './_images/pole-emploi.png' +import { Button } from '@/design-system/buttons' const checkIframe = (obj: SimulatorData[keyof SimulatorData]) => 'iframePath' in obj && obj.iframePath && !('private' in obj && obj.private) @@ -317,32 +318,27 @@ function IntegrationCode({ module = 'simulateur-embauche', color, }: IntegrationCodeProps) { + const { t } = useTranslation() + const codeRef = useRef(null) - const [secondClick, setSecondClick] = useState(false) - const selectAllCode = () => { - if (codeRef.current && !secondClick) { - const range = document.createRange() - range.selectNode(codeRef.current) - window.getSelection()?.removeAllRanges() - window.getSelection()?.addRange(range) - setSecondClick(true) - } - if (secondClick) { - setSecondClick(false) - } + const [copied, setCopied] = useState(false) + + const copyCodeToClipboard = (): void => { + navigator.clipboard + .writeText(codeRef.current?.innerText || '') + .then(() => setCopied(true)) + .catch(() => setCopied(false)) } return ( - - {'<'} - script -
- data-module=" - {module}" - {color ? ( - <> -
- data-couleur=" - {color}" - - ) : ( - '' - )} -
- src - ="https://mon-entreprise.urssaf.fr/simulateur-iframe-integration.js"{'>'} - {'<'} - / - script - {'>'} -
+ + {'<'} + script +
+ data-module=" + {module}" + {color ? ( + <> +
+ data-couleur=" + {color}" + + ) : ( + '' + )} +
+ src + ="https://mon-entreprise.urssaf.fr/simulateur-iframe-integration.js" + {'>'} + {'<'} + / + script + {'>'} +
+
+ +
+ ) }