From 321e0c09be4b26d72b470407217262d10c88089d Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 22:57:48 +0700 Subject: fix --- src/lib/auth/api/editPersonalProfileApi.js | 10 +++ src/lib/auth/components/CompanyProfile.jsx | 97 +++++++++++++++++++++++ src/lib/auth/components/PersonalProfile.jsx | 115 ++++++++++++++++++++++++++++ src/lib/cart/components/Cart.jsx | 70 ++++++++--------- 4 files changed, 257 insertions(+), 35 deletions(-) create mode 100644 src/lib/auth/api/editPersonalProfileApi.js create mode 100644 src/lib/auth/components/CompanyProfile.jsx create mode 100644 src/lib/auth/components/PersonalProfile.jsx (limited to 'src/lib') diff --git a/src/lib/auth/api/editPersonalProfileApi.js b/src/lib/auth/api/editPersonalProfileApi.js new file mode 100644 index 00000000..af2ad4b2 --- /dev/null +++ b/src/lib/auth/api/editPersonalProfileApi.js @@ -0,0 +1,10 @@ +import odooApi from "@/core/api/odooApi" +import { getAuth } from "@/core/utils/auth" + +const editPersonalProfileApi = async ({ data }) => { + const auth = getAuth() + const dataProfile = await odooApi('PUT', `/api/v1/user/${auth.id}`, data) + return dataProfile +} + +export default editPersonalProfileApi \ No newline at end of file diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx new file mode 100644 index 00000000..d66a0209 --- /dev/null +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -0,0 +1,97 @@ +import useAuth from '@/core/hooks/useAuth' +import addressApi from '@/lib/address/api/addressApi' +import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline' +import { useEffect, useState } from 'react' +import { useForm } from 'react-hook-form' + +const PersonalProfile = () => { + const auth = useAuth() + const [isOpen, setIsOpen] = useState(false) + const toggle = () => setIsOpen(!isOpen) + const { register, setValue } = useForm({ + defaultValues: { + email: '', + name: '', + mobile: '', + password: '' + } + }) + + useEffect(() => { + const loadProfile = async () => { + const dataProfile = await addressApi({ id: auth.partnerId }) + setValue('email', dataProfile?.email) + setValue('name', dataProfile?.name) + setValue('mobile', dataProfile?.mobile) + } + if (auth) loadProfile() + }, [auth, setValue]) + + return ( + <> + + + {isOpen && ( +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ )} + + ) +} + +export default PersonalProfile diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx new file mode 100644 index 00000000..29628be9 --- /dev/null +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -0,0 +1,115 @@ +import useAuth from '@/core/hooks/useAuth' +import { setAuth } from '@/core/utils/auth' +import addressApi from '@/lib/address/api/addressApi' +import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline' +import { useEffect, useState } from 'react' +import { useForm } from 'react-hook-form' +import { toast } from 'react-hot-toast' +import editPersonalProfileApi from '../api/editPersonalProfileApi' + +const PersonalProfile = () => { + const auth = useAuth() + const [isOpen, setIsOpen] = useState(false) + const toggle = () => setIsOpen(!isOpen) + const { register, setValue, handleSubmit } = useForm({ + defaultValues: { + email: '', + name: '', + mobile: '', + password: '' + } + }) + + useEffect(() => { + const loadProfile = async () => { + const dataProfile = await addressApi({ id: auth.partnerId }) + setValue('email', dataProfile?.email) + setValue('name', dataProfile?.name) + setValue('mobile', dataProfile?.mobile) + } + if (auth) loadProfile() + }, [auth, setValue]) + + const onSubmitHandler = async (values) => { + let data = values + if (!values.password) delete data.password + const isUpdated = await editPersonalProfileApi({ data }) + console.log(isUpdated) + if (isUpdated?.user) { + setAuth(isUpdated.user) + setValue('password', '') + setIsOpen(false) + toast.success('Berhasil mengubah profil', { duration: 1500 }) + return + } + toast.error('Terjadi kesalahan internal') + } + + return ( + <> + + + {isOpen && ( +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ )} + + ) +} + +export default PersonalProfile diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index 2d94ac0b..af2bec78 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -103,7 +103,7 @@ const Cart = () => { const selectedProduct = () => { if (!products) return [] - return products.filter((product) => product.selected == true) + return products?.filter((product) => product.selected == true) } const deleteProduct = (productId) => { @@ -115,27 +115,27 @@ const Cart = () => { } return ( -
+

Daftar Produk Belanja

Cari Produk Lain
-
+
{cart.isLoading && (
)} - {!cart.isLoading && !products && ( - + {!cart.isLoading && (!products || products?.length == 0) && ( + Keranjang belanja anda masih kosong )} {products?.map((product) => ( -
+
))} -
-
-
-
- Total: - -   - {selectedProduct().length > 0 - ? currencyFormat(totalPriceBeforeTax - totalDiscountAmount + totalTaxAmount) - : '-'} - +
+
+
+ Total: + +   + {selectedProduct().length > 0 + ? currencyFormat(totalPriceBeforeTax - totalDiscountAmount + totalTaxAmount) + : '-'} + +
+
+
+ +
-
-
- -
-- cgit v1.2.3 From 89d99c0386750af7a29678344fe0ed8fb6435d4f Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 22:58:00 +0700 Subject: fix --- src/lib/auth/components/PersonalProfile.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx index 29628be9..46253ef1 100644 --- a/src/lib/auth/components/PersonalProfile.jsx +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -65,7 +65,10 @@ const PersonalProfile = () => { {isOpen && ( -
+
Date: Wed, 22 Feb 2023 23:05:10 +0700 Subject: fix --- src/lib/auth/components/PersonalProfile.jsx | 2 +- src/lib/cart/components/Cart.jsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx index 46253ef1..0b387f2e 100644 --- a/src/lib/auth/components/PersonalProfile.jsx +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -90,7 +90,7 @@ const PersonalProfile = () => {
diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index af2bec78..d0408ddf 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -129,9 +129,11 @@ const Cart = () => { )} {!cart.isLoading && (!products || products?.length == 0) && ( - - Keranjang belanja anda masih kosong - +
+ + Keranjang belanja anda masih kosong + +
)} {products?.map((product) => ( @@ -154,7 +156,7 @@ const Cart = () => { className='object-contain object-center border border-gray_r-6 h-40 w-full rounded-md' /> -
+
Date: Wed, 22 Feb 2023 23:34:50 +0700 Subject: fix --- src/lib/product/components/Product.jsx | 81 ++++++++++++++++++++--- src/lib/product/components/ProductCard.jsx | 20 ++++-- src/lib/wishlist/api/createOrDeleteWishlistApi.js | 10 +++ src/lib/wishlist/api/wishlistApi.js | 14 ++++ src/lib/wishlist/hooks/useWishlist.js | 13 ++++ 5 files changed, 122 insertions(+), 16 deletions(-) create mode 100644 src/lib/wishlist/api/createOrDeleteWishlistApi.js create mode 100644 src/lib/wishlist/api/wishlistApi.js create mode 100644 src/lib/wishlist/hooks/useWishlist.js (limited to 'src/lib') diff --git a/src/lib/product/components/Product.jsx b/src/lib/product/components/Product.jsx index 2181c38e..9e33316c 100644 --- a/src/lib/product/components/Product.jsx +++ b/src/lib/product/components/Product.jsx @@ -9,6 +9,11 @@ import ProductSimilar from './ProductSimilar' import LazyLoad from 'react-lazy-load' import { toast } from 'react-hot-toast' import { updateItemCart } from '@/core/utils/cart' +import useWishlist from '@/lib/wishlist/hooks/useWishlist' +import { HeartIcon } from '@heroicons/react/24/outline' +import useAuth from '@/core/hooks/useAuth' +import { useRouter } from 'next/router' +import createOrDeleteWishlistApi from '@/lib/wishlist/api/createOrDeleteWishlistApi' const informationTabOptions = [ { value: 'specification', label: 'Spesifikasi' }, @@ -17,6 +22,9 @@ const informationTabOptions = [ ] const Product = ({ product }) => { + const auth = useAuth() + const router = useRouter() + const { wishlist } = useWishlist({ productId: product?.id }) const [quantity, setQuantity] = useState('1') const [selectedVariant, setSelectedVariant] = useState(null) const [informationTab, setInformationTab] = useState(null) @@ -82,6 +90,21 @@ const Product = ({ product }) => { toast.success('Berhasil menambahkan ke keranjang') } + const toggleWishlist = async () => { + if (!auth) { + router.push('/login') + return + } + const data = { product_id: product.id } + await createOrDeleteWishlistApi({ data }) + if (wishlist.data.productTotal > 0) { + toast.success('Berhasil menghapus dari wishlist') + } else { + toast.success('Berhasil menambahkan ke wishlist') + } + wishlist.refetch() + } + return ( <> { />
- - {product.manufacture?.name} - +
+ {product.manufacture?.name ? ( + {product.manufacture?.name} + ) : ( +
-
+ )} + +

{activeVariant?.name}

{activeVariant?.price?.discountPercentage > 0 && (
@@ -109,7 +147,10 @@ const Product = ({ product }) => { ) : ( Hubungi kami untuk dapatkan harga terbaik,  - + klik disini @@ -146,10 +187,17 @@ const Product = ({ product }) => { onChange={(e) => setQuantity(e.target.value)} />
- -
@@ -193,7 +241,10 @@ const Product = ({ product }) => { )} {activeVariant?.stock == 0 && ( - + Tanya Stok )} @@ -201,7 +252,10 @@ const Product = ({ product }) => { {activeVariant?.weight > 0 && {activeVariant?.weight} KG} {activeVariant?.weight == 0 && ( - + Tanya Berat )} @@ -232,14 +286,21 @@ const Product = ({ product }) => { const TabButton = ({ children, active, ...props }) => { const activeClassName = active ? 'text-red_r-11 underline underline-offset-4' : 'text-gray_r-11' return ( - ) } const TabContent = ({ children, active, className, ...props }) => ( -
+
{children}
) diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index dd221e4f..6b88a3bd 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -23,12 +23,20 @@ const ProductCard = ({ product, simpleTitle }) => { )}
- - {product?.manufacture?.name} - + {product?.manufacture?.name ? ( + + {product.manufacture.name} + + ) : ( +
-
+ )} { + const auth = getAuth() + const dataWishlist = await odooApi('POST', `/api/v1/user/${auth.id}/wishlist/create-or-delete`, data) + return dataWishlist +} + +export default createOrDeleteWishlistApi \ No newline at end of file diff --git a/src/lib/wishlist/api/wishlistApi.js b/src/lib/wishlist/api/wishlistApi.js new file mode 100644 index 00000000..a8906dd4 --- /dev/null +++ b/src/lib/wishlist/api/wishlistApi.js @@ -0,0 +1,14 @@ +import odooApi from '@/core/api/odooApi' +import { getAuth } from '@/core/utils/auth' + +const wishlistApi = async ({ productId }) => { + const auth = getAuth() + if (!auth) return { productTotal: 0, products: [] } + const dataWishlist = await odooApi( + 'GET', + `/api/v1/user/${auth.id}/wishlist?product_id=${productId}` + ) + return dataWishlist +} + +export default wishlistApi diff --git a/src/lib/wishlist/hooks/useWishlist.js b/src/lib/wishlist/hooks/useWishlist.js new file mode 100644 index 00000000..1eb17d53 --- /dev/null +++ b/src/lib/wishlist/hooks/useWishlist.js @@ -0,0 +1,13 @@ +import { useQuery } from "react-query" +import wishlistApi from "../api/wishlistApi" + +const useWishlist = ({ productId }) => { + const fetchWishlist = async () => await wishlistApi({ productId }) + const { data, isLoading, refetch } = useQuery(`wishlist-${productId}`, fetchWishlist) + + return { + wishlist: { data, isLoading, refetch } + } +} + +export default useWishlist -- cgit v1.2.3 From ac3fdf7be9982e65d8f83a20bc487f8dd62e3bfc Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 23:36:47 +0700 Subject: fix --- src/lib/address/components/CreateAddress.jsx | 58 +++++++++++++++++---- src/lib/address/components/EditAddress.jsx | 58 +++++++++++++++++---- src/lib/auth/api/editPersonalProfileApi.js | 6 +-- src/lib/auth/components/Login.jsx | 27 ++++++++-- src/lib/auth/components/Register.jsx | 17 +++++-- src/lib/brand/components/BrandCard.jsx | 6 ++- src/lib/cart/components/Cart.jsx | 10 +++- src/lib/checkout/components/Checkout.jsx | 33 +++++++++--- src/lib/checkout/components/FinishCheckout.jsx | 38 +++++++------- src/lib/home/components/HeroBanner.jsx | 6 ++- src/lib/home/components/PopularProduct.jsx | 7 ++- src/lib/home/components/PreferredBrand.jsx | 6 ++- src/lib/invoice/components/Invoice.jsx | 5 +- src/lib/invoice/components/Invoices.jsx | 31 +++++++++--- src/lib/product/components/ProductFilter.jsx | 22 ++++++-- src/lib/product/components/ProductSearch.jsx | 13 ++++- src/lib/product/components/ProductSlider.jsx | 10 +++- src/lib/transaction/components/Transaction.jsx | 61 +++++++++++++++++++---- src/lib/transaction/components/Transactions.jsx | 49 ++++++++++++++---- src/lib/variant/components/VariantGroupCard.jsx | 6 ++- src/lib/wishlist/api/createOrDeleteWishlistApi.js | 12 +++-- src/lib/wishlist/components/Wishlists.jsx | 16 ++++-- src/lib/wishlist/hooks/useWishlist.js | 4 +- 23 files changed, 396 insertions(+), 105 deletions(-) (limited to 'src/lib') diff --git a/src/lib/address/components/CreateAddress.jsx b/src/lib/address/components/CreateAddress.jsx index 62bb0858..849b4c01 100644 --- a/src/lib/address/components/CreateAddress.jsx +++ b/src/lib/address/components/CreateAddress.jsx @@ -88,20 +88,34 @@ const CreateAddress = () => { } return ( - +
} + render={(props) => ( + + )} />
{errors.type?.message}
- +
{errors.name?.message}
@@ -118,7 +132,12 @@ const CreateAddress = () => {
- +
{errors.mobile?.message}
@@ -135,7 +154,12 @@ const CreateAddress = () => {
- +
{errors.zip?.message}
@@ -144,7 +168,12 @@ const CreateAddress = () => { } + render={(props) => ( + + )} />
{errors.city?.message}
@@ -155,7 +184,11 @@ const CreateAddress = () => { name='district' control={control} render={(props) => ( - + )} />
@@ -166,12 +199,19 @@ const CreateAddress = () => { name='subDistrict' control={control} render={(props) => ( - + )} />
- diff --git a/src/lib/address/components/EditAddress.jsx b/src/lib/address/components/EditAddress.jsx index 0cfa013a..a832edbc 100644 --- a/src/lib/address/components/EditAddress.jsx +++ b/src/lib/address/components/EditAddress.jsx @@ -102,20 +102,34 @@ const EditAddress = ({ id, defaultValues }) => { } return ( -
+
} + render={(props) => ( + + )} />
{errors.type?.message}
- +
{errors.name?.message}
@@ -132,7 +146,12 @@ const EditAddress = ({ id, defaultValues }) => {
- +
{errors.mobile?.message}
@@ -149,7 +168,12 @@ const EditAddress = ({ id, defaultValues }) => {
- +
{errors.zip?.message}
@@ -158,7 +182,12 @@ const EditAddress = ({ id, defaultValues }) => { } + render={(props) => ( + + )} />
{errors.city?.message}
@@ -169,7 +198,11 @@ const EditAddress = ({ id, defaultValues }) => { name='district' control={control} render={(props) => ( - + )} />
@@ -180,12 +213,19 @@ const EditAddress = ({ id, defaultValues }) => { name='subDistrict' control={control} render={(props) => ( - + )} />
- diff --git a/src/lib/auth/api/editPersonalProfileApi.js b/src/lib/auth/api/editPersonalProfileApi.js index af2ad4b2..39cd44c1 100644 --- a/src/lib/auth/api/editPersonalProfileApi.js +++ b/src/lib/auth/api/editPersonalProfileApi.js @@ -1,5 +1,5 @@ -import odooApi from "@/core/api/odooApi" -import { getAuth } from "@/core/utils/auth" +import odooApi from '@/core/api/odooApi' +import { getAuth } from '@/core/utils/auth' const editPersonalProfileApi = async ({ data }) => { const auth = getAuth() @@ -7,4 +7,4 @@ const editPersonalProfileApi = async ({ data }) => { return dataProfile } -export default editPersonalProfileApi \ No newline at end of file +export default editPersonalProfileApi diff --git a/src/lib/auth/components/Login.jsx b/src/lib/auth/components/Login.jsx index 01b2a571..b4e94e0a 100644 --- a/src/lib/auth/components/Login.jsx +++ b/src/lib/auth/components/Login.jsx @@ -37,7 +37,10 @@ const Login = () => { children: ( <> Email belum diaktivasi, - + aktivasi sekarang @@ -51,18 +54,29 @@ const Login = () => { return (
- Logo Indoteknik + Logo Indoteknik

Mulai Belanja Sekarang

Masuk ke akun kamu untuk belanja

{alert && ( - + {alert.children} )} -
+
{
Belum punya akun Indoteknik?{' '} - + Daftar
diff --git a/src/lib/auth/components/Register.jsx b/src/lib/auth/components/Register.jsx index df08541d..135972d3 100644 --- a/src/lib/auth/components/Register.jsx +++ b/src/lib/auth/components/Register.jsx @@ -26,7 +26,12 @@ const Register = () => { return (
- Logo Indoteknik + Logo Indoteknik

Daftar Akun Indoteknik

@@ -34,7 +39,10 @@ const Register = () => { Buat akun sekarang lebih mudah dan terverifikasi - +