summaryrefslogtreecommitdiff
path: root/src/core/utils
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-07-10 15:58:51 +0700
commit2e3c726bc8217f3960cfecec44b81303b03de72b (patch)
tree1b85ced7f61f3e4c3f1f27b577b37aa161615065 /src/core/utils
parent2b3bd9c0a454dbad69ce29cee877bfb1fca5dfa6 (diff)
parenta99bf6480eea556e53b85e6db45f3b8c2361e693 (diff)
Merge branch 'release' into development
# Conflicts: # src/pages/shop/product/variant/[slug].jsx
Diffstat (limited to 'src/core/utils')
-rw-r--r--src/core/utils/auth.js2
-rw-r--r--src/core/utils/googleTag.js26
-rw-r--r--src/core/utils/slug.js34
-rw-r--r--src/core/utils/whatsappUrl.js2
4 files changed, 45 insertions, 19 deletions
diff --git a/src/core/utils/auth.js b/src/core/utils/auth.js
index a7244747..03b20ae2 100644
--- a/src/core/utils/auth.js
+++ b/src/core/utils/auth.js
@@ -29,7 +29,7 @@ const setAuth = (user) => {
* @returns {boolean} - Returns `true`.
*/
const deleteAuth = async() => {
- // await signOut()
+ await signOut()
deleteCookie('auth')
return true
}
diff --git a/src/core/utils/googleTag.js b/src/core/utils/googleTag.js
index 6d7476bd..96a6bd2e 100644
--- a/src/core/utils/googleTag.js
+++ b/src/core/utils/googleTag.js
@@ -2,7 +2,7 @@ const mapVariants = (variants) => {
return variants.map((variant) => {
const res = {
item_id: variant.id,
- item_name: variant.parent.name,
+ item_name: variant.name,
discount: variant.price.price - variant.price.priceDiscount,
item_brand: variant.manufacture?.name,
item_variant: variant.code || variant.id,
@@ -33,6 +33,20 @@ const sumTotal = (variants) => {
}
}
+const mapProducts = (product) => {
+ const res = {
+ item_id: product.id,
+ item_name: product.name,
+ discount: product.lowest_price.price_discount || 0,
+ // index: 0,
+ item_brand: product.manufacture.name,
+ item_category: product.categories,
+ item_variant: product.variants,
+ price: product.lowest_price.price,
+ quantity: product.stock_total
+ }
+ return res
+}
export const gtagAddToCart = (variant, quantity) => {
const param = {
currency: 'IDR',
@@ -77,3 +91,13 @@ export const gtagPurchase = (variants, shipping, transactionId) => {
}
gtag('event', 'purchase', param)
}
+
+export const gtagProductDetail = (product) => {
+ const items = mapProducts(product)
+ const param = {
+ currency: 'IDR',
+ value: product.id,
+ items
+ }
+ gtag('event', 'view_item', param)
+} \ No newline at end of file
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 }
diff --git a/src/core/utils/whatsappUrl.js b/src/core/utils/whatsappUrl.js
index 9a92f424..7a129aa6 100644
--- a/src/core/utils/whatsappUrl.js
+++ b/src/core/utils/whatsappUrl.js
@@ -7,7 +7,7 @@ const whatsappUrl = (template = 'default', payload, urlPath = null) => {
if(!urlPath) return '/login'
}
let parentName = user.parentName || '-'
- let url = 'https://wa.me/628128080622'
+ let url = 'https://wa.me/6281717181922'
let text = 'Hallo Indoteknik.com,'
switch (template) {
case 'product':