Skip to content

Commit

Permalink
fix: navigate to food list after succesful add food
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtrazy committed Jul 17, 2024
1 parent 018118e commit ee96a91
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/BranchManager/Forms/DynamicForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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: 'Item name is required' }),
Expand Down Expand Up @@ -42,6 +43,7 @@ const FormSchema = z.object({
type FormSchemaType = z.infer<typeof FormSchema>;

const DynamicForm: FC = () => {
const Navigate = useNavigate();
const { register, control, handleSubmit, formState, setValue } =
useForm<FormSchemaType>({
resolver: zodResolver(FormSchema),
Expand Down Expand Up @@ -122,6 +124,7 @@ const DynamicForm: FC = () => {

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);
Expand Down

0 comments on commit ee96a91

Please sign in to comment.