summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-01-31 09:03:22 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-01-31 09:03:22 +0700
commitb8764138241116e0c741a7786364f5630080720c (patch)
treecaf4396671469bc6ac992c9b741fe3f8701c986e /src/core
parent3f849355048e5c280a35a5747577e5296b90e9fd (diff)
parent0550b0dbe9b8e369cfe211b78ab0de49a6e1f49d (diff)
Merge branch 'release' into feature/all-promotion
Diffstat (limited to 'src/core')
-rw-r--r--src/core/components/ScrollToTop.jsx24
-rw-r--r--src/core/components/elements/Navbar/NavbarDesktop.jsx33
-rw-r--r--src/core/components/elements/Navbar/NavbarMobile.jsx12
-rw-r--r--src/core/components/layouts/BasicLayout.jsx33
-rw-r--r--src/core/utils/slug.js34
5 files changed, 81 insertions, 55 deletions
diff --git a/src/core/components/ScrollToTop.jsx b/src/core/components/ScrollToTop.jsx
new file mode 100644
index 00000000..f8e85167
--- /dev/null
+++ b/src/core/components/ScrollToTop.jsx
@@ -0,0 +1,24 @@
+import { useEffect } from 'react';
+import { useRouter } from 'next/router';
+
+const ScrollToTop = () => {
+ const router = useRouter();
+
+ useEffect(() => {
+ const handleRouteChange = (url, { shallow }) => {
+ if (!shallow) {
+ window.scrollTo(0, 0);
+ }
+ };
+
+ router.events.on('routeChangeComplete', handleRouteChange);
+
+ return () => {
+ router.events.off('routeChangeComplete', handleRouteChange);
+ };
+ }, [router.events]);
+
+ return null;
+};
+
+export default ScrollToTop;
diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx
index 2605acbb..760e627d 100644
--- a/src/core/components/elements/Navbar/NavbarDesktop.jsx
+++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx
@@ -1,29 +1,30 @@
+import { useProductContext } from '@/contexts/ProductContext';
+import useAuth from '@/core/hooks/useAuth';
+import { getCountCart } from '@/core/utils/cart';
+import { createSlug } from '@/core/utils/slug';
+import whatsappUrl from '@/core/utils/whatsappUrl';
+import IndoteknikLogo from '@/images/logo.png';
+import Cardheader from '@/lib/cart/components/Cartheader';
+import Category from '@/lib/category/components/Category';
import {
ChevronDownIcon,
- HeartIcon,
- ShoppingCartIcon,
DocumentCheckIcon,
+ HeartIcon,
} from '@heroicons/react/24/outline';
-import Link from '../Link/Link';
+import dynamic from 'next/dynamic';
import Image from 'next/image';
+import { useRouter } from 'next/router';
+import { useEffect, useState } from 'react';
import DesktopView from '../../views/DesktopView';
-import dynamic from 'next/dynamic';
-import IndoteknikLogo from '@/images/logo.png';
-import Category from '@/lib/category/components/Category';
-import { useCallback, useContext, useEffect, useState } from 'react';
-import useAuth from '@/core/hooks/useAuth';
+import Link from '../Link/Link';
import NavbarUserDropdown from './NavbarUserDropdown';
-import { getCartApi, getCountCart } from '@/core/utils/cart';
-import whatsappUrl from '@/core/utils/whatsappUrl';
-import { useRouter } from 'next/router';
-import { getAuth, setAuth } from '@/core/utils/auth';
-import { createSlug, getIdFromSlug } from '@/core/utils/slug';
import { TopBannerSkeleton } from '../Skeleton/TopBannerSkeleton';
-import { useProductContext } from '@/contexts/ProductContext';
-import Cardheader from '@/lib/cart/components/Cartheader';
const Search = dynamic(() => import('./Search'), { ssr: false });
-const TopBanner = dynamic(() => import('./TopBanner'), { ssr: false });
+const TopBanner = dynamic(() => import('./TopBanner'), {
+ ssr: false,
+ loading: () => <TopBannerSkeleton />,
+});
const NavbarDesktop = () => {
const [isOpenCategory, setIsOpenCategory] = useState(false);
diff --git a/src/core/components/elements/Navbar/NavbarMobile.jsx b/src/core/components/elements/Navbar/NavbarMobile.jsx
index 92bd5627..bcf45e0a 100644
--- a/src/core/components/elements/Navbar/NavbarMobile.jsx
+++ b/src/core/components/elements/Navbar/NavbarMobile.jsx
@@ -1,16 +1,16 @@
-import Image from 'next/image';
-import MobileView from '../../views/MobileView';
-import Link from '../Link/Link';
+import useSidebar from '@/core/hooks/useSidebar';
+import { getCountCart } from '@/core/utils/cart';
+import IndoteknikLogo from '@/images/logo.png';
import {
Bars3Icon,
HeartIcon,
ShoppingCartIcon,
} from '@heroicons/react/24/outline';
-import useSidebar from '@/core/hooks/useSidebar';
import dynamic from 'next/dynamic';
-import IndoteknikLogo from '@/images/logo.png';
+import Image from 'next/image';
import { useEffect, useState } from 'react';
-import { getCart, getCountCart } from '@/core/utils/cart';
+import MobileView from '../../views/MobileView';
+import Link from '../Link/Link';
// import TopBanner from './TopBanner';
const Search = dynamic(() => import('./Search'));
diff --git a/src/core/components/layouts/BasicLayout.jsx b/src/core/components/layouts/BasicLayout.jsx
index 2962a08b..b6e2c59f 100644
--- a/src/core/components/layouts/BasicLayout.jsx
+++ b/src/core/components/layouts/BasicLayout.jsx
@@ -1,15 +1,14 @@
import dynamic from 'next/dynamic';
import Image from 'next/image';
import { useEffect, useState } from 'react';
-import axios from 'axios';
+import { useProductContext } from '@/contexts/ProductContext';
import whatsappUrl from '@/core/utils/whatsappUrl';
-import odooApi from '@/core/api/odooApi';
import { useRouter } from 'next/router';
-import { useProductContext } from '@/contexts/ProductContext';
const Navbar = dynamic(() => import('../elements/Navbar/Navbar'), {
ssr: false,
+ loading: () => <div className='h-[156px]' />,
});
const AnimationLayout = dynamic(() => import('./AnimationLayout'), {
ssr: false,
@@ -42,20 +41,20 @@ const BasicLayout = ({ children }) => {
}
}, [product, router]);
- useEffect(() => {
- const getIP = async () => {
- const ip = await odooApi('GET', '/api/ip-address');
- const data = {
- page_title: document.title,
- url: window.location.href,
- ip: ip,
- };
- axios.get(
- `/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`
- );
- };
- getIP();
- }, []);
+ // useEffect(() => {
+ // const getIP = async () => {
+ // const ip = await odooApi('GET', '/api/ip-address');
+ // const data = {
+ // page_title: document.title,
+ // url: window.location.href,
+ // ip: ip,
+ // };
+ // axios.get(
+ // `/api/user-activity?page_title=${data.page_title}&url=${data.url}&ip=${data.ip}`
+ // );
+ // };
+ // getIP();
+ // }, []);
return (
<>
<Navbar />
diff --git a/src/core/utils/slug.js b/src/core/utils/slug.js
index e91bcf83..19c7b115 100644
--- a/src/core/utils/slug.js
+++ b/src/core/utils/slug.js
@@ -1,4 +1,4 @@
-import toTitleCase from './toTitleCase'
+import toTitleCase from './toTitleCase';
/**
* Creates a slug from input parameters by converting the name and appending it with an ID.
@@ -10,19 +10,20 @@ import toTitleCase from './toTitleCase'
* @returns {string} - The generated slug with the prefix, name, and ID.
*/
const createSlug = (prefix, name, id, withHost = false) => {
+ name ||= '';
let slug =
name
?.trim()
.replace(new RegExp(/[^A-Za-z0-9]/, 'g'), '-')
.toLowerCase() +
'-' +
- id
- let splitSlug = slug.split('-')
- let filterSlugFromEmptyChar = splitSlug.filter((x) => x != '')
- slug = prefix + filterSlugFromEmptyChar.join('-')
- if (withHost) slug = process.env.NEXT_PUBLIC_SELF_HOST + slug
- return slug
-}
+ id;
+ let splitSlug = slug.split('-');
+ let filterSlugFromEmptyChar = splitSlug.filter((x) => x != '');
+ slug = prefix + filterSlugFromEmptyChar.join('-');
+ if (withHost) slug = process.env.NEXT_PUBLIC_SELF_HOST + slug;
+ return slug;
+};
/**
* Extracts the ID from a slug.
@@ -32,9 +33,9 @@ const createSlug = (prefix, name, id, withHost = false) => {
* @returns {string} - The extracted ID from the slug.
*/
const getIdFromSlug = (slug) => {
- let id = slug.split('-')
- return id[id.length - 1]
-}
+ let id = slug.split('-');
+ return id[id.length - 1];
+};
/**
* Extracts the name from a slug.
@@ -45,9 +46,10 @@ const getIdFromSlug = (slug) => {
* @returns {string} - The extracted name from the slug in title case.
*/
const getNameFromSlug = (slug) => {
- let name = slug.split('-')
- name.pop()
- return toTitleCase(name.join(' '))
-}
+ let name = slug.split('-');
+ name.pop();
+ return toTitleCase(name.join(' '));
+};
+
+export { createSlug, getIdFromSlug, getNameFromSlug };
-export { createSlug, getIdFromSlug, getNameFromSlug }