Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Send feedback directly to a dedicated slack channel #34196

Merged
merged 8 commits into from Sep 26, 2022
62 changes: 62 additions & 0 deletions docs/src/modules/components/AppLayoutDocsFooter.js
Expand Up @@ -108,6 +108,67 @@ async function postFeedback(data) {
}
}

async function postFeedbackOnSlack(data) {
const { rating, comment, version, language } = data;

if (!comment || comment.length < 10) {
return;
}

const env = window.location.host.indexOf('mui.com') !== -1 ? 'prod' : 'dev';

if (env === 'dev') {
// return;
}

const slackMessage = {
blocks: [
{
type: 'header',
text: {
type: 'plain_text',
text: `New comment ${rating > 0 ? '👍' : '👎'}`,
emoji: true,
},
},
{
type: 'section',
text: {
type: 'plain_text',
text: comment,
emoji: true,
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `v: ${version}, lang: ${language}`,
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: 'Go to the page',
emoji: true,
},
url: window.location.host,
},
},
],
};
try {
await fetch(`https://hooks.slack.com/services/${process.env.SLACK_FEEDBACKS_TOKEN}`, {
method: 'POST',
referrerPolicy: 'origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(slackMessage),
});
} catch (error) {
console.error(error);
}
}

async function getUserFeedback(id) {
const env = location.hostname === 'mui.com' ? 'prod' : 'dev';
const URL = `${process.env.FEEDBACK_URL}/${env}/feedback/${id}`;
Expand Down Expand Up @@ -135,6 +196,7 @@ async function submitFeedback(page, rating, comment, language) {
language,
};

await postFeedbackOnSlack(data);
const result = await postFeedback(data);
if (result) {
document.cookie = `feedbackId=${result.id};path=/;max-age=31536000`;
Expand Down