Skip to content

Commit 2ce8073

Browse files
JaviMunitaJaviera Munita
andauthored
fix(PDYE-974): nuevo botón userway (#647)
Co-authored-by: Javiera Munita <javieramunita@MacBook-Air-de-Javiera.local>
1 parent 1ac3b69 commit 2ce8073

File tree

3 files changed

+27
-81
lines changed

3 files changed

+27
-81
lines changed

src/atoms/Icons/Accessibility.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ import { Base, BaseProps } from './Base'
33
export function Accessibility(props: BaseProps): JSX.Element {
44
return (
55
<Base {...props}>
6-
<svg
7-
width="16"
8-
height="16"
9-
viewBox="0 0 16 16"
10-
fill="none"
11-
stroke="#60798E"
12-
strokeWidth={0.3}
13-
>
6+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
147
<path
158
fillRule="evenodd"
169
clipRule="evenodd"

src/documentation/pages/Molecules/UserWay.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1-
import { MyHeading, MyText, MyTittle, Code } from '@/documentation/components'
1+
import { MyHeading, MyText, Code } from '@/documentation/components'
22
import { UserWay } from '@/molecules/UserWay/UserWay'
33

44
export const ViewUserWay = (): JSX.Element => {
55
return (
66
<>
77
<MyHeading>UserWay</MyHeading>
88
<MyText>
9-
Trigger personalizado para el widget gratuito de accesibilidad UserWay. Carga el script del
10-
widget, verifica que esté listo antes de poder ejecutarlo y maneja el click del botón.
9+
Botón personalizado para el widget gratuito de accesibilidad UserWay. Contiene los estilos
10+
base del elemento customizado y una función que detecta un botón localizado en el archivo
11+
index.html implementado en el sitio.
1112
</MyText>
12-
<Code text="import { UserWay } from '@eclass/ui-kit'" />
1313
<UserWay />
14-
<MyTittle>Props y atributos</MyTittle>
14+
<Code
15+
text="import { UserWay } from '@eclass/ui-kit'
16+
<UserWay/>"
17+
/>
1518
<MyText>
16-
El componente puede recibir un parámetro de color opcional que cambia el color del menú del
17-
widget. De no ser especificado, se usa el color predeterminado.
19+
Al hacer click en este componente, se activa el botón html que actúa como trigger del
20+
widget. Es importante que el botón al que apunta la función, tenga el id 'userWayTrigger'.
1821
</MyText>
19-
<Code text="<UserWay color='#0189FF'/>" />
22+
<Code
23+
text="function triggerWidget() {
24+
const buttonB = document.getElementById('userWayTrigger')
25+
if (buttonB?.click) {
26+
buttonB.click()
27+
}}
28+
"
29+
/>
2030
</>
2131
)
2232
}

src/molecules/UserWay/UserWay.tsx

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,13 @@
11
import { Box } from '@chakra-ui/react'
2-
import { useEffect, useState } from 'react'
32

43
import { Accessibility } from '@/atoms/Icons/Accessibility'
54
import { vars } from '@theme'
65

7-
declare global {
8-
interface Window {
9-
UserWay: {
10-
widgetOpen: () => void
11-
}
12-
}
13-
}
14-
15-
interface IUserWay {
16-
color?: string
17-
}
18-
19-
const waitForUserWay = async (): Promise<void> => {
20-
return await new Promise((resolve, reject) => {
21-
const checkUserWay = (): void => {
22-
if (window.UserWay) {
23-
resolve() // Resuelve cuando UserWay está disponible
24-
} else {
25-
requestAnimationFrame(checkUserWay) // Sigue esperando
26-
}
27-
}
28-
29-
try {
30-
checkUserWay() // Inicia la verificación
31-
} catch (error) {
32-
reject(new Error('UserWay script failed to load'))
33-
}
34-
})
35-
}
36-
37-
export function UserWay({ color = '#0189FF' }: IUserWay): JSX.Element {
38-
const [isUserWayReady, setIsUserWayReady] = useState(false)
39-
40-
useEffect(() => {
41-
// Cargar el script de UserWay
42-
if (!document.getElementById('userway-script')) {
43-
const script = document.createElement('script')
44-
script.id = 'userway-script'
45-
script.src = 'https://cdn.userway.org/widget.js'
46-
script.async = true
47-
script.setAttribute('data-account', '06mvMZzmO4')
48-
script.setAttribute('data-color', color)
49-
script.setAttribute('data-trigger', 'customTrigger')
50-
document.body.appendChild(script)
51-
}
52-
53-
// Esperar a que el script esté listo
54-
waitForUserWay()
55-
.then(() => {
56-
setIsUserWayReady(true)
57-
return undefined
58-
})
59-
.catch((error) => {
60-
console.error('Failed to load UserWay:', error)
61-
})
62-
}, [color])
63-
64-
const handleButtonClick = (): void => {
65-
if (isUserWayReady && window?.UserWay?.widgetOpen) {
66-
window.UserWay.widgetOpen() // Abrir el menú
67-
} else {
68-
console.error('UserWay script not loaded yet.')
6+
export function UserWay(): JSX.Element {
7+
const triggerWidget = (): void => {
8+
const buttonB = document.getElementById('userWayTrigger')
9+
if (buttonB?.click) {
10+
buttonB.click() // Hace clic en el botón del archivo index.html
6911
}
7012
}
7113

@@ -78,13 +20,14 @@ export function UserWay({ color = '#0189FF' }: IUserWay): JSX.Element {
7820
border="1px solid transparent"
7921
display="flex"
8022
height="30px"
81-
id="customTrigger"
23+
id="UserWayButton"
8224
justifyContent="center"
83-
onClick={handleButtonClick}
25+
padding="0 8px"
8426
width="30px"
8527
_hover={{
8628
background: 'rgba(96, 121, 142, 0.8)',
8729
}}
30+
onClick={triggerWidget}
8831
>
8932
<Accessibility />
9033
</Box>

0 commit comments

Comments
 (0)