diff --git a/src/components/products/ProductDetails.jsx b/src/components/products/ProductDetails.jsx index 7d3b99f..a46c93b 100644 --- a/src/components/products/ProductDetails.jsx +++ b/src/components/products/ProductDetails.jsx @@ -1,45 +1,53 @@ import {useMutation, useQueryClient} from '@tanstack/react-query' import {Formik, Form} from 'formik' import * as Yup from "yup"; -import InputText from '../InputText' -import {addCustomTemplate} from '../../services/siteServices' -import queryKeys from '../../services/queryKeys'; +// import InputText from '../InputText' +import {updateProduct} from '../../services/siteServices' +// import queryKeys from '../../services/queryKeys'; -const initialValues = { - custom_id: "", - provision_name: "", -}; - // To get the validation schema const validationSchema = Yup.object().shape({ - custom_id: Yup.string().required("custom_id is required").min(6, 'must be upto 6 characters').max(25, 'must not exceed 25 characters'), - provision_name: Yup.string().required("provision_name is required").min(6, 'must be upto 6 characters').max(200, 'must not exceed 200 characters'), + details: Yup.string().required("details text is required").min(6, 'must be upto 6 characters').max(500, 'must not exceed 500 characters'), + sale_text: Yup.string().required("sales text is required").min(6, 'must be upto 6 characters').max(500, 'must not exceed 500 characters'), }); -export default function ProductDetails() { +export default function ProductDetails({productDetails}) { + + const initialValues = { + details: productDetails?.details, + sale_text: productDetails?.sale_text, + }; const queryClient = useQueryClient() - const customTemplate = useMutation({ + const productUpdate = useMutation({ mutationFn: (fields) => { - if (!fields.custom_id || !fields.provision_name) { - throw new Error('Please provide all fields marked *') - } - return addCustomTemplate(fields) + return updateProduct(fields) }, onSuccess: () => { - queryClient.refetchQueries({ - queryKey: [...queryKeys.custom_template], - // type: 'active', - // exact: true, - }) + // queryClient.refetchQueries({ + // queryKey: [...queryKeys.custom_template], + // // type: 'active', + // // exact: true, + // }) }, + onSettled: ()=>{ + setTimeout(()=>{ + productUpdate.reset() + }, 3000) + } }) //FUNCTION TO HANDLE ADD TEMPLATE const handleSubmit = (values, helper) => { - // customTemplate.mutate(values) + const reqData = { + details: values.details, + product_detail_id: productDetails?.product_detail_id, + product_id: productDetails?.product_id, + sale_text: values.sale_text, + } + productUpdate.mutate(reqData) }; return ( @@ -54,50 +62,50 @@ export default function ProductDetails() { className='flex flex-col w-full bg-white dark:bg-black-box text-black-body dark:text-white-body rounded-xl p-16 sm:px-20 sm:py-16 shadow'>
{customTemplate.error.message}
+{productUpdate.error.message}
{'Template Added'}
+{'Product Details Updated'}
Product Configuration
-| - Item - | -- Value - | -
|---|---|
|
-
-
-
- ProductID
-
- |
-
-
- P000008
-
- |
-
|
-
-
-
- Description
-
- |
-
-
- Get Open EMR for practice management
-
- |
-
|
-
-
-
- Status
-
- |
-
-
- 1
-
- |
-
|
-
-
-
- Added
-
- |
-
-
- 2025-06-14T23:00:12.43598
-
- |
-
|
-
-
-
- Banner
-
- |
-
-
- p5.jpg
-
- |
-
|
-
-
-
- UID
-
- |
-
-
- 5c45eadb-b8b9-4d20-aaec-4fca5bcc93d3
-
- |
-
Product Details
-Loading...
+ > + : isError ? +{error.message}
+ : +Product Configuration
+| + Item + | ++ Value + | +
|---|---|
|
+
+
+
+ ProductID
+
+ |
+
+
+ {productConfig?.product_id}
+
+ |
+
|
+
+
+
+ Description
+
+ |
+
+
+ {productConfig?.description}
+
+ |
+
|
+
+
+
+ Status
+
+ |
+
+
+ {productConfig?.status}
+
+ |
+
|
+
+
+
+ Added
+
+ |
+
+
+ {getDateTimeFromDateString(productConfig?.added)}
+
+ |
+
|
+
+
+
+ Banner
+
+ |
+
+
+ {productConfig?.banner}
+
+ |
+
|
+
+
+
+ UID
+
+ |
+
+
+ {productConfig?.uid}
+
+ |
+
Product Details
+