Browse Source

user get back to the page after log in or sign up

main
sina_sajjadi 1 month ago
parent
commit
211fd4fa6f
  1. 10
      next-i18next.config.js
  2. 9
      next.config.js
  3. 6
      package-lock.json
  4. 2
      package.json
  5. 6
      public/locales/en/common.json
  6. 258
      src/app/(client-components)/(Header)/LangDropdown.tsx
  7. 9
      src/app/blog/SectionMagazine5.tsx
  8. 2
      src/app/login/page.tsx
  9. 2
      src/app/signup/otp-code/page.tsx
  10. 2
      src/app/signup/page.tsx
  11. 4
      yarn.lock

10
next-i18next.config.js

@ -0,0 +1,10 @@
const path = require("path");
module.exports = {
i18n: {
locales: ["en", "de", "es", "ar", "he", "zh", "fa"],
defaultLocale: "en",
localeDetection: false,
},
localePath: path.resolve("./public/locales"),
};

9
next.config.js

@ -1,4 +1,6 @@
/** @type {import('next').NextConfig} */
const { i18n } = require("./next-i18next.config");
module.exports = {
@ -13,11 +15,8 @@ module.exports = {
eslint: {
ignoreDuringBuilds: true,
},
i18n: {
locales: ['en'], // List all the languages you want to support
defaultLocale: 'en', // The default language of the website
localeDetection: true, // Enable or disable automatic locale detection based on browser settings
},
i18n,
images: {
remotePatterns: [
{

6
package-lock.json

@ -25,6 +25,7 @@
"framer-motion": "^10.12.16",
"google-libphonenumber": "^3.2.38",
"google-map-react": "^2.2.1",
"i18next": "^23.15.1",
"libphonenumber-js": "^1.11.9",
"lodash": "^4.17.21",
"next": "^13.4.3",
@ -34,6 +35,7 @@
"react-datepicker": "^4.11.0",
"react-dom": "^18.2.0",
"react-hooks-global-state": "^2.1.0",
"react-i18next": "^15.0.2",
"react-icons": "^5.3.0",
"react-swipeable": "^7.0.0",
"react-toastify": "^10.0.5",
@ -2727,7 +2729,6 @@
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz",
"integrity": "sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg==",
"peer": true,
"dependencies": {
"void-elements": "3.1.0"
}
@ -2765,7 +2766,6 @@
"url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project"
}
],
"peer": true,
"dependencies": {
"@babel/runtime": "^7.23.2"
}
@ -4338,7 +4338,6 @@
"version": "15.0.2",
"resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-15.0.2.tgz",
"integrity": "sha512-z0W3/RES9Idv3MmJUcf0mDNeeMOUXe+xoL0kPfQPbDoZHmni/XsIoq5zgT2MCFUiau283GuBUK578uD/mkAbLQ==",
"peer": true,
"dependencies": {
"@babel/runtime": "^7.25.0",
"html-parse-stringify": "^3.0.1"
@ -5457,7 +5456,6 @@
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz",
"integrity": "sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==",
"peer": true,
"engines": {
"node": ">=0.10.0"
}

2
package.json

@ -32,6 +32,7 @@
"framer-motion": "^10.12.16",
"google-libphonenumber": "^3.2.38",
"google-map-react": "^2.2.1",
"i18next": "^23.15.1",
"libphonenumber-js": "^1.11.9",
"lodash": "^4.17.21",
"next": "^13.4.3",
@ -41,6 +42,7 @@
"react-datepicker": "^4.11.0",
"react-dom": "^18.2.0",
"react-hooks-global-state": "^2.1.0",
"react-i18next": "^15.0.2",
"react-icons": "^5.3.0",
"react-swipeable": "^7.0.0",
"react-toastify": "^10.0.5",

6
public/locales/en/common.json

@ -0,0 +1,6 @@
{
"hello": "Hello",
"welcome": "Welcome to our website",
"language": "Language"
}

258
src/app/(client-components)/(Header)/LangDropdown.tsx

@ -1,52 +1,15 @@
import React, { Fragment, useState } from "react";
import { Popover, Tab, Transition } from "@headlessui/react";
import {
BanknotesIcon,
GlobeAltIcon,
ChevronDownIcon,
} from "@heroicons/react/24/outline";
import { FC, Fragment } from "react";
import { headerCurrency } from "./CurrencyDropdown";
import { ChevronDownIcon } from "@heroicons/react/24/outline";
import { MdOutlineLanguage } from "react-icons/md";
import { useTranslation } from "next-i18next";
import { useRouter } from "next/navigation"; // Importing from next/navigation
export const headerLanguage = [
{
id: "English",
name: "English",
description: "United State",
href: "##",
active: true,
},
{
id: "Vietnamese",
name: "Vietnamese",
description: "Vietnamese",
href: "##",
},
{
id: "Francais",
name: "Francais",
description: "Belgique",
href: "##",
},
{
id: "Francais",
name: "Francais",
description: "Canada",
href: "##",
},
{
id: "Francais",
name: "Francais",
description: "Belgique",
href: "##",
},
{
id: "Francais",
name: "Francais",
description: "Canada",
href: "##",
},
// Language options
const languageOptions = [
{ id: "en", name: "English", description: "United States", icon: <MdOutlineLanguage /> },
{ id: "vi", name: "Vietnamese", description: "Vietnam", icon: <MdOutlineLanguage /> },
{ id: "fr", name: "French", description: "France", icon: <MdOutlineLanguage /> },
];
interface LangDropdownProps {
@ -54,133 +17,102 @@ interface LangDropdownProps {
className?: string;
}
function classNames(...classes: any) {
function classNames(...classes: string[]) {
return classes.filter(Boolean).join(" ");
}
const LangDropdown: FC<LangDropdownProps> = ({
const LangDropdown: React.FC<LangDropdownProps> = ({
panelClassName = "top-full right-0 max-w-sm w-96",
className = "hidden md:flex",
}) => {
const renderLang = (close: () => void) => {
return (
<div className="grid gap-8 lg:grid-cols-2">
{headerLanguage.map((item, index) => (
<a
key={index}
href={item.href}
onClick={() => close()}
className={`flex items-center p-2 -m-3 transition duration-150 ease-in-out rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus-visible:ring focus-visible:ring-orange-500 focus-visible:ring-opacity-50 ${
item.active ? "bg-gray-100 dark:bg-gray-700" : "opacity-80"
}`}
>
<div className="">
<p className="text-sm font-medium ">{item.name}</p>
<p className="text-xs text-gray-500 dark:text-gray-400">
{item.description}
</p>
</div>
</a>
))}
</div>
);
};
const { t } = useTranslation("common");
const router = useRouter();
const [selectedItem, setSelectedItem] = useState(languageOptions[0]);
const renderCurr = (close: () => void) => {
return (
<div className="grid gap-7 lg:grid-cols-2">
{headerCurrency.map((item, index) => (
<a
key={index}
href={item.href}
onClick={() => close()}
className={`flex items-center p-2 -m-3 transition duration-150 ease-in-out rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus-visible:ring focus-visible:ring-orange-500 focus-visible:ring-opacity-50 ${
item.active ? "bg-gray-100 dark:bg-gray-700" : "opacity-80"
}`}
>
<item.icon className="w-[18px] h-[18px] " />
<p className="ml-2 text-sm font-medium ">{item.name}</p>
</a>
))}
</div>
);
// Handle language selection and route change
const handleItemClick = (option: any) => {
setSelectedItem(option);
router.push(`/${option.id}`); // Change locale using next/navigation's router
};
return (
<>
<Popover className={`LangDropdown relative ${className}`}>
{({ open, close }) => (
<>
<Popover.Button
className={`
${open ? "" : "text-opacity-80"}
group self-center h-10 sm:h-12 px-3 py-1.5 inline-flex items-center text-sm text-gray-800 dark:text-neutral-200 font-medium hover:text-opacity-100 focus:outline-none `}
>
<MdOutlineLanguage size={25}/>
{/* <span className="mx-1">/</span>
<BanknotesIcon className="w-5 h-5 opacity-80" /> */}
<ChevronDownIcon
className={`${open ? "-rotate-180" : "text-opacity-70"}
ml-1 h-4 w-4 group-hover:text-opacity-80 transition ease-in-out duration-150`}
aria-hidden="true"
/>
</Popover.Button>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 translate-y-1"
enterTo="opacity-100 translate-y-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1"
>
<Popover.Panel className={`absolute z-20 ${panelClassName}`}>
<div className="p-3 sm:p-6 rounded-2xl bg-white dark:bg-neutral-800 shadow-lg ring-1 ring-black ring-opacity-5">
<Tab.Group>
<Tab.List className="flex space-x-1 rounded-full bg-gray-100 dark:bg-slate-700 p-1">
{["Language", "Currency"].map((category) => (
<Tab
key={category}
className={({ selected }) =>
classNames(
"w-full rounded-full py-2 text-sm font-medium leading-5 text-gray-700",
"focus:outline-none focus:ring-0",
selected
? "bg-white shadow"
: "text-gray-700 dark:text-slate-300 hover:bg-white/70 dark:hover:bg-slate-900/40"
)
}
>
{category}
</Tab>
))}
</Tab.List>
<Tab.Panels className="mt-5">
<Tab.Panel
className={classNames(
"rounded-xl p-3",
"focus:outline-none focus:ring-0"
)}
>
{renderLang(close)}
</Tab.Panel>
<Tab.Panel
className={classNames(
"rounded-xl p-3",
"focus:outline-none focus:ring-0"
)}
>
{renderCurr(close)}
</Tab.Panel>
</Tab.Panels>
</Tab.Group>
</div>
</Popover.Panel>
</Transition>
</>
)}
</Popover>
</>
<Popover className={`LangDropdown relative ${className}`}>
{({ open, close }) => (
<>
<Popover.Button
className={`
${open ? "" : "text-opacity-80"}
group self-center h-10 sm:h-12 px-3 py-1.5 inline-flex items-center text-sm text-gray-800 dark:text-neutral-200 font-medium hover:text-opacity-100 focus:outline-none
`}
>
<MdOutlineLanguage size={25} />
<ChevronDownIcon
className={`${open ? "-rotate-180" : "text-opacity-70"}
ml-1 h-4 w-4 group-hover:text-opacity-80 transition ease-in-out duration-150`}
aria-hidden="true"
/>
</Popover.Button>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 translate-y-1"
enterTo="opacity-100 translate-y-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1"
>
<Popover.Panel className={`absolute z-20 ${panelClassName}`}>
<div className="p-3 sm:p-6 rounded-2xl bg-white dark:bg-neutral-800 shadow-lg ring-1 ring-black ring-opacity-5">
<Tab.Group>
<Tab.List className="flex space-x-1 rounded-full bg-gray-100 dark:bg-slate-700">
<Tab
key={"Language"}
className={({ selected }) =>
classNames(
"w-full rounded-full py-2 text-sm font-medium leading-5 text-gray-700",
"focus:outline-none focus:ring-0",
selected
? "bg-white"
: "text-gray-700 dark:text-slate-300 hover:bg-white/70 dark:hover:bg-slate-900/40"
)
}
>
Language
</Tab>
</Tab.List>
<Tab.Panels className="mt-5">
<Tab.Panel className={classNames("rounded-xl p-3", "focus:outline-none focus:ring-0")}>
<div className="grid gap-8 lg:grid-cols-2">
{languageOptions.map((item) => (
<button
key={item.id}
onClick={() => {
handleItemClick(item);
close();
}}
className={`flex items-center p-2 -m-3 transition duration-150 ease-in-out rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus-visible:ring focus-visible:ring-orange-500 focus-visible:ring-opacity-50 ${
selectedItem.id === item.id ? "bg-gray-100 dark:bg-gray-700" : "opacity-80"
}`}
>
<div className="">
<p className="text-sm font-medium">{item.name}</p>
<p className="text-xs text-gray-500 dark:text-gray-400">{item.description}</p>
</div>
</button>
))}
</div>
</Tab.Panel>
</Tab.Panels>
</Tab.Group>
</div>
</Popover.Panel>
</Transition>
</>
)}
</Popover>
);
};
export default LangDropdown;

9
src/app/blog/SectionMagazine5.tsx

@ -5,9 +5,11 @@ import { PostDataType } from "@/data/types";
import Card12 from "./Card12";
import Card13 from "./Card13";
import axiosInstance from "@/components/api/axios";
import { useTranslation } from "next-i18next";
const SectionMagazine5 = () => {
const { t } = useTranslation("common");
const [posts , setPosts] = useState([])
useEffect(()=>{
@ -17,9 +19,14 @@ const SectionMagazine5 = () => {
})
} , [])
console.log(t("welcome"));
return (
<div className="nc-SectionMagazine5">
<div className="grid lg:grid-cols-2 gap-6 md:gap-8">
<p>{t("welcome")}</p>
{posts[0] && <Card12 post={posts[0]} />}
<div className="grid gap-6 md:gap-8">
{posts

2
src/app/login/page.tsx

@ -100,7 +100,7 @@ const PageLogin: FC<PageLoginProps> = () => {
if (response.status === 201) {
toast.success("Login successful!");
setUser(response.data);
router.push("/"); // Redirect to home or any other page after successful login
router.back(); // Redirect to home or any other page after successful login
} else {
toast.error("Login failed, please check your credentials.", {
position: "top-right",

2
src/app/signup/otp-code/page.tsx

@ -15,7 +15,7 @@ const PageSignUp: FC<PageSignUpProps> = () => {
useEffect(() => {
if (Object.keys(user).length) {
router.replace("/");
router.back();
}
}, [user, router]);

2
src/app/signup/page.tsx

@ -75,7 +75,7 @@ const PageSignUp: FC<PageSignUpProps> = () => {
`/api/account/verfication/?range_phone=${countryCode}&phone_number=${phoneNumber}`
);
form.verification_methodes = response.data.verification_method;
router.push("/signup/methodes");
router.replace("/signup/methodes");
} catch (error: any) {
console.error("Error fetching data:", error);
setFailed(error.message || "An error occurred.");

4
yarn.lock

@ -1551,7 +1551,7 @@ i18next-fs-backend@^2.3.2:
resolved "https://registry.npmjs.org/i18next-fs-backend/-/i18next-fs-backend-2.3.2.tgz"
integrity sha512-LIwUlkqDZnUI8lnUxBnEj8K/FrHQTT/Sc+1rvDm9E8YvvY5YxzoEAASNx+W5M9DfD5s77lI5vSAFWeTp26B/3Q==
"i18next@>= 23.2.3", "i18next@>= 23.7.13":
i18next@^23.15.1, "i18next@>= 23.2.3", "i18next@>= 23.7.13":
version "23.15.1"
resolved "https://registry.npmjs.org/i18next/-/i18next-23.15.1.tgz"
integrity sha512-wB4abZ3uK7EWodYisHl/asf8UYEhrI/vj/8aoSsrj/ZDxj4/UXPOa1KvFt1Fq5hkUHquNqwFlDprmjZ8iySgYA==
@ -2443,7 +2443,7 @@ react-hooks-global-state@^2.1.0:
dependencies:
zustand "4.0.0"
"react-i18next@>= 13.5.0":
react-i18next@^15.0.2, "react-i18next@>= 13.5.0":
version "15.0.2"
resolved "https://registry.npmjs.org/react-i18next/-/react-i18next-15.0.2.tgz"
integrity sha512-z0W3/RES9Idv3MmJUcf0mDNeeMOUXe+xoL0kPfQPbDoZHmni/XsIoq5zgT2MCFUiau283GuBUK578uD/mkAbLQ==

Loading…
Cancel
Save