Skip to content

Commit

Permalink
feat: redesign doc feedback UI (#447)
Browse files Browse the repository at this point in the history
* feat(components): add new feedback section types

* feat(feedback): add hubspot form tracking

* feat(feedback): provide feedback section UI

* feat(locale): add new feedback i18n

* feat: add new feedback section to doc template

* refactor: remove legacy feedback button from doc template

* fix(feedback): fix skip behavior

* refine(feedback): improve styles

* refine(template): enable JP feedback

* fix(feedback): fix styles

* refine(feedback): improve typography styles

* refine(locale/ja): improve translation

* refine(locale/ja): improve feedback translation

* refine(locale/en): improve feedback translation
  • Loading branch information
Yuiham authored Nov 15, 2023
1 parent 9d3fa91 commit 8f6634d
Show file tree
Hide file tree
Showing 10 changed files with 561 additions and 18 deletions.
6 changes: 6 additions & 0 deletions gatsby/create-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export const createDocs = async ({
version: versionRecord[pathConfig.locale][pathConfig.repo][name],
},
buildType: (process.env.WEBSITE_BUILD_TYPE ?? "prod") as BuildType, // prod | archive, default is prod; archive is for archive site
feature: {
feedback: true
}
},
});

Expand Down Expand Up @@ -257,6 +260,9 @@ export const createDocHome = async ({
version: [],
},
buildType: (process.env.WEBSITE_BUILD_TYPE ?? "prod") as BuildType,
feature: {
feedback: false
}
},
});
});
Expand Down
24 changes: 24 additions & 0 deletions locale/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,30 @@
"thumbUp": "Yes",
"thumbDown": "No"
},
"docFeedbackSurvey": {
"action": {
"submit": "Submit",
"skip": "Skip"
},
"message": {
"thank": "Thank you for your valuable feedback!"
},
"positive": {
"title": "Thanks! What did you like?",
"easy": "Easy to understand",
"solvedProblem": "Solved my problem",
"helpToDecide": "Helped me decide to use the product",
"other": "Others"
},
"negative": {
"title": "What went wrong?",
"hard": "Hard to understand",
"nothingFound": "Couldn't find what I need",
"inaccurate": "Inaccurate or out of date",
"sampleError": "Code sample errors",
"other": "Others"
}
},
"doc404": {
"title": "Sorry, we can't find the page you were looking for.",
"youMayWish": "You may wish to:",
Expand Down
24 changes: 24 additions & 0 deletions locale/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,30 @@
"thumbUp": "はい",
"thumbDown": "いいえ"
},
"docFeedbackSurvey": {
"action": {
"submit": "送信",
"skip": "スキップ"
},
"message": {
"thank": "貴重なご意見をありがとうございます!"
},
"positive": {
"title": "ありがとうございます!ドキュメントサイト改善のため、フィードバックをお願いします。",
"easy": "理解しやすい",
"solvedProblem": "問題を解決できた",
"helpToDecide": "製品使用を決断するのに役立った",
"other": "その他"
},
"negative": {
"title": "ドキュメントサイト改善のため、フィードバックをお願いします。",
"hard": "分かりづらい",
"nothingFound": "必要なものが見つからなかった",
"inaccurate": "不正確または古い情報だった",
"sampleError": "コードサンプルがエラーだった",
"other": "その他"
}
},
"doc404": {
"title": "お探しのページが見つかりません。",
"youMayWish": "You may wish to:",
Expand Down
24 changes: 24 additions & 0 deletions locale/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@
"thumbUp": "",
"thumbDown": ""
},
"docFeedbackSurvey": {
"action": {
"submit": "提交",
"skip": "跳过"
},
"message": {
"thank": "感谢您的宝贵意见!"
},
"positive": {
"title": "谢谢!您喜欢文档的原因是?",
"easy": "容易理解",
"solvedProblem": "解决了我的问题",
"helpToDecide": "帮助我决定使用该产品",
"other": "其他原因"
},
"negative": {
"title": "您不喜欢文档的原因是?",
"hard": "难以理解",
"nothingFound": "找不到我想要的信息",
"inaccurate": "内容不准确或过时",
"sampleError": "代码示例错误",
"other": "其他原因"
}
},
"doc404": {
"title": "抱歉,您要找的页面走丢了…",
"youMayWish": "您可以:",
Expand Down
273 changes: 273 additions & 0 deletions src/components/Card/FeedbackSection/FeedbackSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
import { Trans } from "gatsby-plugin-react-i18next";
import {
Box,
Stack,
Typography,
FormControl,
RadioGroup,
Radio,
FormControlLabel,
} from "@mui/material";
import { ThumbUpOutlined, ThumbDownOutlined } from "@mui/icons-material";
import { Locale } from "static/Type";
import { useState } from "react";
import { trackCustomEvent } from "gatsby-plugin-google-analytics";
import { submitFeedbackDetail, submitLiteFeedback } from "./tracking";
import { FeedbackCategory } from "./types";
import {
ActionButton,
controlLabelSx,
labelProps,
radioSx,
ThumbButton,
typoFontFamily,
} from "./components";

interface FeedbackSectionProps {
title: string;
locale: Locale;
}

export function FeedbackSection({ title, locale }: FeedbackSectionProps) {
const [thumbVisible, setThumbVisible] = useState(true);
const [helpful, setHelpful] = useState<boolean>();
const [surveyVisible, setSurverVisible] = useState(false);

const onThumbClick = (helpful: boolean) => {
trackCustomEvent({
category: helpful ? `doc-${locale}-useful` : `doc-${locale}-useless`,
action: "click",
label: title,
transport: "beacon",
});
submitLiteFeedback({
locale,
category: helpful ? FeedbackCategory.Positive : FeedbackCategory.Negative
})

setHelpful(helpful);
setThumbVisible(false);
setSurverVisible(true);
};

const [positiveVal, setPositiveVal] = useState<string>("");
const onPositiveChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setPositiveVal((event.target as HTMLInputElement).value);
};

const [negativeVal, setNegativeVal] = useState<string>("");
const onNegativeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setNegativeVal((event.target as HTMLInputElement).value);
};

const [submitted, setSubmitted] = useState(false);

const onPositiveSubmit = () => {
submitFeedbackDetail({
locale,
category: FeedbackCategory.Positive,
reason: positiveVal,
});
setSurverVisible(false);
setSubmitted(true);
};
const onNegativeSubmit = () => {
submitFeedbackDetail({
locale,
category: FeedbackCategory.Negative,
reason: negativeVal,
});
setSurverVisible(false);
setSubmitted(true);
};

const onSkip = () => {
setSurverVisible(false);
setPositiveVal("");
setNegativeVal("");
setSubmitted(true);
};

return (
<Box px="1.5rem">
<Typography
variant="h2"
sx={{
color: "website.f1",
fontSize: "1.5rem",
fontWeight: 600,
fontFamily: typoFontFamily,
lineHeight: 1.25,
marginTop: "24px",
marginBottom: "16px",
paddingBottom: "0.3em",
borderBottom: "1px solid #d8dee4",
}}
>
<Trans i18nKey="docHelpful.header" />
</Typography>
{thumbVisible && (
<Stack direction="row" spacing={2} mb="48px">
<ThumbButton
variant="contained"
size="small"
startIcon={<ThumbUpOutlined sx={{ width: 14, height: 14 }} />}
className="FeedbackBtn-thumbUp"
aria-label="Thumb Up"
onClick={() => onThumbClick(true)}
>
<Trans i18nKey="docHelpful.thumbUp" />
</ThumbButton>
<ThumbButton
variant="contained"
size="small"
startIcon={<ThumbDownOutlined sx={{ width: 14, height: 14 }} />}
className="FeedbackBtn-thumbDown"
aria-label="Thumb Down"
onClick={() => onThumbClick(false)}
>
<Trans i18nKey="docHelpful.thumbDown" />
</ThumbButton>
</Stack>
)}
{surveyVisible && helpful && (
<Box>
<FormControl>
<Typography variant="body1" color="website.f1" fontWeight={500} fontFamily={typoFontFamily}>
<Trans i18nKey="docFeedbackSurvey.positive.title" />
</Typography>
<RadioGroup
aria-labelledby="doc-positive-feedback-survey"
name="doc-positive-feedback-survey-radio-group"
value={positiveVal}
onChange={onPositiveChange}
sx={{ my: "6px" }}
>
<FormControlLabel
value="easy"
label={<Trans i18nKey="docFeedbackSurvey.positive.easy" />}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
<FormControlLabel
value="solvedProblem"
label={
<Trans i18nKey="docFeedbackSurvey.positive.solvedProblem" />
}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
<FormControlLabel
value="helpToDecide"
label={
<Trans i18nKey="docFeedbackSurvey.positive.helpToDecide" />
}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
<FormControlLabel
value="other"
label={<Trans i18nKey="docFeedbackSurvey.positive.other" />}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
</RadioGroup>
</FormControl>
<Stack direction="row" spacing={2} mt="12px" mb="24px">
<ActionButton
variant="outlined"
size="small"
disabled={!positiveVal}
onClick={onPositiveSubmit}
>
<Trans i18nKey="docFeedbackSurvey.action.submit" />
</ActionButton>
<ActionButton variant="outlined" size="small" onClick={onSkip}>
<Trans i18nKey="docFeedbackSurvey.action.skip" />
</ActionButton>
</Stack>
</Box>
)}
{surveyVisible && !helpful && (
<Box>
<FormControl>
<Typography variant="body1" color="website.f1" fontWeight={500} fontFamily={typoFontFamily}>
<Trans i18nKey="docFeedbackSurvey.negative.title" />
</Typography>
<RadioGroup
aria-labelledby="doc-negative-feedback-survey"
name="doc-negative-feedback-survey-radio-group"
value={negativeVal}
onChange={onNegativeChange}
sx={{ my: "6px" }}
>
<FormControlLabel
value="hard"
label={<Trans i18nKey="docFeedbackSurvey.negative.hard" />}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
<FormControlLabel
value="nothingFound"
label={
<Trans i18nKey="docFeedbackSurvey.negative.nothingFound" />
}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
<FormControlLabel
value="inaccurate"
label={
<Trans i18nKey="docFeedbackSurvey.negative.inaccurate" />
}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
<FormControlLabel
value="sampleError"
label={
<Trans i18nKey="docFeedbackSurvey.negative.sampleError" />
}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
<FormControlLabel
value="other"
label={<Trans i18nKey="docFeedbackSurvey.negative.other" />}
control={<Radio size="small" sx={radioSx} />}
componentsProps={labelProps}
sx={controlLabelSx}
/>
</RadioGroup>
</FormControl>
<Stack direction="row" spacing={2} mt="12px" mb="24px">
<ActionButton
variant="outlined"
size="small"
disabled={!negativeVal}
onClick={onNegativeSubmit}
>
<Trans i18nKey="docFeedbackSurvey.action.submit" />
</ActionButton>
<ActionButton variant="outlined" size="small" onClick={onSkip}>
<Trans i18nKey="docFeedbackSurvey.action.skip" />
</ActionButton>
</Stack>
</Box>
)}
{submitted && (
<Typography variant="body1" color="website.f1" fontWeight={500} fontFamily={typoFontFamily} mb="48px">
<Trans i18nKey="docFeedbackSurvey.message.thank" />
</Typography>
)}
</Box>
);
}
Loading

0 comments on commit 8f6634d

Please sign in to comment.