@@ -8,42 +8,69 @@ 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
18
const FEEDBACK_BUTTONS = useMemo (
17
19
( ) => [
18
20
{
19
21
icon : < FormIcon /> ,
20
22
title : "feedback.modal.buttons.form.title" ,
21
23
description : "feedback.modal.buttons.form.description" ,
22
- href : process . env . NEXT_PUBLIC_ALPHA_FEEDBACK_FORM ,
24
+ href : config ?. FRONTEND_FEEDBACK_FORM_URL ,
23
25
} ,
24
26
{
25
27
icon : < TchapIcon /> ,
26
28
title : "feedback.modal.buttons.tchap.title" ,
27
29
description : "feedback.modal.buttons.tchap.description" ,
28
- href : process . env . NEXT_PUBLIC_ALPHA_FEEDBACK_TCHAP ,
30
+ href : config ?. FRONTEND_FEEDBACK_TCHAP_URL ,
29
31
} ,
30
32
{
31
33
icon : < VisioIcon /> ,
32
34
title : "feedback.modal.buttons.visio.title" ,
33
35
description : "feedback.modal.buttons.visio.description" ,
34
- href : process . env . NEXT_PUBLIC_ALPHA_FEEDBACK_VISIO ,
36
+ href : config ?. FRONTEND_FEEDBACK_VISIO_URL ,
35
37
} ,
36
38
] ,
37
39
[ ]
38
40
) ;
39
41
42
+ const showFeedbackButton = ( ) => {
43
+ if ( ! config ?. FRONTEND_FEEDBACK_BUTTON_SHOW ) {
44
+ return false ;
45
+ }
46
+
47
+ // For idle mode, there is no feedback buttons displayed as the modal will never show up,
48
+ // so we show the button even if there is no href.
49
+ if (
50
+ ! config ?. FRONTEND_FEEDBACK_BUTTON_IDLE &&
51
+ FEEDBACK_BUTTONS . filter ( ( button ) => ! ! button . href ) . length === 0
52
+ ) {
53
+ return false ;
54
+ }
55
+ return true ;
56
+ } ;
57
+
58
+ if ( ! showFeedbackButton ( ) ) {
59
+ return null ;
60
+ }
61
+
40
62
return (
41
63
< >
42
64
< Button
43
65
color = "tertiary"
44
66
icon = { < Icon name = "info" /> }
45
67
className = "c__feedback__button"
46
- onClick = { modal . open }
68
+ onClick = { ( ) => {
69
+ if ( config ?. FRONTEND_FEEDBACK_BUTTON_IDLE ) {
70
+ return ;
71
+ }
72
+ modal . open ( ) ;
73
+ } }
47
74
{ ...props . buttonProps }
48
75
>
49
76
{ t ( "feedback.button" ) }
@@ -57,7 +84,7 @@ export const Feedback = (props: { buttonProps?: Partial<ButtonProps> }) => {
57
84
{ t ( "feedback.modal.description" ) }
58
85
</ p >
59
86
< div className = "c__feedback__modal__buttons" >
60
- { FEEDBACK_BUTTONS . map ( ( button ) => (
87
+ { FEEDBACK_BUTTONS . filter ( ( button ) => ! ! button . href ) . map ( ( button ) => (
61
88
< FeedbackButton
62
89
key = { button . title }
63
90
{ ...button }
0 commit comments