Skip to content

Commit bc400d6

Browse files
committed
update FeedbackCard, implement useSurvey + matomo
1 parent 8919535 commit bc400d6

File tree

2 files changed

+41
-39
lines changed

2 files changed

+41
-39
lines changed

src/components/FeedbackCard.tsx

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
1-
import React, { ReactNode, useState } from "react"
1+
import { type ReactNode, useState } from "react"
22
import { useRouter } from "next/router"
33
import { useTranslation } from "next-i18next"
4-
import { Flex, FlexProps, Heading } from "@chakra-ui/react"
4+
import { Flex, type FlexProps, Heading } from "@chakra-ui/react"
55

6-
import { Button } from "./Buttons"
7-
import { FeedbackThumbsUpIcon } from "./icons"
6+
import { Button } from "@/components/Buttons"
7+
import { FeedbackThumbsUpIcon } from "@/components/icons"
8+
import Link from "@/components/Link"
89

9-
// TODO: add trackCustomEvent when util is migrated
10-
// import { trackCustomEvent } from "../utils/matomo"
10+
import { trackCustomEvent } from "@/lib/utils/matomo"
1111

12-
// TODO: add useSurvey after hook is migrated
13-
// import { useSurvey } from "../hooks/useSurvey"
12+
import { useSurvey } from "@/hooks/useSurvey"
1413

15-
export interface IProps extends FlexProps {
14+
type FeedbackCardProps = FlexProps & {
1615
prompt?: string
1716
isArticle?: boolean
1817
}
1918

20-
const FeedbackCard: React.FC<IProps> = ({
21-
prompt,
22-
isArticle = false,
23-
...props
24-
}) => {
19+
const FeedbackCard = ({ prompt, isArticle, ...props }: FeedbackCardProps) => {
2520
const { t } = useTranslation("common")
2621
const [feedbackSubmitted, setFeedbackSubmitted] = useState(false)
27-
// const surveyUrl = useSurvey(feedbackSubmitted)
22+
const surveyUrl = useSurvey(feedbackSubmitted)
2823
const { asPath } = useRouter()
2924

3025
const isTutorial = asPath?.includes("tutorials")
3126

3227
const getTitle = (feedbackSubmitted: boolean): ReactNode => {
3328
if (!feedbackSubmitted) {
3429
if (prompt) return prompt
35-
3630
if (isTutorial) return t("feedback-card-prompt-tutorial")
3731
if (isArticle) return t("feedback-card-prompt-article")
3832

@@ -43,23 +37,21 @@ const FeedbackCard: React.FC<IProps> = ({
4337
}
4438

4539
const handleSubmit = (choice: boolean): void => {
46-
// TODO: add trackCustomEvent when util is migrated
47-
// trackCustomEvent({
48-
// eventCategory: `Page is helpful feedback`,
49-
// eventAction: `Clicked`,
50-
// eventName: String(choice),
51-
// })
40+
trackCustomEvent({
41+
eventCategory: `Page is helpful feedback`,
42+
eventAction: `Clicked`,
43+
eventName: String(choice),
44+
})
5245
setFeedbackSubmitted(true)
5346
}
5447

5548
const handleSurveyOpen = (): void => {
56-
// TODO: add trackCustomEvent when util is migrated
57-
// trackCustomEvent({
58-
// eventCategory: `Feedback survey opened`,
59-
// eventAction: `Clicked`,
60-
// eventName: "Feedback survey opened",
61-
// })
62-
// window && surveyUrl && window.open(surveyUrl, "_blank")
49+
trackCustomEvent({
50+
eventCategory: `Feedback survey opened`,
51+
eventAction: `Clicked`,
52+
eventName: "Feedback survey opened",
53+
})
54+
window && surveyUrl && window.open(surveyUrl, "_blank")
6355
}
6456

6557
return (
@@ -68,28 +60,25 @@ const FeedbackCard: React.FC<IProps> = ({
6860
borderColor="border"
6961
bg="feedbackGradient"
7062
borderRadius="base"
71-
p={6}
63+
p="6"
7264
direction="column"
73-
mb={4}
74-
mt={8}
65+
mb="4"
66+
mt="8"
7567
w="full"
7668
{...props}
7769
>
78-
<Flex direction="column" gap={4}>
79-
<Heading as="h3" m={0} mb={2} fontSize="1.375rem" fontWeight="bold">
70+
<Flex direction="column" gap="4">
71+
<Heading as="h3" m="0" mb="2" fontSize="1.375rem" fontWeight="bold">
8072
{getTitle(feedbackSubmitted)}
8173
</Heading>
8274
{feedbackSubmitted && (
8375
<p>
8476
{t("feedback-widget-thank-you-subtitle")}{" "}
8577
{t("feedback-widget-thank-you-subtitle-ext")}{" "}
86-
<a href="https://discord.gg/rZz26QWfCg\" target="_blank\">
87-
Discord
88-
</a>
89-
.
78+
<Link href="/discord/">Discord</Link>.
9079
</p>
9180
)}
92-
<Flex gap={4}>
81+
<Flex gap="4">
9382
{!feedbackSubmitted ? (
9483
<>
9584
<Button

src/hooks/useSurvey.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useMemo } from "react"
2+
import { useRouter } from "next/router"
3+
4+
import { SITE_URL } from "@/lib/constants"
5+
6+
export const useSurvey = (feedbackSubmitted: boolean) => {
7+
const { asPath } = useRouter()
8+
const url = SITE_URL + asPath
9+
return useMemo((): string | null => {
10+
if (!feedbackSubmitted) return null
11+
return `https://iwokuhuz.paperform.co//?url=${url}`
12+
}, [feedbackSubmitted, url])
13+
}

0 commit comments

Comments
 (0)