refactor: replace getBaseUrlWithLocale with getUrlWithLocale
- Updated multiple files to replace the deprecated getBaseUrlWithLocale function with the new getUrlWithLocale function for generating localized URLs. - Ensured consistency across the application by standardizing URL generation methods in checkout, customer portal, and various marketing pages.
This commit is contained in:
parent
fd11648d98
commit
d0dc072324
@ -2,7 +2,7 @@
|
||||
|
||||
import { getSession } from "@/lib/server";
|
||||
import { findPlanByPlanId } from "@/lib/price-plan";
|
||||
import { getBaseUrlWithLocale } from "@/lib/urls/urls";
|
||||
import { getUrlWithLocale } from "@/lib/urls/urls";
|
||||
import { createCheckout } from "@/payment";
|
||||
import { CreateCheckoutParams } from "@/payment/types";
|
||||
import { getLocale } from "next-intl/server";
|
||||
@ -68,9 +68,8 @@ export const createCheckoutAction = actionClient
|
||||
};
|
||||
|
||||
// Create the checkout session with localized URLs
|
||||
const baseUrlWithLocale = getBaseUrlWithLocale(locale);
|
||||
const successUrl = `${baseUrlWithLocale}/settings/billing?session_id={CHECKOUT_SESSION_ID}`;
|
||||
const cancelUrl = `${baseUrlWithLocale}/pricing`;
|
||||
const successUrl = getUrlWithLocale('/settings/billing?session_id={CHECKOUT_SESSION_ID}', locale);
|
||||
const cancelUrl = getUrlWithLocale('/pricing', locale);
|
||||
const params: CreateCheckoutParams = {
|
||||
planId,
|
||||
priceId,
|
||||
|
@ -3,7 +3,7 @@
|
||||
import db from "@/db";
|
||||
import { user } from "@/db/schema";
|
||||
import { getSession } from "@/lib/server";
|
||||
import { getBaseUrlWithLocale } from "@/lib/urls/urls";
|
||||
import { getUrlWithLocale } from "@/lib/urls/urls";
|
||||
import { createCustomerPortal } from "@/payment";
|
||||
import { CreatePortalParams } from "@/payment/types";
|
||||
import { eq } from "drizzle-orm";
|
||||
@ -67,8 +67,7 @@ export const createPortalAction = actionClient
|
||||
const locale = await getLocale();
|
||||
|
||||
// Create the portal session with localized URL if no custom return URL is provided
|
||||
const baseUrlWithLocale = getBaseUrlWithLocale(locale);
|
||||
const returnUrlWithLocale = returnUrl || `${baseUrlWithLocale}/settings/billing`;
|
||||
const returnUrlWithLocale = returnUrl || getUrlWithLocale('/settings/billing', locale);
|
||||
const params: CreatePortalParams = {
|
||||
customerId: customerResult[0].customerId,
|
||||
returnUrl: returnUrlWithLocale,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import FAQs from '@/components/blocks/faqs/faqs';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
@ -27,7 +27,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: t('title'),
|
||||
description: t('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}`,
|
||||
canonicalUrl: getUrlWithLocale('/', locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { CustomPage } from '@/components/page/custom-page';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getPage } from '@/lib/page/get-page';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import type { NextPageProps } from '@/types/next-page-props';
|
||||
import type { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
@ -28,7 +28,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: page.title + ' | ' + t('title'),
|
||||
description: page.description,
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/cookie`,
|
||||
canonicalUrl: getUrlWithLocale("/cookie", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { CustomPage } from '@/components/page/custom-page';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getPage } from '@/lib/page/get-page';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import type { NextPageProps } from '@/types/next-page-props';
|
||||
import type { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
@ -28,7 +28,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: page.title + ' | ' + t('title'),
|
||||
description: page.description,
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/privacy`,
|
||||
canonicalUrl: getUrlWithLocale("/privacy", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { CustomPage } from '@/components/page/custom-page';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getPage } from '@/lib/page/get-page';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import type { NextPageProps } from '@/types/next-page-props';
|
||||
import type { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
@ -28,7 +28,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: page.title + ' | ' + t('title'),
|
||||
description: page.description,
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/terms`,
|
||||
canonicalUrl: getUrlWithLocale("/terms", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { MailIcon } from 'lucide-react';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
@ -20,7 +20,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: pt('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/about`,
|
||||
canonicalUrl: getUrlWithLocale("/about", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ReleaseCard } from '@/components/release/release-card';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getReleases } from '@/lib/release/get-releases';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import type { NextPageProps } from '@/types/next-page-props';
|
||||
import type { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
@ -22,7 +22,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: pt('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/changelog`,
|
||||
canonicalUrl: getUrlWithLocale("/changelog", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ContactFormCard } from '@/components/contact/contact-form-card';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
@ -17,7 +17,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: pt('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/contact`,
|
||||
canonicalUrl: getUrlWithLocale("/contact", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { WaitlistFormCard } from '@/components/waitlist/waitlist-form-card';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
@ -16,7 +16,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: pt('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/waitlist`,
|
||||
canonicalUrl: getUrlWithLocale("/waitlist", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import BlockPreview from '@/components/nsui/block-preview';
|
||||
import { blocks, categories } from '@/components/nsui/blocks';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
@ -26,7 +26,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: category + ' | ' + t('title'),
|
||||
description: t('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/blocks/${category}`,
|
||||
canonicalUrl: getUrlWithLocale("/blocks/${category}", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ import EmptyGrid from '@/components/shared/empty-grid';
|
||||
import CustomPagination from '@/components/shared/pagination';
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { NextPageProps } from '@/types/next-page-props';
|
||||
import { allCategories, allPosts } from 'content-collections';
|
||||
import type { Metadata } from 'next';
|
||||
@ -34,7 +34,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: `${category.name} | ${t('title')}`,
|
||||
description: category.description,
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/blog/category/${slug}`,
|
||||
canonicalUrl: getUrlWithLocale("/blog/category/${slug}", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ import EmptyGrid from '@/components/shared/empty-grid';
|
||||
import CustomPagination from '@/components/shared/pagination';
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { NextPageProps } from '@/types/next-page-props';
|
||||
import { allPosts } from 'content-collections';
|
||||
import { Metadata } from 'next';
|
||||
@ -21,7 +21,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: pt('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/blog`,
|
||||
canonicalUrl: getUrlWithLocale("/blog", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import { websiteConfig } from '@/config/website';
|
||||
import { LocaleLink } from '@/i18n/navigation';
|
||||
import { getTableOfContents } from '@/lib/blog/toc';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import type { NextPageProps } from '@/types/next-page-props';
|
||||
import { allPosts, Post } from 'content-collections';
|
||||
import { CalendarIcon, ClockIcon, FileTextIcon } from 'lucide-react';
|
||||
@ -99,7 +99,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: `${post.title} | ${t('title')}`,
|
||||
description: post.description,
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}${post.slug}`,
|
||||
canonicalUrl: getUrlWithLocale(post.slug, locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
@ -15,7 +15,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: pt('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/pricing`,
|
||||
canonicalUrl: getUrlWithLocale('/pricing', locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ErrorCard } from '@/components/auth/error-card';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
@ -17,7 +17,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: t('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/auth/error`,
|
||||
canonicalUrl: getUrlWithLocale('/auth/error', locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ForgotPasswordForm } from '@/components/auth/forgot-password-form';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
@ -17,7 +17,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: t('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/auth/forgot-password`,
|
||||
canonicalUrl: getUrlWithLocale("/auth/forgot-password", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { LoginForm } from '@/components/auth/login-form';
|
||||
import { LocaleLink } from '@/i18n/navigation';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Routes } from '@/routes';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
@ -19,7 +19,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: t('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/auth/login`,
|
||||
canonicalUrl: getUrlWithLocale("/auth/login", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { RegisterForm } from '@/components/auth/register-form';
|
||||
import { LocaleLink } from '@/i18n/navigation';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Routes } from '@/routes';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
@ -19,7 +19,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: t('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/auth/register`,
|
||||
canonicalUrl: getUrlWithLocale('/auth/register', locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ResetPasswordForm } from '@/components/auth/reset-password-form';
|
||||
import { constructMetadata } from '@/lib/metadata';
|
||||
import { getBaseUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
import { Metadata } from 'next';
|
||||
import { Locale } from 'next-intl';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
@ -17,7 +17,7 @@ export async function generateMetadata({
|
||||
return constructMetadata({
|
||||
title: pt('title') + ' | ' + t('title'),
|
||||
description: t('description'),
|
||||
canonicalUrl: `${getBaseUrlWithLocale(locale)}/auth/reset-password`,
|
||||
canonicalUrl: getUrlWithLocale("/auth/reset-password", locale),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -19,13 +19,6 @@ export function shouldAppendLocale(locale?: Locale | null): boolean {
|
||||
return !!locale && locale !== routing.defaultLocale && locale !== 'default';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URL of the application with the locale appended
|
||||
*/
|
||||
export function getBaseUrlWithLocale(locale?: Locale | null): string {
|
||||
return shouldAppendLocale(locale) ? `${baseUrl}/${locale}` : baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL of the application with the locale appended
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user