diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/auth/api/editPersonalProfileApi.js | 10 | ||||
| -rw-r--r-- | src/lib/auth/components/CompanyProfile.jsx | 97 | ||||
| -rw-r--r-- | src/lib/auth/components/PersonalProfile.jsx | 115 | ||||
| -rw-r--r-- | src/lib/cart/components/Cart.jsx | 70 | ||||
| -rw-r--r-- | src/pages/my/profile.jsx | 10 |
5 files changed, 267 insertions, 35 deletions
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 ( + <> + <button + type='button' + onClick={toggle} + className='p-4 flex items-center text-left' + > + <div> + <div className='font-semibold mb-2'>Informasi Akun</div> + <div className='text-gray_r-11'> + Dibawah ini adalah data diri yang anda masukkan, periksa kembali data diri anda + </div> + </div> + <div className='p-2 bg-gray_r-3 rounded'> + {!isOpen && <ChevronDownIcon className='w-6' />} + {isOpen && <ChevronUpIcon className='w-6' />} + </div> + </button> + + {isOpen && ( + <form className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4'> + <div> + <label>Email</label> + <input + {...register('email')} + type='text' + disabled + className='form-input mt-3' + /> + </div> + <div> + <label>Nama Lengkap</label> + <input + {...register('name')} + type='text' + className='form-input mt-3' + /> + </div> + <div> + <label>No. Handphone</label> + <input + {...register('mobile')} + type='text' + className='form-input mt-3' + /> + </div> + <div> + <label>Kata Sandi</label> + <input + {...register('password')} + type='password' + className='form-input mt-3' + placeholder='Isi jika ingin mengubah kata sandi' + /> + </div> + <button + type='submit' + className='btn-yellow w-full' + > + Simpan + </button> + </form> + )} + </> + ) +} + +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 ( + <> + <button + type='button' + onClick={toggle} + className='p-4 flex items-center text-left' + > + <div> + <div className='font-semibold mb-2'>Informasi Akun</div> + <div className='text-gray_r-11'> + Dibawah ini adalah data diri yang anda masukan, periksa kembali data diri anda + </div> + </div> + <div className='p-2 bg-gray_r-3 rounded'> + {!isOpen && <ChevronDownIcon className='w-6' />} + {isOpen && <ChevronUpIcon className='w-6' />} + </div> + </button> + + {isOpen && ( + <form className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4' onSubmit={handleSubmit(onSubmitHandler)}> + <div> + <label>Email</label> + <input + {...register('email')} + type='text' + disabled + className='form-input mt-3' + /> + </div> + <div> + <label>Nama Lengkap</label> + <input + {...register('name')} + type='text' + className='form-input mt-3' + /> + </div> + <div> + <label>No. Handphone</label> + <input + {...register('mobile')} + type='text' + className='form-input mt-3' + /> + </div> + <div> + <label>Kata Sandi</label> + <input + {...register('password')} + type='password' + className='form-input mt-3' + placeholder='Isi jika ingin mengubah kata sandi' + /> + </div> + <button + type='submit' + className='btn-yellow w-full mt-2' + > + Simpan + </button> + </form> + )} + </> + ) +} + +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 ( - <div className='pt-6'> + <div className='pt-4'> <div className='flex justify-between mb-4 px-4'> <h1 className='font-semibold'>Daftar Produk Belanja</h1> <Link href='/'>Cari Produk Lain</Link> </div> - <div className='flex flex-col gap-y-4 px-4'> + <div className='flex flex-col gap-y-4 h-screen'> {cart.isLoading && ( <div className='flex justify-center my-4'> <Spinner className='w-6 text-gray_r-12/50 fill-gray_r-12' /> </div> )} - {!cart.isLoading && !products && ( - <Alert className='text-center my-2' type='info'> + {!cart.isLoading && (!products || products?.length == 0) && ( + <Alert className='text-center my-2 mx-4' type='info'> Keranjang belanja anda masih kosong </Alert> )} {products?.map((product) => ( - <div key={product?.id} className='flex'> + <div key={product?.id} className='flex mx-4'> <button type='button' className='flex items-center mr-2' @@ -214,37 +214,37 @@ const Cart = () => { </div> </div> ))} - </div> - <div className='sticky bottom-0 left-0 w-full p-4 mt-6 border-t border-gray_r-6 bg-white'> - <div className='flex justify-between mb-4'> - <div className='text-gray_r-11'> - Total: - <span className='text-red_r-11 font-semibold'> - - {selectedProduct().length > 0 - ? currencyFormat(totalPriceBeforeTax - totalDiscountAmount + totalTaxAmount) - : '-'} - </span> + <div className='sticky bottom-0 left-0 w-full p-4 mt-auto border-t border-gray_r-6 bg-white'> + <div className='flex justify-between mb-4'> + <div className='text-gray_r-11'> + Total: + <span className='text-red_r-11 font-semibold'> + + {selectedProduct().length > 0 + ? currencyFormat(totalPriceBeforeTax - totalDiscountAmount + totalTaxAmount) + : '-'} + </span> + </div> + </div> + <div className='flex gap-x-3'> + <button + type='button' + className='btn-yellow flex-1' + disabled={selectedProduct().length == 0} + onClick={() => router.push('/shop/quotation')} + > + Quotation + </button> + <button + type='button' + className='btn-solid-red flex-1' + disabled={selectedProduct().length == 0} + onClick={() => router.push('/shop/checkout')} + > + Checkout + </button> </div> - </div> - <div className='flex gap-x-3'> - <button - type='button' - className='btn-yellow flex-1' - disabled={selectedProduct().length == 0} - onClick={() => router.push('/shop/quotation')} - > - Quotation - </button> - <button - type='button' - className='btn-solid-red flex-1' - disabled={selectedProduct().length == 0} - onClick={() => router.push('/shop/checkout')} - > - Checkout - </button> </div> </div> diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx new file mode 100644 index 00000000..f69d4303 --- /dev/null +++ b/src/pages/my/profile.jsx @@ -0,0 +1,10 @@ +import AppLayout from '@/core/components/layouts/AppLayout' +import PersonalProfile from '@/lib/auth/components/PersonalProfile' + +export default function Profile() { + return ( + <AppLayout title='Akun Saya'> + <PersonalProfile /> + </AppLayout> + ) +} |
