diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/auth/components/Activate.jsx | 2 | ||||
| -rw-r--r-- | src/lib/auth/components/Register.jsx | 2 | ||||
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 58 | ||||
| -rw-r--r-- | src/lib/home/api/popularProductApi.js | 2 | ||||
| -rw-r--r-- | src/lib/home/hooks/useCategoryHome.js | 4 | ||||
| -rw-r--r-- | src/lib/invoice/utils/invoices.js | 4 | ||||
| -rw-r--r-- | src/lib/product/api/productSearchApi.js | 2 | ||||
| -rw-r--r-- | src/lib/product/api/productSimilarApi.js | 2 | ||||
| -rw-r--r-- | src/lib/transaction/utils/transactions.js | 4 |
9 files changed, 28 insertions, 52 deletions
diff --git a/src/lib/auth/components/Activate.jsx b/src/lib/auth/components/Activate.jsx index 7970524c..f67cc168 100644 --- a/src/lib/auth/components/Activate.jsx +++ b/src/lib/auth/components/Activate.jsx @@ -67,7 +67,7 @@ const Activate = () => { const activationRequest = async (e) => { e.preventDefault() setIsLoading(true) - let activationRequest = await axios.post(`${process.env.SELF_HOST}/api/activation-request`, { + let activationRequest = await axios.post(`${process.env.NEXT_PUBLIC_SELF_HOST}/api/activation-request`, { email }) if (activationRequest.data.activationRequest) { diff --git a/src/lib/auth/components/Register.jsx b/src/lib/auth/components/Register.jsx index d02081ce..82b81b52 100644 --- a/src/lib/auth/components/Register.jsx +++ b/src/lib/auth/components/Register.jsx @@ -27,7 +27,7 @@ const Register = () => { const isRegistered = await registerApi({ data }) setIsLoading(false) if (isRegistered.register) { - await axios.post(`${process.env.SELF_HOST}/api/activation-request`, { email }) + await axios.post(`${process.env.NEXT_PUBLIC_SELF_HOST}/api/activation-request`, { email }) setAlert({ children: 'Berhasil mendaftarkan akun anda, cek email untuk melakukan aktivasi akun', type: 'success' diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index f6170b13..42608cef 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -5,7 +5,6 @@ import useAuth from '@/core/hooks/useAuth' import { getItemAddress } from '@/core/utils/address' import addressesApi from '@/lib/address/api/addressesApi' import CartApi from '@/lib/cart/api/CartApi' -import VariantCard from '@/lib/variant/components/VariantCard' import { ExclamationCircleIcon } from '@heroicons/react/24/outline' import { useEffect, useRef, useState } from 'react' import _ from 'lodash' @@ -16,6 +15,8 @@ import getFileBase64 from '@/core/utils/getFileBase64' import checkoutApi from '../api/checkoutApi' import { useRouter } from 'next/router' import VariantGroupCard from '@/lib/variant/components/VariantGroupCard' +import axios from 'axios' +import Script from 'next/script' const Checkout = () => { const router = useRouter() @@ -89,18 +90,12 @@ const Checkout = () => { } }, [products]) - const [selectedPayment, setSelectedPayment] = useState(null) - const poNumber = useRef('') const poFile = useRef('') const [isLoading, setIsLoading] = useState(false) const checkout = async () => { - if (!selectedPayment) { - toast.error('Pilih metode pembayaran', { position: 'bottom-center' }) - return - } const file = poFile.current.files[0] if (typeof file !== 'undefined' && file.size > 5000000) { toast.error('Maksimal ukuran file adalah 5MB', { position: 'bottom-center' }) @@ -122,12 +117,16 @@ const Checkout = () => { const isCheckouted = await checkoutApi({ data }) setIsLoading(false) - if (isCheckouted?.id) { - for (const product of products) deleteItemCart({ productId: product.id }) - router.push(`/shop/checkout/finish?id=${isCheckouted.id}`) + if (!isCheckouted?.id) { + toast.error('Gagal melakukan transaksi, terjadi kesalahan internal') return } - toast.error('Gagal melakukan transaksi, terjadi kesalahan internal') + + const payment = await axios.post( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}` + ) + for (const product of products) deleteItemCart({ productId: product.id }) + window.snap.pay(payment.data.token) } return ( @@ -223,32 +222,6 @@ const Checkout = () => { <Divider /> <div className='p-4'> - <div className='font-medium'> - Metode Pembayaran <span className='font-normal text-gray_r-11'>(Wajib dipilih)</span> - </div> - <div className='grid gap-y-3 mt-4'> - {payments.map((payment, index) => ( - <button - type='button' - className={ - 'text-left border border-gray_r-6 rounded-md p-3 ' + - (selectedPayment == payment.name && 'border-yellow_r-10 bg-yellow_r-3') - } - onClick={() => setSelectedPayment(payment.name)} - key={index} - > - <p> - {payment.name} - {payment.number} - </p> - <p className='mt-1 text-gray_r-11'>PT. Indoteknik Dotcom Gemilang</p> - </button> - ))} - </div> - </div> - - <Divider /> - - <div className='p-4'> <div className='font-medium'>Purchase Order</div> <div className='mt-4 flex gap-x-3'> @@ -284,15 +257,16 @@ const Checkout = () => { {isLoading ? 'Loading...' : 'Bayar'} </button> </div> + + <Script + async + src='https://app.sandbox.midtrans.com/snap/snap.js' + data-client-key='' + /> </> ) } -const payments = [ - { name: 'BCA', number: '8870-4000-81' }, - { name: 'MANDIRI', number: '155-0067-6869-75' } -] - const SectionAddress = ({ address, label, url }) => ( <div className='p-4'> <div className='flex justify-between items-center'> diff --git a/src/lib/home/api/popularProductApi.js b/src/lib/home/api/popularProductApi.js index 5a6d3212..37e4390e 100644 --- a/src/lib/home/api/popularProductApi.js +++ b/src/lib/home/api/popularProductApi.js @@ -2,7 +2,7 @@ import axios from 'axios' const popularProductApi = async () => { const dataPopularProducts = await axios( - `${process.env.SELF_HOST}/api/shop/search?q=*&page=1&orderBy=popular` + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=1&orderBy=popular` ) return dataPopularProducts.data.response } diff --git a/src/lib/home/hooks/useCategoryHome.js b/src/lib/home/hooks/useCategoryHome.js index cfaa3d9c..ea9f8d6a 100644 --- a/src/lib/home/hooks/useCategoryHome.js +++ b/src/lib/home/hooks/useCategoryHome.js @@ -3,7 +3,9 @@ import { useQuery } from 'react-query' const useCategoryHome = ({ id }) => { const fetchCategoryHome = async () => await categoryHomeApi({ id }) - const { isLoading, data } = useQuery(`categoryHome-${id}`, fetchCategoryHome) + const { isLoading, data } = useQuery(`categoryHome-${id}`, fetchCategoryHome, { + refetchOnWindowFocus: false + }) return { categoryHome: { data, isLoading } diff --git a/src/lib/invoice/utils/invoices.js b/src/lib/invoice/utils/invoices.js index 221e53cf..63fe91f6 100644 --- a/src/lib/invoice/utils/invoices.js +++ b/src/lib/invoice/utils/invoices.js @@ -1,10 +1,10 @@ const downloadInvoice = (invoice) => { - const url = `${process.env.ODOO_HOST}/api/v1/download/invoice/${invoice.id}/${invoice.token}` + const url = `${process.env.NEXT_PUBLIC_ODOO_HOST}/api/v1/download/invoice/${invoice.id}/${invoice.token}` window.open(url, 'download') } const downloadTaxInvoice = (invoice) => { - const url = `${process.env.ODOO_HOST}/api/v1/download/tax-invoice/${invoice.id}/${invoice.token}` + const url = `${process.env.NEXT_PUBLIC_ODOO_HOST}/api/v1/download/tax-invoice/${invoice.id}/${invoice.token}` window.open(url, 'download') } diff --git a/src/lib/product/api/productSearchApi.js b/src/lib/product/api/productSearchApi.js index b9acd94b..e7ad49a6 100644 --- a/src/lib/product/api/productSearchApi.js +++ b/src/lib/product/api/productSearchApi.js @@ -2,7 +2,7 @@ import _ from 'lodash-contrib' import axios from 'axios' const productSearchApi = async ({ query }) => { - const dataProductSearch = await axios(`${process.env.SELF_HOST}/api/shop/search?${query}`) + const dataProductSearch = await axios(`${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?${query}`) return dataProductSearch.data } diff --git a/src/lib/product/api/productSimilarApi.js b/src/lib/product/api/productSimilarApi.js index 7142fab4..8fd17ab9 100644 --- a/src/lib/product/api/productSimilarApi.js +++ b/src/lib/product/api/productSimilarApi.js @@ -2,7 +2,7 @@ import axios from 'axios' const productSimilarApi = async ({ query }) => { const dataProductSimilar = await axios( - `${process.env.SELF_HOST}/api/shop/search?q=${query}&page=1&orderBy=popular` + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=${query}&page=1&orderBy=popular` ) return dataProductSimilar.data.response } diff --git a/src/lib/transaction/utils/transactions.js b/src/lib/transaction/utils/transactions.js index 4c7522be..ef2f8d97 100644 --- a/src/lib/transaction/utils/transactions.js +++ b/src/lib/transaction/utils/transactions.js @@ -2,13 +2,13 @@ import { getAuth } from '@/core/utils/auth' const downloadPurchaseOrder = (transaction) => { const auth = getAuth() - const url = `${process.env.ODOO_HOST}/api/v1/partner/${auth.partnerId}/sale_order/${transaction.id}/download_po/${transaction.token}` + const url = `${process.env.NEXT_PUBLIC_ODOO_HOST}/api/v1/partner/${auth.partnerId}/sale_order/${transaction.id}/download_po/${transaction.token}` window.open(url, 'download') } const downloadQuotation = (transaction) => { const auth = getAuth() - const url = `${process.env.ODOO_HOST}/api/v1/partner/${auth.partnerId}/sale_order/${transaction.id}/download/${transaction.token}` + const url = `${process.env.NEXT_PUBLIC_ODOO_HOST}/api/v1/partner/${auth.partnerId}/sale_order/${transaction.id}/download/${transaction.token}` window.open(url, 'download') } |
