Add check of account creation time to show carousel (#1284)

Co-authored-by: artrejo <ato9000@users.noreply.github.com>
This commit is contained in:
victor-meng
2022-06-01 15:25:56 -07:00
committed by GitHub
parent 46ca952955
commit 7e1343e84f
10 changed files with 29 additions and 29 deletions

View File

@@ -56,6 +56,8 @@ interface UserContext {
export type ApiType = "SQL" | "Mongo" | "Gremlin" | "Tables" | "Cassandra";
export type PortalEnv = "localhost" | "blackforest" | "fairfax" | "mooncake" | "prod" | "dev";
const ONE_WEEK_IN_MS = 604800000;
const features = extractFeatures();
const { enableSDKoperations: useSDKOperations } = features;
@@ -71,10 +73,30 @@ const userContext: UserContext = {
collectionCreationDefaults: CollectionCreationDefaults,
};
function isAccountNewerThanThresholdInMs(createdAt: string, threshold: number) {
let createdAtMs: number = Date.parse(createdAt);
if (isNaN(createdAtMs)) {
createdAtMs = 0;
}
const nowMs: number = Date.now();
const millisecsSinceAccountCreation = nowMs - createdAtMs;
return threshold > millisecsSinceAccountCreation;
}
function updateUserContext(newContext: Partial<UserContext>): void {
if (newContext.databaseAccount) {
newContext.apiType = apiType(newContext.databaseAccount);
if (!localStorage.getItem(newContext.databaseAccount.id)) {
const isNewAccount = isAccountNewerThanThresholdInMs(
newContext.databaseAccount?.systemData?.createdAt || "",
ONE_WEEK_IN_MS
);
if (
!localStorage.getItem(newContext.databaseAccount.id) &&
(userContext.isTryCosmosDBSubscription || isNewAccount)
) {
useCarousel.getState().setShouldOpen(true);
localStorage.setItem(newContext.databaseAccount.id, "true");
}