업데이트
This commit is contained in:
parent
3af1d68b85
commit
03baa76f6f
@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
import * as Yup from 'yup';
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import toast from 'react-hot-toast';
|
||||
import { capitalCase } from 'change-case';
|
||||
@ -92,7 +92,7 @@ export default function ProductForm({
|
||||
// brand: Yup.string().required('brand is required'),
|
||||
// metaTitle: Yup.string().required('Meta title is required'),
|
||||
// metaDescription: Yup.string().required('Meta description is required'),
|
||||
images: Yup.array().min(1, 'Images is required'),
|
||||
images: Yup.array().min(1, 'Images is required')
|
||||
// sku: Yup.string().required('Sku is required'),
|
||||
// available: Yup.number().required('Quantaty is required')
|
||||
// colors: Yup.array().required('Color is required'),
|
||||
@ -102,13 +102,15 @@ export default function ProductForm({
|
||||
// .required('Sale price is required')
|
||||
// .lessThan(Yup.ref('price'), 'Sale price should be smaller than price')
|
||||
});
|
||||
|
||||
|
||||
const formik = useFormik({
|
||||
enableReinitialize: true,
|
||||
initialValues: {
|
||||
name: currentProduct?.name || '',
|
||||
description: currentProduct?.description || '',
|
||||
code: currentProduct?.code || `${now.getFullYear()}${now.getMonth()}${now.getDay()}${now.getHours()}${now.getMinutes()}${now.getSeconds()}`,
|
||||
code:
|
||||
currentProduct?.code ||
|
||||
`${now.getFullYear()}${now.getMonth()}${now.getDay()}${now.getHours()}${now.getMinutes()}${now.getSeconds()}`,
|
||||
slug: currentProduct?.slug || '',
|
||||
metaTitle: currentProduct?.metaTitle || '',
|
||||
metaDescription: currentProduct?.metaDescription || '',
|
||||
@ -127,7 +129,7 @@ export default function ProductForm({
|
||||
colors: currentProduct?.colors || '',
|
||||
sizes: currentProduct?.sizes || '',
|
||||
available: currentProduct?.available || '1',
|
||||
images: currentProduct?.images || [],
|
||||
images: currentProduct?.images || []
|
||||
},
|
||||
|
||||
validationSchema: NewProductSchema,
|
||||
@ -191,8 +193,6 @@ export default function ProductForm({
|
||||
setFieldValue('images', removeImage);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// const handleAnnotationsChange = (updatedAnnotations) => {
|
||||
// setAnnotations(updatedAnnotations);
|
||||
// formik.setFieldValue('metaDescription', updatedAnnotations)
|
||||
@ -207,6 +207,11 @@ export default function ProductForm({
|
||||
formik.setFieldValue('slug', slug); // set the value of slug in the formik state
|
||||
formik.handleChange(event); // handle the change in formik
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log('this Value', values)
|
||||
}, [values])
|
||||
|
||||
return (
|
||||
<Stack spacing={3}>
|
||||
<FormikProvider value={formik}>
|
||||
@ -337,7 +342,7 @@ export default function ProductForm({
|
||||
)}
|
||||
</FormControl>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={6} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={6} sx={{ display: 'none' }}>
|
||||
<FormControl fullWidth>
|
||||
{isInitialized ? (
|
||||
<Skeleton variant="text" width={100} />
|
||||
@ -362,7 +367,7 @@ export default function ProductForm({
|
||||
)}
|
||||
</FormControl>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={6} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={6} sx={{ display: 'none' }}>
|
||||
<LabelStyle component={'label'} htmlFor="size">
|
||||
{'Sizes'}
|
||||
</LabelStyle>
|
||||
@ -391,7 +396,7 @@ export default function ProductForm({
|
||||
)}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={6} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={6} sx={{ display: 'none' }}>
|
||||
<LabelStyle component={'label'} htmlFor="color">
|
||||
{'Colors'}
|
||||
</LabelStyle>
|
||||
@ -421,7 +426,7 @@ export default function ProductForm({
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12} md={6} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={6} sx={{ display: 'none' }}>
|
||||
<FormControl fullWidth>
|
||||
{isInitialized ? (
|
||||
<Skeleton variant="text" width={80} />
|
||||
@ -451,7 +456,7 @@ export default function ProductForm({
|
||||
)}
|
||||
</FormControl>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={4} sx={{ display: 'none' }}>
|
||||
<FormControl fullWidth>
|
||||
{isInitialized ? (
|
||||
<Skeleton variant="text" width={80} />
|
||||
@ -484,7 +489,7 @@ export default function ProductForm({
|
||||
)}
|
||||
</FormControl>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={4} sx={{ display: 'none' }}>
|
||||
<div>
|
||||
{isInitialized ? (
|
||||
<Skeleton variant="text" width={120} />
|
||||
@ -506,7 +511,7 @@ export default function ProductForm({
|
||||
)}
|
||||
</div>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={4} sx={{ display: 'none' }}>
|
||||
<div>
|
||||
<LabelStyle component={'label'} htmlFor="product-sku">
|
||||
{'Product Sku'}
|
||||
@ -520,7 +525,7 @@ export default function ProductForm({
|
||||
/>
|
||||
</div>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={12} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={12} sx={{ display: 'none' }}>
|
||||
{isInitialized ? (
|
||||
<Skeleton variant="text" width={70} />
|
||||
) : (
|
||||
@ -556,7 +561,7 @@ export default function ProductForm({
|
||||
/>
|
||||
)}
|
||||
</Grid>
|
||||
<Grid item xs={12} md={12} sx={{display:'none'}}>
|
||||
<Grid item xs={12} md={12} sx={{ display: 'none' }}>
|
||||
<div>
|
||||
{isInitialized ? (
|
||||
<Skeleton variant="text" width={100} />
|
||||
@ -624,7 +629,6 @@ export default function ProductForm({
|
||||
formik.setFieldValue('metaDescription', value);
|
||||
}
|
||||
}}
|
||||
|
||||
error={Boolean(touched.images && errors.images)}
|
||||
/>
|
||||
{touched.images && errors.images && (
|
||||
@ -663,7 +667,7 @@ export default function ProductForm({
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div style={{display:'none'}}>
|
||||
<div style={{ display: 'none' }}>
|
||||
{isInitialized ? (
|
||||
<Skeleton variant="text" width={140} />
|
||||
) : (
|
||||
@ -686,7 +690,7 @@ export default function ProductForm({
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{display:'none'}}>
|
||||
<div style={{ display: 'none' }}>
|
||||
<LabelStyle component={'label'} htmlFor="quantity">
|
||||
{'Quantity'}
|
||||
</LabelStyle>
|
||||
@ -700,7 +704,7 @@ export default function ProductForm({
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{display:'none'}}>
|
||||
<div style={{ display: 'none' }}>
|
||||
<LabelStyle component={'label'} htmlFor="regular-price">
|
||||
{'Regular Price'}
|
||||
</LabelStyle>
|
||||
@ -717,7 +721,7 @@ export default function ProductForm({
|
||||
helperText={touched.price && errors.price}
|
||||
/>
|
||||
</div>
|
||||
<div style={{display:'none'}}>
|
||||
<div style={{ display: 'none' }}>
|
||||
<LabelStyle component={'label'} htmlFor="sale-price">
|
||||
{'Sale Price'}
|
||||
</LabelStyle>
|
||||
|
@ -1,5 +1,5 @@
|
||||
'use client';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useMutation } from 'react-query';
|
||||
import toast from 'react-hot-toast';
|
||||
import PropTypes from 'prop-types';
|
||||
@ -59,7 +59,6 @@ export default function SubCategoryForm({
|
||||
isInitialized = false
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
const [state, setstate] = useState({
|
||||
loading: false,
|
||||
name: '',
|
||||
@ -110,7 +109,7 @@ export default function SubCategoryForm({
|
||||
file: currentCategory?.cover || '',
|
||||
slug: currentCategory?.slug || '',
|
||||
status: currentCategory?.status || STATUS_OPTIONS[0],
|
||||
parentCategory: currentCategory?.category || (categories && categories[0]?._id) || ''
|
||||
parentCategory: currentCategory?.parentCategory || (categories && categories[0]?._id) || ''
|
||||
},
|
||||
enableReinitialize: true,
|
||||
validationSchema: NewCategorySchema,
|
||||
|
Loading…
Reference in New Issue
Block a user