From 092dc7fc49246580023a8b97101d51845c81bf04 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 31 Mar 2023 11:17:55 +0700 Subject: iframe content --- src/core/api/odooApi.js | 4 +-- src/core/components/elements/Link/Link.jsx | 10 +++++++- src/core/components/elements/Popup/BottomPopup.jsx | 6 ++--- src/lib/content/components/PageContent.jsx | 2 +- src/lib/iframe/components/IframeContent.jsx | 30 ++++++++++++++++++++++ src/lib/invoice/utils/invoices.js | 4 +-- src/lib/transaction/components/Transaction.jsx | 6 ++--- src/lib/transaction/utils/transactions.js | 4 +-- src/pages/about-us.jsx | 8 +++--- src/pages/blog/[slug].jsx | 2 +- src/pages/shop/search.jsx | 2 +- 11 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 src/lib/iframe/components/IframeContent.jsx (limited to 'src') diff --git a/src/core/api/odooApi.js b/src/core/api/odooApi.js index 41460fda..25ee9adf 100644 --- a/src/core/api/odooApi.js +++ b/src/core/api/odooApi.js @@ -4,7 +4,7 @@ import { getCookie, setCookie } from 'cookies-next' import { getAuth } from '../utils/auth' const renewToken = async () => { - let token = await axios.get(process.env.NEXT_PUBLIC_ODOO_HOST + '/api/token') + let token = await axios.get(process.env.NEXT_PUBLIC_ODOO_API_HOST + '/api/token') setCookie('token', token.data.result) return token.data.result } @@ -26,7 +26,7 @@ const odooApi = async (method, url, data = {}, headers = {}) => { let axiosParameter = { method, - url: process.env.NEXT_PUBLIC_ODOO_HOST + url, + url: process.env.NEXT_PUBLIC_ODOO_API_HOST + url, headers: { Authorization: token, ...headers } } if (auth) axiosParameter.headers['Token'] = auth.token diff --git a/src/core/components/elements/Link/Link.jsx b/src/core/components/elements/Link/Link.jsx index 75fc6ca8..557abbc4 100644 --- a/src/core/components/elements/Link/Link.jsx +++ b/src/core/components/elements/Link/Link.jsx @@ -1,10 +1,18 @@ import NextLink from 'next/link' +import { useRouter } from 'next/router' +import { useEffect } from 'react' const Link = ({ children, ...props }) => { + const router = useRouter() + + useEffect(() => { + router.events.on('routeChangeStart', () => window.scrollTo({ top: 0, behavior: 'smooth' })) + }, [router]) + return ( window.scrollTo({ top: 0, behavior: 'smooth' })} + // onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })} scroll={false} className={`block font-medium text-red_r-11 ${props?.className || ''}`} > diff --git a/src/core/components/elements/Popup/BottomPopup.jsx b/src/core/components/elements/Popup/BottomPopup.jsx index 1fc77932..5e9f68c7 100644 --- a/src/core/components/elements/Popup/BottomPopup.jsx +++ b/src/core/components/elements/Popup/BottomPopup.jsx @@ -49,9 +49,9 @@ const BottomPopup = ({ children, active = false, title, close }) => { diff --git a/src/lib/content/components/PageContent.jsx b/src/lib/content/components/PageContent.jsx index f7c2f467..bb44dd92 100644 --- a/src/lib/content/components/PageContent.jsx +++ b/src/lib/content/components/PageContent.jsx @@ -10,7 +10,7 @@ const PageContent = ({ path }) => { let parsedContent = content.data.content parsedContent = parsedContent.replaceAll( 'src="/web/image', - `src="${process.env.NEXT_PUBLIC_ODOO_HOST}/web/image` + `src="${process.env.NEXT_PUBLIC_ODOO_API_HOST}/web/image` ) const contentClassNames = ` prose diff --git a/src/lib/iframe/components/IframeContent.jsx b/src/lib/iframe/components/IframeContent.jsx new file mode 100644 index 00000000..52f2a26e --- /dev/null +++ b/src/lib/iframe/components/IframeContent.jsx @@ -0,0 +1,30 @@ +import { useEffect, useRef, useState } from 'react' + +const IframeContent = ({ url }) => { + const [iframeLoaded, setIframeLoaded] = useState(false) + const [iframe, setIframe] = useState(null) + const iframeRef = useRef(null) + + useEffect(() => { + if (iframeLoaded) { + setIframe({ + height: document.querySelector('main').offsetHeight + }) + } + }, [iframeLoaded]) + + return ( +
+