Remove localStorage for NPS (#1733)

* Remove localStorage for NPS

* Run npm format

* Update comment
This commit is contained in:
sindhuba 2024-02-06 09:54:50 -08:00 committed by GitHub
parent 2d06eef9cc
commit 6d98b4a500
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 50 deletions

View File

@ -265,80 +265,37 @@ export default class Explorer {
// TODO: return result
}
private getRandomInt(max: number) {
return Math.floor(Math.random() * max);
}
public openNPSSurveyDialog(): void {
if (!Platform.Portal) {
return;
}
const NINETY_DAYS_IN_MS = 7776000000;
const ONE_DAY_IN_MS = 86400000;
const THREE_DAYS_IN_MS = 259200000;
const lastSubmitted: string = localStorage.getItem("lastSubmitted");
Logger.logInfo(`NPS Survey last shown date: ${lastSubmitted}`, "Explorer/openNPSSurveyDialog");
if (lastSubmitted !== null) {
Logger.logInfo(`NPS Survey last shown is not empty ${lastSubmitted}`, "Explorer/openNPSSurveyDialog");
let lastSubmittedDate: number = parseInt(lastSubmitted);
Logger.logInfo(`NPS Survey last shown is parsed ${lastSubmittedDate.toString()}`, "Explorer/openNPSSurveyDialog");
if (isNaN(lastSubmittedDate)) {
Logger.logInfo(
`NPS Survey last shown is not a number ${lastSubmittedDate.toString()}`,
"Explorer/openNPSSurveyDialog",
);
lastSubmittedDate = 0;
}
const nowMs: number = Date.now();
Logger.logInfo(`NPS Survey current date ${nowMs.toString()}`, "Explorer/openNPSSurveyDialog");
const millisecsSinceLastSubmitted = nowMs - lastSubmittedDate;
if (millisecsSinceLastSubmitted < NINETY_DAYS_IN_MS) {
Logger.logInfo(
`NPS Survey last shown is less than ninety days ${millisecsSinceLastSubmitted.toString()}`,
"Explorer/openNPSSurveyDialog",
);
return;
}
}
const SEVEN_DAYS_IN_MS = 604800000;
// Try Cosmos DB subscription - survey shown to 100% of users at day 1 in Data Explorer.
if (userContext.isTryCosmosDBSubscription) {
if (isAccountNewerThanThresholdInMs(userContext.databaseAccount?.systemData?.createdAt || "", ONE_DAY_IN_MS)) {
Logger.logInfo(
`Displaying NPS Survey for Try Cosmos DB ${userContext.apiType}`,
`Sending message to Portal to check if NPS Survey can be displayed in Try Cosmos DB ${userContext.apiType}`,
"Explorer/openNPSSurveyDialog",
);
this.sendNPSMessage();
sendMessage({ type: MessageTypes.DisplayNPSSurvey });
}
} else {
// Show survey when an existing account is older than 3 days
// Show survey when an existing account is older than 7 days
if (
!isAccountNewerThanThresholdInMs(userContext.databaseAccount?.systemData?.createdAt || "", THREE_DAYS_IN_MS)
!isAccountNewerThanThresholdInMs(userContext.databaseAccount?.systemData?.createdAt || "", SEVEN_DAYS_IN_MS)
) {
Logger.logInfo(
`Displaying NPS Survey for users with existing ${userContext.apiType} account older than 3 days`,
`Sending message to Portal to check if NPS Survey can be displayed for existing ${userContext.apiType} account older than 7 days`,
"Explorer/openNPSSurveyDialog",
);
this.sendNPSMessage();
sendMessage({ type: MessageTypes.DisplayNPSSurvey });
}
}
}
private sendNPSMessage() {
sendMessage({ type: MessageTypes.DisplayNPSSurvey });
Logger.logInfo(
`NPS Survey logging current date when survey is shown ${Date.now().toString()}`,
"Explorer/openNPSSurveyDialog",
);
localStorage.setItem("lastSubmitted", Date.now().toString());
}
public async refreshDatabaseForResourceToken(): Promise<void> {
const databaseId = userContext.parsedResourceToken?.databaseId;
const collectionId = userContext.parsedResourceToken?.collectionId;