Updated the footer to remove the domian url as it was causing the redirect to shopify domain

This commit is contained in:
Mandeep Tatla 2024-05-12 11:59:57 +09:30
parent 8cd637e609
commit c799a5f53d
3 changed files with 15 additions and 3 deletions

View File

@ -2,7 +2,6 @@
import clsx from 'clsx';
import { Menu } from 'lib/shopify/types';
import { RemoveTheDomainFromUrl } from 'lib/utils';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { useEffect, useState } from 'react';
@ -18,7 +17,7 @@ const FooterMenuItem = ({ item }: { item: Menu }) => {
return (
<li>
<Link
href={RemoveTheDomainFromUrl(item.path)}
href={item.path}
className={clsx(
'block p-2 text-lg underline-offset-4 hover:text-black hover:underline md:inline-block md:text-sm dark:hover:text-neutral-300',
{

View File

@ -3,6 +3,7 @@ import Link from 'next/link';
import FooterMenu from 'components/layout/footer-menu';
import LogoSquare from 'components/logo-square';
import { getMenu } from 'lib/shopify';
import { RemoveTheDomainFromArray } from 'lib/utils';
import { Suspense } from 'react';
const { COMPANY_NAME, SITE_NAME } = process.env;
@ -12,6 +13,7 @@ export default async function Footer() {
const copyrightDate = 2023 + (currentYear > 2023 ? `-${currentYear}` : '');
const skeleton = 'w-full h-6 animate-pulse rounded bg-neutral-200 dark:bg-neutral-700';
const menu = await getMenu('next-js-frontend-footer-menu');
const updatedMenuLinks = RemoveTheDomainFromArray(menu);
const copyrightName = COMPANY_NAME || SITE_NAME || '';
return (
@ -35,7 +37,7 @@ export default async function Footer() {
</div>
}
>
<FooterMenu menu={menu} />
<FooterMenu menu={updatedMenuLinks} />
</Suspense>
<div className="md:ml-auto">
<a

View File

@ -15,6 +15,17 @@ export const RemoveTheDomainFromUrl = (url: string) => {
return modifiedUrl;
};
export const RemoveTheDomainFromArray = (menu: any) => {
const lowercaseString = `https://${SHOPIFY_STORE_DOMAIN}`.toLowerCase();
const modifiedUrls = menu.map((item: any) => {
const modifiedPath = item.path.replace(lowercaseString, '');
return { ...item, path: modifiedPath };
});
return modifiedUrls;
};
export const ensureStartsWith = (stringToCheck: string, startsWith: string) =>
stringToCheck.startsWith(startsWith) ? stringToCheck : `${startsWith}${stringToCheck}`;