diff --git a/donutshop_ecommerce/src/app/users/[id]/page.js b/donutshop_ecommerce/src/app/users/[id]/page.js index ec81751..f3172d2 100644 --- a/donutshop_ecommerce/src/app/users/[id]/page.js +++ b/donutshop_ecommerce/src/app/users/[id]/page.js @@ -4,6 +4,7 @@ import UserTab from '../../../components/layout/UserTab' import useProfile from '../../../components/UseProfile'; import UserForm from '../../../components/layout/UserForm'; import { useParams } from 'next/navigation'; +import toast from 'react-hot-toast'; const EditUsersPage = () => { const {data, loading} = useProfile(); @@ -19,13 +20,26 @@ const EditUsersPage = () => { }) }, []) - function handleSaveButton(ev, data){ + async function handleSaveButton(ev, data){ ev.preventDefault(); - fetch('/api/profile', { - method: 'PUT', - headers: {'Content-Type':'application/json'}, - body: JSON.stringify({...data, _id:id}), + const promise = new Promise(async (resolve, reject) => { + const response = await fetch('/api/profile', { + method: 'PUT', + headers: {'Content-Type':'application/json'}, + body: JSON.stringify({...data, _id:id}), + }) + if(response.ok){ + resolve(); + } else { + reject(); + } + }); + await toast.promise(promise, { + loading: 'Saving...', + success: 'Profile is saved', + error: 'Fail to saved your prodile', }) + } diff --git a/donutshop_ecommerce/src/components/layout/MenuItemForm.js b/donutshop_ecommerce/src/components/layout/MenuItemForm.js index 9d867c8..225bce2 100644 --- a/donutshop_ecommerce/src/components/layout/MenuItemForm.js +++ b/donutshop_ecommerce/src/components/layout/MenuItemForm.js @@ -41,7 +41,7 @@ const MenuItemForm = ({handleMenuFormSubmit, menuItem}) => {