From 2403ff657c6869acf42e5db67a031075fa0847cb Mon Sep 17 00:00:00 2001 From: iamtrazy Date: Wed, 4 Dec 2024 07:28:09 +0530 Subject: [PATCH] fix: Dynamic form sub category and feature name auto delete fix --- .../BranchManager/Forms/DynamicForm/index.tsx | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/components/BranchManager/Forms/DynamicForm/index.tsx b/src/components/BranchManager/Forms/DynamicForm/index.tsx index 7999043..ce806ec 100644 --- a/src/components/BranchManager/Forms/DynamicForm/index.tsx +++ b/src/components/BranchManager/Forms/DynamicForm/index.tsx @@ -146,11 +146,24 @@ const DynamicForm: FC = () => { } }; - // const [categories] = useState([ - // { key: 'Non-Vegetarian', label: 'Non-Vegetarian' }, - // { key: 'Vegetarian', label: 'Vegetarian' }, - // { key: 'Other', label: 'Other' }, - // ]); + const addSubCategory = (featureIndex: number) => { + const currentFeature = fields[featureIndex]; + update(featureIndex, { + name: currentFeature.name, // Preserve the feature name + subCategories: [...currentFeature.subCategories, { name: '', price: 0 }], + }); + }; + + const removeSubCategory = (featureIndex: number, subIndex: number) => { + const currentFeature = fields[featureIndex]; + update(featureIndex, { + name: currentFeature.name, // Preserve the feature name + subCategories: currentFeature.subCategories.filter( + (_, i) => i !== subIndex, + ), + }); + }; + if (!categories.length) { return
Loading...
; } @@ -320,14 +333,7 @@ const DynamicForm: FC = () => { @@ -336,15 +342,7 @@ const DynamicForm: FC = () => {