Skip to content

Commit bedbbf9

Browse files
committed
✨(front) add customization to feedbacks
Let's implement the freshly added envvar to the feedback feature.
1 parent 777a917 commit bedbbf9

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to
1212

1313
- ✨(front) add move modal #213
1414
- ✨(front) update the homepage to alpha #234
15+
- ✨(global) add customization to feedbacks
1516

1617
## Changed
1718

src/frontend/apps/drive/src/features/feedback/Feedback.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,69 @@ import {
88
} from "@openfun/cunningham-react";
99
import React, { useMemo } from "react";
1010
import { useTranslation } from "react-i18next";
11+
import { useApiConfig } from "../config/useApiConfig";
1112

1213
export const Feedback = (props: { buttonProps?: Partial<ButtonProps> }) => {
1314
const { t } = useTranslation();
1415
const modal = useModal();
16+
const { data: config } = useApiConfig();
1517

1618
const FEEDBACK_BUTTONS = useMemo(
1719
() => [
1820
{
1921
icon: <FormIcon />,
2022
title: "feedback.modal.buttons.form.title",
2123
description: "feedback.modal.buttons.form.description",
22-
href: process.env.NEXT_PUBLIC_ALPHA_FEEDBACK_FORM,
24+
href: config?.FRONTEND_FEEDBACK_FORM_URL,
2325
},
2426
{
2527
icon: <TchapIcon />,
2628
title: "feedback.modal.buttons.tchap.title",
2729
description: "feedback.modal.buttons.tchap.description",
28-
href: process.env.NEXT_PUBLIC_ALPHA_FEEDBACK_TCHAP,
30+
href: config?.FRONTEND_FEEDBACK_TCHAP_URL,
2931
},
3032
{
3133
icon: <VisioIcon />,
3234
title: "feedback.modal.buttons.visio.title",
3335
description: "feedback.modal.buttons.visio.description",
34-
href: process.env.NEXT_PUBLIC_ALPHA_FEEDBACK_VISIO,
36+
href: config?.FRONTEND_FEEDBACK_VISIO_URL,
3537
},
3638
],
3739
[]
3840
);
3941

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+
4062
return (
4163
<>
4264
<Button
4365
color="tertiary"
4466
icon={<Icon name="info" />}
4567
className="c__feedback__button"
46-
onClick={modal.open}
68+
onClick={() => {
69+
if (config?.FRONTEND_FEEDBACK_BUTTON_IDLE) {
70+
return;
71+
}
72+
modal.open();
73+
}}
4774
{...props.buttonProps}
4875
>
4976
{t("feedback.button")}
@@ -57,7 +84,7 @@ export const Feedback = (props: { buttonProps?: Partial<ButtonProps> }) => {
5784
{t("feedback.modal.description")}
5885
</p>
5986
<div className="c__feedback__modal__buttons">
60-
{FEEDBACK_BUTTONS.map((button) => (
87+
{FEEDBACK_BUTTONS.filter((button) => !!button.href).map((button) => (
6188
<FeedbackButton
6289
key={button.title}
6390
{...button}

src/frontend/apps/drive/src/pages/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import {
2727
} from "@/features/ui/components/toaster/Toaster";
2828
import { Button } from "@openfun/cunningham-react";
2929
import { Feedback } from "@/features/feedback/Feedback";
30+
import { useApiConfig } from "@/features/config/useApiConfig";
3031
export default function HomePage() {
3132
const { t } = useTranslation();
3233
const { user } = useAuth();
34+
const { data: config } = useApiConfig();
3335

3436
useEffect(() => {
3537
if (user) {
@@ -88,7 +90,7 @@ export default function HomePage() {
8890
color="secondary"
8991
icon={<Icon name="info" type={IconType.OUTLINED} />}
9092
fullWidth
91-
href={process.env.NEXT_PUBLIC_ALPHA_MORE}
93+
href={config?.FRONTEND_MORE_LINK}
9294
target="_blank"
9395
>
9496
{t("home.more")}

0 commit comments

Comments
 (0)