From 4de313bd514167203daec4304f0d754653f00c85 Mon Sep 17 00:00:00 2001 From: Luigi Carvalho Date: Tue, 31 Oct 2023 15:25:27 +0000 Subject: [PATCH 01/10] add default locale in next.config.js --- next.config.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/next.config.js b/next.config.js index d5b9922..881f487 100644 --- a/next.config.js +++ b/next.config.js @@ -4,6 +4,7 @@ // module.exports = nextConfig const withNextIntl = require('next-intl/plugin')('./i18n.ts'); +const defLocale = (typeof window !== 'undefined') ? localStorage.getItem("lang") : "en"; module.exports = withNextIntl({ experimental: { @@ -15,42 +16,42 @@ module.exports = withNextIntl({ return [ { source: '/', - destination: '/en', + destination: '/'+defLocale, permanent: true, }, { source: '/admin', - destination: '/en/admin/dashboard', + destination: '/'+defLocale+'/admin/dashboard', permanent: true, }, { source: '/admin/dashboard', - destination: '/en/admin/dashboard', + destination: '/'+defLocale+'/admin/dashboard', permanent: true, }, { source: '/admin/projects', - destination: '/en/admin/projects', + destination: '/'+defLocale+'/admin/projects', permanent: true, }, { source: '/admin/users', - destination: '/en/admin/users', + destination: '/'+defLocale+'/admin/users', permanent: true, }, { source: '/admin/newsletter', - destination: '/en/admin/newsletter', + destination: '/'+defLocale+'/admin/newsletter', permanent: true, }, { source: '/admin/subscriptions', - destination: '/en/admin/subscriptions', + destination: '/'+defLocale+'/admin/subscriptions', permanent: true, }, { source: '/admin/settings', - destination: '/en/admin/settings', + destination: '/'+defLocale+'/admin/settings', permanent: true, }, ] From 9a1d965db8ea84dd1a947239caaf7a91bd28863b Mon Sep 17 00:00:00 2001 From: Luigi Carvalho Date: Tue, 31 Oct 2023 15:38:55 +0000 Subject: [PATCH 02/10] removed unnecessary localstorage in next.config --- next.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/next.config.js b/next.config.js index 881f487..ce320c9 100644 --- a/next.config.js +++ b/next.config.js @@ -4,7 +4,7 @@ // module.exports = nextConfig const withNextIntl = require('next-intl/plugin')('./i18n.ts'); -const defLocale = (typeof window !== 'undefined') ? localStorage.getItem("lang") : "en"; +const defLocale = "en"; module.exports = withNextIntl({ experimental: { From 132416c53078f2b61922fd1a95e21911fc027d49 Mon Sep 17 00:00:00 2001 From: Luigi Carvalho Date: Tue, 31 Oct 2023 17:17:52 +0000 Subject: [PATCH 03/10] fixed locale in links and removed unnecessary redirects --- next.config.js | 37 +------------------ src/app/[locale]/admin/dashboard/login.tsx | 6 +-- src/app/[locale]/admin/newsletter/page.tsx | 2 +- src/app/[locale]/admin/projects/page.tsx | 2 +- src/app/[locale]/admin/settings/page.tsx | 2 +- src/app/[locale]/admin/subscriptions/page.tsx | 2 +- src/app/[locale]/admin/users/page.tsx | 2 +- src/app/[locale]/components/admin/navbar.js | 2 +- 8 files changed, 10 insertions(+), 45 deletions(-) diff --git a/next.config.js b/next.config.js index ce320c9..5ac2f5c 100644 --- a/next.config.js +++ b/next.config.js @@ -18,42 +18,7 @@ module.exports = withNextIntl({ source: '/', destination: '/'+defLocale, permanent: true, - }, - { - source: '/admin', - destination: '/'+defLocale+'/admin/dashboard', - permanent: true, - }, - { - source: '/admin/dashboard', - destination: '/'+defLocale+'/admin/dashboard', - permanent: true, - }, - { - source: '/admin/projects', - destination: '/'+defLocale+'/admin/projects', - permanent: true, - }, - { - source: '/admin/users', - destination: '/'+defLocale+'/admin/users', - permanent: true, - }, - { - source: '/admin/newsletter', - destination: '/'+defLocale+'/admin/newsletter', - permanent: true, - }, - { - source: '/admin/subscriptions', - destination: '/'+defLocale+'/admin/subscriptions', - permanent: true, - }, - { - source: '/admin/settings', - destination: '/'+defLocale+'/admin/settings', - permanent: true, - }, + } ] }, }); diff --git a/src/app/[locale]/admin/dashboard/login.tsx b/src/app/[locale]/admin/dashboard/login.tsx index bc475b8..672a8ed 100644 --- a/src/app/[locale]/admin/dashboard/login.tsx +++ b/src/app/[locale]/admin/dashboard/login.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useEffect, useState } from 'react'; -import { useTranslations } from 'next-intl'; +import { useLocale, useTranslations } from 'next-intl'; import Link from 'next/link'; import admstyles from '../../styles/admin/admin.module.scss'; import { doLogin } from '../../utils/authUtils'; @@ -45,7 +45,7 @@ export default function DashboardLogin() { setIsLoggedIn(true); setIsLoading(false); - location.href = "/admin/dashboard"; + location.href = `/${localStorage.getItem("lang")}/admin/dashboard`; } }).catch((error) => console.error(error)) } @@ -86,7 +86,7 @@ export default function DashboardLogin() { )} - {t('btnBack')} + {t('btnBack')} diff --git a/src/app/[locale]/admin/newsletter/page.tsx b/src/app/[locale]/admin/newsletter/page.tsx index aba8007..10641e8 100644 --- a/src/app/[locale]/admin/newsletter/page.tsx +++ b/src/app/[locale]/admin/newsletter/page.tsx @@ -39,7 +39,7 @@ export default function AdminNewsletterPage() {

{t('welcome', { 'username': username })}

{t('title')}

Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae dolorem quas, distinctio asperiores mollitia ratione dignissimos cumque omnis reiciendis quos veritatis veniam ipsa. Velit illo adipisci, amet corrupti voluptatem laudantium.

- {t('btnBack')} + {t('btnBack')} diff --git a/src/app/[locale]/admin/projects/page.tsx b/src/app/[locale]/admin/projects/page.tsx index 75147ff..eabbf02 100644 --- a/src/app/[locale]/admin/projects/page.tsx +++ b/src/app/[locale]/admin/projects/page.tsx @@ -39,7 +39,7 @@ export default function AdminProjectsPage() {

{t('welcome', { 'username': username })}

{t('title')}

Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae dolorem quas, distinctio asperiores mollitia ratione dignissimos cumque omnis reiciendis quos veritatis veniam ipsa. Velit illo adipisci, amet corrupti voluptatem laudantium.

- {t('btnBack')} + {t('btnBack')} diff --git a/src/app/[locale]/admin/settings/page.tsx b/src/app/[locale]/admin/settings/page.tsx index f44733e..d576e85 100644 --- a/src/app/[locale]/admin/settings/page.tsx +++ b/src/app/[locale]/admin/settings/page.tsx @@ -39,7 +39,7 @@ export default function AdminSettingsPage() {

{t('welcome', { 'username': username })}

{t('title')}

Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae dolorem quas, distinctio asperiores mollitia ratione dignissimos cumque omnis reiciendis quos veritatis veniam ipsa. Velit illo adipisci, amet corrupti voluptatem laudantium.

- {t('btnBack')} + {t('btnBack')} diff --git a/src/app/[locale]/admin/subscriptions/page.tsx b/src/app/[locale]/admin/subscriptions/page.tsx index 1322830..ec0013e 100644 --- a/src/app/[locale]/admin/subscriptions/page.tsx +++ b/src/app/[locale]/admin/subscriptions/page.tsx @@ -194,7 +194,7 @@ export default function AdminSubscriptionsPage() {
- {t('btnBack')} + {t('btnBack')}
diff --git a/src/app/[locale]/admin/users/page.tsx b/src/app/[locale]/admin/users/page.tsx index 58f213a..4f38392 100644 --- a/src/app/[locale]/admin/users/page.tsx +++ b/src/app/[locale]/admin/users/page.tsx @@ -39,7 +39,7 @@ export default function AdminUsersPage() {

{t('welcome', { 'username': username })}

{t('title')}

Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae dolorem quas, distinctio asperiores mollitia ratione dignissimos cumque omnis reiciendis quos veritatis veniam ipsa. Velit illo adipisci, amet corrupti voluptatem laudantium.

- {t('btnBack')} + {t('btnBack')} diff --git a/src/app/[locale]/components/admin/navbar.js b/src/app/[locale]/components/admin/navbar.js index 05f215b..ca65e3d 100644 --- a/src/app/[locale]/components/admin/navbar.js +++ b/src/app/[locale]/components/admin/navbar.js @@ -33,7 +33,7 @@ export default function NavbarAdmin() { setUserName(""); setIsLoggedIn(false); - location.href = "/admin"; + location.href = `/${localStorage.getItem("lang")}/admin`; }).catch((error) => console.error(error)); }; From 5cf72d60fa2c2328a39d0f5980ecce0353f70755 Mon Sep 17 00:00:00 2001 From: Luigi Carvalho Date: Tue, 31 Oct 2023 17:21:55 +0000 Subject: [PATCH 04/10] fixed links with locale in sidebar admin --- src/app/[locale]/components/admin/sidebar.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/app/[locale]/components/admin/sidebar.js b/src/app/[locale]/components/admin/sidebar.js index 2c69a8b..bc278a9 100644 --- a/src/app/[locale]/components/admin/sidebar.js +++ b/src/app/[locale]/components/admin/sidebar.js @@ -5,15 +5,16 @@ import { usePathname } from 'next/navigation'; import { useTranslations } from 'next-intl'; export default function SidebarAdmin() { + const lang = localStorage.getItem("lang"); const t = useTranslations('Admin.Sidebar'); const pthname = usePathname(); const aryLinks = [ - { id: 1, name: t('sbaropt1'), href: "/admin/projects", icon: "bi-kanban" }, - { id: 2, name: t('sbaropt2'), href: "/admin/users", icon: "bi-people" }, - { id: 3, name: t('sbaropt3'), href: "/admin/newsletter", icon: "bi-newspaper" }, - { id: 4, name: t('sbaropt4'), href: "/admin/subscriptions", icon: "bi-inbox" }, - { id: 5, name: t('sbaropt5'), href: "/admin/settings", icon: "bi-gear" } + { id: 1, name: t('sbaropt1'), href: `/${lang}/admin/projects`, icon: "bi-kanban" }, + { id: 2, name: t('sbaropt2'), href: `/${lang}/admin/users`, icon: "bi-people" }, + { id: 3, name: t('sbaropt3'), href: `/${lang}/admin/newsletter`, icon: "bi-newspaper" }, + { id: 4, name: t('sbaropt4'), href: `/${lang}/admin/subscriptions`, icon: "bi-inbox" }, + { id: 5, name: t('sbaropt5'), href: `/${lang}/admin/settings`, icon: "bi-gear" } ]; const [isCollapsed, setIsCollapsed] = useState(false); From ce76ff629aaed6050352e01e94ea6edf13d47468 Mon Sep 17 00:00:00 2001 From: Luigi Carvalho Date: Tue, 31 Oct 2023 17:26:14 +0000 Subject: [PATCH 05/10] fixed links with locale in sidebar and navbars --- src/app/[locale]/components/admin/navbar.js | 2 +- src/app/[locale]/components/admin/sidebar.js | 2 +- src/app/[locale]/components/navbar.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/[locale]/components/admin/navbar.js b/src/app/[locale]/components/admin/navbar.js index ca65e3d..6f8617b 100644 --- a/src/app/[locale]/components/admin/navbar.js +++ b/src/app/[locale]/components/admin/navbar.js @@ -44,7 +44,7 @@ export default function NavbarAdmin() { - LCP + LCP diff --git a/src/app/[locale]/components/admin/sidebar.js b/src/app/[locale]/components/admin/sidebar.js index bc278a9..253b59d 100644 --- a/src/app/[locale]/components/admin/sidebar.js +++ b/src/app/[locale]/components/admin/sidebar.js @@ -28,7 +28,7 @@ export default function SidebarAdmin() { <>