diff --git a/src/views/apps/ecommerce/products/add/ProductVariants.tsx b/src/views/apps/ecommerce/products/add/ProductVariants.tsx
index 9fdcefc..b48e08a 100644
--- a/src/views/apps/ecommerce/products/add/ProductVariants.tsx
+++ b/src/views/apps/ecommerce/products/add/ProductVariants.tsx
@@ -1,30 +1,42 @@
'use client'
// React Imports
-import { useState } from 'react'
-import type { SyntheticEvent } from 'react'
// MUI Imports
-import Grid from '@mui/material/Grid2'
-import Card from '@mui/material/Card'
-import CardHeader from '@mui/material/CardHeader'
-import CardContent from '@mui/material/CardContent'
import Button from '@mui/material/Button'
-import MenuItem from '@mui/material/MenuItem'
+import Card from '@mui/material/Card'
+import CardContent from '@mui/material/CardContent'
+import CardHeader from '@mui/material/CardHeader'
+import Grid from '@mui/material/Grid2'
// Components Imports
import CustomIconButton from '@core/components/mui/IconButton'
import CustomTextField from '@core/components/mui/TextField'
+import { useDispatch, useSelector } from 'react-redux'
+import { RootState } from '../../../../../redux-store'
+import { setProductField } from '../../../../../redux-store/slices/product'
const ProductVariants = () => {
- // States
- const [count, setCount] = useState(1)
+ const dispatch = useDispatch()
+ const { variants } = useSelector((state: RootState) => state.productReducer.productRequest)
- const deleteForm = (e: SyntheticEvent) => {
- e.preventDefault()
+ const handleAddVariant = () => {
+ dispatch(setProductField({ field: 'variants', value: [...variants, { name: '', cost: 0, price_modifier: 0 }] }))
+ }
- // @ts-ignore
- e.target.closest('.repeater-item').remove()
+ const handleRemoveVariant = (index: number) => {
+ const updated = variants.filter((_, i) => i !== index)
+ dispatch(setProductField({ field: 'variants', value: updated }))
+ }
+
+ const handleInputChange = (index: number, e: any) => {
+ const { name, value } = e.target
+ const updated = [...variants]
+ updated[index] = {
+ ...updated[index],
+ [name]: name === 'name' ? value : Number(value)
+ }
+ dispatch(setProductField({ field: 'variants', value: updated }))
}
return (
@@ -32,21 +44,40 @@ const ProductVariants = () => {
- {Array.from(Array(count).keys()).map((item, index) => (
+ {variants.map((variant, index) => (
-
-
-
-
-
-
+ handleInputChange(index, e)}
+ />
-
-
-
-
+
+ handleInputChange(index, e)}
+ />
+
+
+
+ handleInputChange(index, e)}
+ />
+ handleRemoveVariant(index)} className='min-is-fit'>
@@ -55,7 +86,7 @@ const ProductVariants = () => {
))}
-