Skip to content

Commit

Permalink
Merge pull request #7353 from brionmario/fix-21710
Browse files Browse the repository at this point in the history
Integrate `tldts` to derive the `domain` name
  • Loading branch information
brionmario authored Jan 26, 2025
2 parents 1d763c1 + 688eb22 commit 61590a6
Show file tree
Hide file tree
Showing 29 changed files with 728 additions and 460 deletions.
10 changes: 10 additions & 0 deletions .changeset/honest-ears-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@wso2is/react-components": minor
"@wso2is/unit-testing": minor
"@wso2is/identity-apps-core": minor
"@wso2is/myaccount": minor
"@wso2is/core": minor
"@wso2is/i18n": minor
---

Integrate `tldts` to derive the `domain` name
165 changes: 0 additions & 165 deletions apps/myaccount/src/components/footer/footer.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions apps/myaccount/src/components/footer/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions apps/myaccount/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2019, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
* Copyright (c) 2019-2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -20,7 +20,6 @@ export * from "./applications";
export * from "./account-recovery";
export * from "./change-password";
export * from "./consents";
export * from "./footer";
export * from "./linked-accounts";
export * from "./multi-factor-authentication";
export * from "./overview";
Expand Down
48 changes: 8 additions & 40 deletions apps/myaccount/src/components/shared/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ import {
LinkedAccountInterface
} from "@wso2is/core/models";
import { addAlert } from "@wso2is/core/store";
import {
CookieStorageUtils,
StringUtils
} from "@wso2is/core/utils";
import { I18n, LanguageChangeException, LocaleMeta, SupportedLanguagesMeta } from "@wso2is/i18n";
import { CookieStorageUtils, StringUtils, URLUtils } from "@wso2is/core/utils";
import { I18n, I18nModuleConstants, LanguageChangeException, LocaleMeta, SupportedLanguagesMeta } from "@wso2is/i18n";
import isEmpty from "lodash-es/isEmpty";
import moment from "moment";
import React, {
Expand Down Expand Up @@ -195,42 +192,13 @@ export const Header: FunctionComponent<HeaderPropsInterface> = (
});

const cookieSupportedLanguage: string = language.replace("-", "_");
const domain: string = ";domain=" + extractDomainFromHost();
const cookieExpiryTime: number = 30;
const expires: string = "; expires=" + new Date().setTime(cookieExpiryTime * 24 * 60 * 60 * 1000);
const cookieString: string = "ui_lang=" + (cookieSupportedLanguage || "") + expires + domain + "; path=/";

CookieStorageUtils.setItem(cookieString);
};

/**
* Extracts the domain from the hostname.
* If parsing fails, undefined will be returned.
*
* @returns current domain
*/
const extractDomainFromHost = (): string => {
let domain: string = undefined;

/**
* Extract the domain from the hostname.
* Ex: If console.wso2-is.com is parsed, `wso2-is.com` will be set as the domain.
* If hostname has no periods, then entire hostname is taken as domain. Ex: localhost
*/
try {
const hostnameTokens: string[] = window.location.hostname.split(".");

if (hostnameTokens.length == 1){
domain = hostnameTokens[0];
} else if (hostnameTokens.length > 1) {
domain = hostnameTokens.slice(hostnameTokens.length - 2, hostnameTokens.length).join(".");
}
} catch (e) {
// Couldn't parse the hostname. Log the error in debug mode.
// Tracked here https://github.com/wso2/product-is/issues/11650.
}

return domain;
CookieStorageUtils.setCookie(
I18nModuleConstants.PREFERENCE_STORAGE_KEY,
cookieSupportedLanguage,
{ days: 30 },
URLUtils.getDomain(window.location.href)
);
};

/**
Expand Down
46 changes: 13 additions & 33 deletions apps/myaccount/src/layouts/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ import Navbar from "@oxygen-ui/react/Navbar";
import Snackbar from "@oxygen-ui/react/Snackbar";
import { AlertInterface, AnnouncementBannerInterface, ChildRouteInterface, RouteInterface } from "@wso2is/core/models";
import { initializeAlertSystem } from "@wso2is/core/store";
import { RouteUtils as CommonRouteUtils, CommonUtils, CookieStorageUtils, RouteUtils } from "@wso2is/core/utils";
import { I18n, LanguageChangeException } from "@wso2is/i18n";
import {
RouteUtils as CommonRouteUtils,
CommonUtils, CookieStorageUtils,
RouteUtils,
URLUtils
} from "@wso2is/core/utils";
import { I18n, I18nModuleConstants, LanguageChangeException } from "@wso2is/i18n";
import { Alert, ContentLoader, EmptyPlaceholder, ErrorBoundary, LinkButton } from "@wso2is/react-components";
import isEmpty from "lodash-es/isEmpty";
import kebabCase from "lodash-es/kebabCase";
Expand Down Expand Up @@ -110,40 +115,15 @@ export const DashboardLayout: FunctionComponent<PropsWithChildren<DashboardLayou
});

const cookieSupportedLanguage: string = language.replace("-", "_");
const domain: string = ";domain=" + extractDomainFromHost();
const cookieExpiryTime: number = 30;
const expires: string = "; expires=" + new Date().setTime(cookieExpiryTime * 24 * 60 * 60 * 1000);
const cookieString: string = "ui_lang=" + (cookieSupportedLanguage || "") + expires + domain + "; path=/";

CookieStorageUtils.setItem(cookieString);
CookieStorageUtils.setCookie(
I18nModuleConstants.PREFERENCE_STORAGE_KEY,
cookieSupportedLanguage,
{ days: 30 },
URLUtils.getDomain(window.location.href)
);
};

/**
* Extracts the domain from the hostname.
* If parsing fails, undefined will be returned.
*
* @returns current domain
*/
const extractDomainFromHost = (): string => {
let domain: string = undefined;

/**
* Extract the domain from the hostname.
* Ex: If console.wso2-is.com is parsed, `wso2-is.com` will be set as the domain.
*/
try {
const hostnameTokens: string[] = window.location.hostname.split(".");

if (hostnameTokens.length > 1) {
domain = hostnameTokens.slice(hostnameTokens.length - 2, hostnameTokens.length).join(".");
}
} catch (e) {
// Couldn't parse the hostname. Log the error in debug mode.
// Tracked here https://github.com/wso2/product-is/issues/11650.
}

return domain;
};

/**
* Performs pre-requisites for the side panel items visibility.
Expand Down
Loading

0 comments on commit 61590a6

Please sign in to comment.