Skip to content

Commit 072a6dc

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

File tree

3 files changed

+62
-26
lines changed

3 files changed

+62
-26
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: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,75 @@ 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

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+
}
3972

4073
return (
4174
<>
4275
<Button
4376
color="tertiary"
4477
icon={<Icon name="info" />}
4578
className="c__feedback__button"
46-
onClick={modal.open}
79+
onClick={onClick}
4780
{...props.buttonProps}
4881
>
4982
{t("feedback.button")}
@@ -57,7 +90,7 @@ export const Feedback = (props: { buttonProps?: Partial<ButtonProps> }) => {
5790
{t("feedback.modal.description")}
5891
</p>
5992
<div className="c__feedback__modal__buttons">
60-
{FEEDBACK_BUTTONS.map((button) => (
93+
{FEEDBACK_BUTTONS.filter((button) => !!button.href).map((button) => (
6194
<FeedbackButton
6295
key={button.title}
6396
{...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)