-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: show survey card on Home page (#8078)
* add custom style * Update Publish.tsx * display card on Home page * Update constants.tsx * Update shell.ts * Update Home.tsx * move survey into separate component * get more info automatically * move URL into constant * move more props around * Update constants.tsx * turn non-rendering component into hook * move card to design page * start adding ipcRenderer stuff * update card design * get machineID and stash in Recoil * read OS and place in URL * add spacer to notification card * better notification styling * fix constants and typercheck error
- Loading branch information
Showing
15 changed files
with
195 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
Composer/packages/client/src/components/Notifications/SurveyNotification.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { useEffect } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { ClientStorage } from '../../utils/storage'; | ||
import { surveyEligibilityState, dispatcherState, machineInfoState } from '../../recoilModel/atoms/appState'; | ||
import { MachineInfo } from '../../recoilModel/types'; | ||
import { SURVEY_URL_BASE } from '../../constants'; | ||
import TelemetryClient from '../../telemetry/TelemetryClient'; | ||
|
||
function buildUrl(info: MachineInfo) { | ||
// User OS | ||
// hashed machineId | ||
// composer version | ||
// maybe include subscription ID; wait for global sign-in feature | ||
// session ID (global telemetry GUID) | ||
const version = process.env.COMPOSER_VERSION; | ||
|
||
const parameters = { | ||
Source: 'Composer', | ||
os: info.os || 'Unknown', | ||
machineId: info.id, | ||
version, | ||
}; | ||
|
||
return ( | ||
`${SURVEY_URL_BASE}?` + | ||
Object.keys(parameters) | ||
.map((key) => `${key}=${parameters[key]}`) | ||
.join('&') | ||
); | ||
} | ||
|
||
export function useSurveyNotification() { | ||
const { addNotification, deleteNotification } = useRecoilValue(dispatcherState); | ||
const surveyEligible = useRecoilValue(surveyEligibilityState); | ||
const machineInfo = useRecoilValue(machineInfoState); | ||
|
||
useEffect(() => { | ||
const url = buildUrl(machineInfo); | ||
deleteNotification('survey'); | ||
|
||
if (surveyEligible) { | ||
const surveyStorage = new ClientStorage(window.localStorage, 'survey'); | ||
TelemetryClient.track('HATSSurveyOffered'); | ||
|
||
addNotification({ | ||
id: 'survey', | ||
type: 'question', | ||
title: 'Would you mind taking a quick survey?', | ||
description: `We read every response and will use your feedback to improve Composer.`, | ||
stretchLinks: true, | ||
links: [ | ||
{ | ||
label: 'Take survey', | ||
onClick: () => { | ||
// This is safe; we control what the URL that gets built is | ||
// eslint-disable-next-line security/detect-non-literal-fs-filename | ||
window.open(url, '_blank'); | ||
TelemetryClient.track('HATSSurveyAccepted'); | ||
deleteNotification('survey'); | ||
}, | ||
}, | ||
|
||
{ | ||
// this is functionally identical to clicking the close box | ||
label: 'Remind me later', | ||
onClick: () => { | ||
TelemetryClient.track('HATSSurveyDismissed'); | ||
deleteNotification('survey'); | ||
}, | ||
}, | ||
null, | ||
{ | ||
label: 'No thanks', | ||
onClick: () => { | ||
TelemetryClient.track('HATSSurveyRejected'); | ||
deleteNotification('survey'); | ||
surveyStorage.set('optedOut', true); | ||
}, | ||
}, | ||
], | ||
}); | ||
} | ||
}, []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.