🐛 Cache le widget Chômage Partiel quand on quitte le simulateur

pull/1130/head
Maxime Quandalle 2020-10-12 18:24:19 +02:00
parent ae6679d819
commit 44e515f23a
1 changed files with 10 additions and 3 deletions

View File

@ -9,18 +9,23 @@ import React, { useContext, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { DottedName } from 'Rules'
import styled from 'styled-components'
import { productionMode } from '../../../../utils'
declare global {
interface Window {
STONLY_WID: string
StonlyWidget?: {
open: () => void
close: () => void
launcherShow: () => void
launcherHide: () => void
}
}
}
export default function ChômagePartiel() {
const inIframe = useContext(IsEmbeddedContext)
useEffect(() => {
if (inIframe || !productionMode) {
if (inIframe) {
return
}
const script = document.createElement('script')
@ -28,10 +33,12 @@ export default function ChômagePartiel() {
script.src = 'https://stonly.com/js/widget/stonly-widget.js'
script.async = true
document.body.appendChild(script)
window.StonlyWidget?.launcherShow()
return () => {
window.StonlyWidget?.launcherHide()
document.body.removeChild(script)
}
}, [])
}, [inIframe])
return (
<>
<Warning localStorageKey="covid19">