@@ -8,42 +8,75 @@ import {
8
8
} from "@openfun/cunningham-react" ;
9
9
import React , { useMemo } from "react" ;
10
10
import { useTranslation } from "react-i18next" ;
11
+ import { useApiConfig } from "../config/useApiConfig" ;
11
12
12
13
export const Feedback = ( props : { buttonProps ?: Partial < ButtonProps > } ) => {
13
14
const { t } = useTranslation ( ) ;
14
15
const modal = useModal ( ) ;
16
+ const { data : config } = useApiConfig ( ) ;
15
17
16
- const FEEDBACK_BUTTONS = useMemo (
17
- ( ) => [
18
- {
19
- icon : < FormIcon /> ,
20
- title : "feedback.modal.buttons.form.title" ,
21
- description : "feedback.modal.buttons.form.description" ,
22
- href : process . env . NEXT_PUBLIC_ALPHA_FEEDBACK_FORM ,
23
- } ,
24
- {
25
- icon : < TchapIcon /> ,
26
- title : "feedback.modal.buttons.tchap.title" ,
27
- description : "feedback.modal.buttons.tchap.description" ,
28
- href : process . env . NEXT_PUBLIC_ALPHA_FEEDBACK_TCHAP ,
29
- } ,
30
- {
31
- icon : < VisioIcon /> ,
32
- title : "feedback.modal.buttons.visio.title" ,
33
- description : "feedback.modal.buttons.visio.description" ,
34
- href : process . env . NEXT_PUBLIC_ALPHA_FEEDBACK_VISIO ,
35
- } ,
36
- ] ,
37
- [ ]
38
- ) ;
18
+ const FEEDBACK_BUTTONS = useMemo ( ( ) => {
19
+ return config ?. FRONTEND_FEEDBACK_ITEMS
20
+ ? Object . entries ( config . FRONTEND_FEEDBACK_ITEMS ) . map ( ( [ key , value ] ) => {
21
+ let Icon : React . ReactElement ;
22
+ switch ( key ) {
23
+ case "form" :
24
+ Icon = < FormIcon /> ;
25
+ break ;
26
+ case "tchap" :
27
+ Icon = < TchapIcon /> ;
28
+ break ;
29
+ case "visio" :
30
+ Icon = < VisioIcon /> ;
31
+ break ;
32
+ default :
33
+ Icon = < FormIcon /> ;
34
+ break ;
35
+ }
36
+ return {
37
+ icon : Icon ,
38
+ title : `feedback.modal.buttons.${ key } .title` ,
39
+ description : `feedback.modal.buttons.${ key } .description` ,
40
+ href : value . url ,
41
+ } ;
42
+ } )
43
+ : [ ] ;
44
+ } , [ ] ) ;
45
+
46
+ const showFeedbackButton = ( ) => {
47
+ if ( ! config ?. FRONTEND_FEEDBACK_BUTTON_SHOW ) {
48
+ return false ;
49
+ }
50
+
51
+ // For idle mode, there is no feedback buttons displayed as the modal will never show up,
52
+ // so we show the button even if there is no href.
53
+ if (
54
+ ! config ?. FRONTEND_FEEDBACK_BUTTON_IDLE &&
55
+ FEEDBACK_BUTTONS . filter ( ( button ) => ! ! button . href ) . length === 0
56
+ ) {
57
+ return false ;
58
+ }
59
+ return true ;
60
+ } ;
61
+
62
+ const onClick = ( ) => {
63
+ if ( config ?. FRONTEND_FEEDBACK_BUTTON_IDLE ) {
64
+ return ;
65
+ }
66
+ modal . open ( ) ;
67
+ } ;
68
+
69
+ if ( ! showFeedbackButton ( ) ) {
70
+ return null ;
71
+ }
39
72
40
73
return (
41
74
< >
42
75
< Button
43
76
color = "tertiary"
44
77
icon = { < Icon name = "info" /> }
45
78
className = "c__feedback__button"
46
- onClick = { modal . open }
79
+ onClick = { onClick }
47
80
{ ...props . buttonProps }
48
81
>
49
82
{ t ( "feedback.button" ) }
@@ -57,7 +90,7 @@ export const Feedback = (props: { buttonProps?: Partial<ButtonProps> }) => {
57
90
{ t ( "feedback.modal.description" ) }
58
91
</ p >
59
92
< div className = "c__feedback__modal__buttons" >
60
- { FEEDBACK_BUTTONS . map ( ( button ) => (
93
+ { FEEDBACK_BUTTONS . filter ( ( button ) => ! ! button . href ) . map ( ( button ) => (
61
94
< FeedbackButton
62
95
key = { button . title }
63
96
{ ...button }
0 commit comments