summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-11-29 10:55:52 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-11-29 10:55:52 +0700
commitac83b0ea5afd82194f38fbc913678e16a81b5c2c (patch)
tree4373da17bcb43d752b7bd888e28ba906099a19aa /src/pages
parentc7b437cd0541cde9e2a829ec3c5689dc237505a8 (diff)
parentb4861f70338adb3960125923a7e6e4032279c88e (diff)
Merge branch 'new-release' into Feature/pengajuan-tempo
# Conflicts: # src/lib/auth/components/Menu.jsx # src/pages/my/menu.jsx
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/api/flashsale-header.js40
-rw-r--r--src/pages/api/search-flashsale.js45
-rw-r--r--src/pages/my/menu.jsx4
3 files changed, 87 insertions, 2 deletions
diff --git a/src/pages/api/flashsale-header.js b/src/pages/api/flashsale-header.js
new file mode 100644
index 00000000..31f8efdd
--- /dev/null
+++ b/src/pages/api/flashsale-header.js
@@ -0,0 +1,40 @@
+import odooApi from '@/core/api/odooApi';
+import { createClient } from 'redis';
+
+const client = createClient();
+
+client.on('error', (err) => console.error('Redis Client Error', err));
+
+const connectRedis = async () => {
+ if (!client.isOpen) {
+ await client.connect();
+ }
+};
+
+export default async function handler(req, res) {
+ try {
+ await connectRedis();
+ const cacheKey = `flashsale_header`;
+ // await client.del(cacheKey);
+ let cachedData = await client.get(cacheKey);
+
+ if (cachedData) {
+ const data = JSON.parse(cachedData);
+ return res.status(200).json({ data });
+ } else {
+ const flashSale = await odooApi('GET', `/api/v1/flashsale/header`);
+
+ await client.set(
+ cacheKey,
+ JSON.stringify(flashSale),
+ 'EX',
+ flashSale.duration
+ );
+ cachedData = await client.get(cacheKey);
+ return res.status(200).json({ data: cachedData });
+ }
+ } catch (error) {
+ console.error('Error interacting with Redis or fetching data:', error);
+ return res.status(500).json({ error: 'Internal Server Error' });
+ }
+}
diff --git a/src/pages/api/search-flashsale.js b/src/pages/api/search-flashsale.js
new file mode 100644
index 00000000..d9e56c83
--- /dev/null
+++ b/src/pages/api/search-flashsale.js
@@ -0,0 +1,45 @@
+import odooApi from '@/core/api/odooApi';
+import { createClient } from 'redis';
+import _ from 'lodash-contrib';
+import axios from 'axios';
+
+const client = createClient();
+
+client.on('error', (err) => console.error('Redis Client Error', err));
+
+const connectRedis = async () => {
+ if (!client.isOpen) {
+ await client.connect();
+ }
+};
+
+export default async function handler(req, res) {
+ const { query, operation, duration } = req.query;
+ try {
+ await connectRedis();
+ const cacheKey = `flashsale_product`;
+ // await client.del(cacheKey);
+ let cachedData = await client.get(cacheKey);
+
+ if (cachedData) {
+ const data = JSON.parse(cachedData);
+ return res.status(200).json({ data });
+ } else {
+ const dataProductSearch = await axios(
+ `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?${query}&operation=${operation}]`
+ );
+
+ await client.set(
+ cacheKey,
+ JSON.stringify(dataProductSearch.data),
+ 'EX',
+ duration
+ );
+ cachedData = await client.get(cacheKey);
+ return res.status(200).json({ data: cachedData });
+ }
+ } catch (error) {
+ console.error('Error interacting with Redis or fetching data:', error);
+ return res.status(500).json({ error: 'Internal Server Error' });
+ }
+}
diff --git a/src/pages/my/menu.jsx b/src/pages/my/menu.jsx
index 63b4d35c..407e400f 100644
--- a/src/pages/my/menu.jsx
+++ b/src/pages/my/menu.jsx
@@ -8,7 +8,7 @@ import { ChevronRightIcon, UserIcon } from '@heroicons/react/24/solid';
import { signOut, useSession } from 'next-auth/react';
import { useRouter } from 'next/router';
import ImageNext from 'next/image';
-
+import whatsappUrl from '@/core/utils/whatsappUrl';
export default function Menu() {
const auth = useAuth();
const router = useRouter();
@@ -118,7 +118,7 @@ export default function Menu() {
<MenuHeader>Pusat Bantuan</MenuHeader>
<div className='divide-y divide-gray_r-6 border-y border-gray_r-6 mt-4'>
- <LinkItem href='/'>
+ <LinkItem href={whatsappUrl('', '', '')}>
{' '}
<div className='flex gap-x-3 items-center'>
<ImageNext