diff --git a/.gitignore b/.gitignore index a547bf3..3f16caa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ yarn-error.log* pnpm-debug.log* lerna-debug.log* +# environment +.env + node_modules dist dist-ssr diff --git a/env.example b/env.example new file mode 100644 index 0000000..5c41572 --- /dev/null +++ b/env.example @@ -0,0 +1,2 @@ +VITE_API_URL="http://localhost:8080/api/lafresca" +VITE_UPLOAD_URL="https://s3-bucket.usweb.aws.com/upload" \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index d5d1f6a..3c9cf87 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,7 +13,7 @@ import Dashboard from '@pages/BranchManager/Dashboard'; import BranchManagerLayout from '@layouts/BranchManagerLayout'; import LoginPage from '@pages/User/LogIn'; import UserLayout from '@layouts/UserLayout'; -import Foods from '@pages/BranchManager/Foods'; +import AddFoods from '@pages/BranchManager/Foods/AddFood'; import FoodItem from '@pages/FoodItem'; import AllFoodItems from '@pages/AllFoodItems'; import FoodList from '@pages/BranchManager/FoodList'; @@ -24,6 +24,8 @@ import { OrderHistory } from './components/User/OrderHistory/OrderHistory'; import User from '@pages/BranchManager/Users'; import UserAdd from '@pages/BranchManager/Users/AddUser'; import UserEdit from '@pages/BranchManager/Users/EditUser'; +import EditFoods from '@pages/BranchManager/Foods/EditFood'; +import AddCategories from '@pages/BranchManager/Categories/AddCategories'; const routes = createRoutesFromElements( @@ -106,6 +108,15 @@ const routes = createRoutesFromElements( } /> + + + + + } + /> - + } /> - - + + } /> @@ -164,6 +175,15 @@ const routes = createRoutesFromElements( } /> + + + + + } + /> , ); diff --git a/src/components/BranchManager/Forms/DynamicForm/CategoryForm.tsx b/src/components/BranchManager/Forms/DynamicForm/CategoryForm.tsx new file mode 100644 index 0000000..0ad4327 --- /dev/null +++ b/src/components/BranchManager/Forms/DynamicForm/CategoryForm.tsx @@ -0,0 +1,122 @@ +import { FC, useEffect, useState } from 'react'; +import { z } from 'zod'; +import { useForm, SubmitHandler } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { XMarkIcon } from '@heroicons/react/24/outline'; +import { TrashIcon } from '@heroicons/react/24/solid'; +import ImageInput from '@components/BranchManager/Inputs/ImageInput'; +import { Button } from '@nextui-org/react'; +import MultiSelect from '@components/BranchManager/Forms/MultiSelect'; +import { Category } from '@/types/category'; +import { toast } from 'react-toastify'; +import { useNavigate } from 'react-router-dom'; + +const FormSchema = z.object({ + name: z.string().min(1, { message: 'Category name is required' }), + description: z.string().optional(), +}); + +type FormSchemaType = z.infer; + +function CategoryForm() { + const Navigate = useNavigate(); + const { register, handleSubmit, formState } = useForm({ + resolver: zodResolver(FormSchema), + }); + + const { errors } = formState; + + useEffect(() => { + if (Object.keys(errors).length) { + console.log('Form errors:', errors); + } + }, [errors]); + + const onSubmit: SubmitHandler = async (data) => { + console.log('Form data:', data); + try { + const apiUrl = (import.meta as any).env.VITE_API_URL; + const response = await fetch(`${apiUrl}/category`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }); + + if (response.ok) { + toast('Food item added successfully', { type: 'success' }); + Navigate('/branch-manager/foods'); + } else { + toast('Failed to add food item', { type: 'error' }); + console.error('Failed to add food item:', response.statusText); + } + } catch (error) { + console.error('Error adding food item:', error); + toast('Failed to add food item', { type: 'error' }); + } + }; + + return ( +
+
+
+

+ Add Food Categories +

+
+
+
+
+ +