From cd66a460880353b8509bf29d94bd13e8adf42911 Mon Sep 17 00:00:00 2001 From: KarimAldeen Date: Wed, 21 Feb 2024 17:43:06 +0300 Subject: [PATCH] Done --- src/Components/Karimalden/View/Object.tsx | 92 +++++++++++++++ src/Pages/Products/View/BasicInfo.tsx | 4 +- src/Pages/Products/View/ObjectField.tsx | 6 +- src/Pages/Products/View/taps/File.tsx | 41 +++++++ src/Pages/Products/View/taps/FileImage.tsx | 39 +++++++ .../Products/View/taps/ResposiveTabs.tsx | 106 +++++++++++++++--- src/Pages/Products/View/taps/SearchTabs.tsx | 60 ++++++++++ src/Pages/Products/View/taps/VariableTabs.tsx | 9 ++ src/Pages/Products/formUtil.ts | 1 + src/Styles/Layout/Layout.scss | 22 +++- 10 files changed, 361 insertions(+), 19 deletions(-) create mode 100644 src/Components/Karimalden/View/Object.tsx create mode 100644 src/Pages/Products/View/taps/File.tsx create mode 100644 src/Pages/Products/View/taps/FileImage.tsx create mode 100644 src/Pages/Products/View/taps/SearchTabs.tsx create mode 100644 src/Pages/Products/View/taps/VariableTabs.tsx diff --git a/src/Components/Karimalden/View/Object.tsx b/src/Components/Karimalden/View/Object.tsx new file mode 100644 index 0000000..82f2f77 --- /dev/null +++ b/src/Components/Karimalden/View/Object.tsx @@ -0,0 +1,92 @@ +import React, { useEffect, useState } from 'react'; +import { CloseOutlined } from '@ant-design/icons'; +import { Button, Card, Form, Input, Space, Typography } from 'antd'; +import { useFormikContext } from 'formik'; + +const ObjectField = ({value , onChange}:any) => { + const [form] = Form.useForm(); + const formik = useFormikContext(); + const [FieldItems, setFieldItems] = useState([]) + const handleChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; + setFieldItems((prevState:any) => ({ + ...prevState, + [name]: value + })); + formik.setFieldValue("info", FieldItems) + + }; + + useEffect(() => { + form.setFieldsValue({ + items: [{ list: [{ Attribute: '', Description: '' }] }] + }); + + }, []); + + return ( +
+ + {(fields, { add, remove }) => ( +
+ {fields.map((field, index) => ( +
+ + Information + + + {/* Nested Form.List for sub-items */} + + + {(subFields, subOpt) => ( +
+ {subFields.map((subField) => ( + + + + + + + + + { + subOpt.remove(subField.name); + }} + /> + + ))} + +
+ )} +
+
+
+ ))} +
+ )} +
+
+ ); +}; + +export default ObjectField; diff --git a/src/Pages/Products/View/BasicInfo.tsx b/src/Pages/Products/View/BasicInfo.tsx index 83f4035..346f7f3 100644 --- a/src/Pages/Products/View/BasicInfo.tsx +++ b/src/Pages/Products/View/BasicInfo.tsx @@ -18,7 +18,7 @@ const BasicInfo = ({setIsValed}:any) => { console.log(values); } }, [isValid,values]); - + return ( @@ -30,7 +30,7 @@ const BasicInfo = ({setIsValed}:any) => { - + diff --git a/src/Pages/Products/View/ObjectField.tsx b/src/Pages/Products/View/ObjectField.tsx index 01b8b4a..6b63b55 100644 --- a/src/Pages/Products/View/ObjectField.tsx +++ b/src/Pages/Products/View/ObjectField.tsx @@ -3,7 +3,7 @@ import { CloseOutlined } from '@ant-design/icons'; import { Button, Card, Form, Input, Space, Typography } from 'antd'; import { useFormikContext } from 'formik'; -const ObjectField: React.FC = () => { +const ObjectField = () => { const [form] = Form.useForm(); const formik = useFormikContext(); const [FieldItems, setFieldItems] = useState([]) @@ -13,8 +13,9 @@ const ObjectField: React.FC = () => { ...prevState, [name]: value })); + formik.setFieldValue("info", FieldItems) - + }; useEffect(() => { @@ -22,6 +23,7 @@ const ObjectField: React.FC = () => { items: [{ list: [{ Attribute: '', Description: '' }] }] }); + }, []); return ( diff --git a/src/Pages/Products/View/taps/File.tsx b/src/Pages/Products/View/taps/File.tsx new file mode 100644 index 0000000..7c39e43 --- /dev/null +++ b/src/Pages/Products/View/taps/File.tsx @@ -0,0 +1,41 @@ +import React from 'react'; +import { UploadOutlined } from '@ant-design/icons'; +import { Button, Upload } from 'antd'; +import type { UploadFile } from 'antd'; + +const fileList: UploadFile[] = [ + +]; + + +const App = ({value, onChange}:any) => { + + const FilehandleChange = (data:any) => { + + console.log('===================================='); + console.log(data?.fileList); + console.log('===================================='); + }; + const customRequest = async ({ onSuccess}: any) => { + onSuccess(); + }; + return( + + <> + onChange(data?.fileList)} + customRequest={customRequest} + > + + + + + ); +} + +export default App; \ No newline at end of file diff --git a/src/Pages/Products/View/taps/FileImage.tsx b/src/Pages/Products/View/taps/FileImage.tsx new file mode 100644 index 0000000..8cc8cb7 --- /dev/null +++ b/src/Pages/Products/View/taps/FileImage.tsx @@ -0,0 +1,39 @@ +import React from 'react'; +import { UploadOutlined } from '@ant-design/icons'; +import { Button, Upload } from 'antd'; +import type { UploadFile } from 'antd'; + +const fileList: UploadFile[] = [ + +]; + + +const App = ({value, onChange}:any) => { + + const FilehandleChange = (data:any) => { + + console.log('===================================='); + console.log(data?.fileList); + console.log('===================================='); + }; + const customRequest = async ({ onSuccess}: any) => { + onSuccess(); + }; + return( + + <> + onChange(data?.fileList)} + customRequest={customRequest} + > + + + + ); +} + +export default App; \ No newline at end of file diff --git a/src/Pages/Products/View/taps/ResposiveTabs.tsx b/src/Pages/Products/View/taps/ResposiveTabs.tsx index e1f87f5..1433e7f 100644 --- a/src/Pages/Products/View/taps/ResposiveTabs.tsx +++ b/src/Pages/Products/View/taps/ResposiveTabs.tsx @@ -1,7 +1,12 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { Tabs, Space, Input } from 'antd'; import { CopyOutlined } from '@ant-design/icons'; import { useTranslation } from 'react-i18next'; +import { Col, Row } from 'reactstrap'; +import FileImage from './FileImage'; +import SearchTabs from './SearchTabs'; +import ObjectField from '../ObjectField'; +import { useFormikContext } from 'formik'; const { TabPane } = Tabs; @@ -26,6 +31,22 @@ const App: React.FC = () => { const onChange = (newActiveKey: string) => { setActiveKey(newActiveKey); }; + useEffect(() => { +console.log(inputValues); + }, [inputValues]) + + +const formikContext = useFormikContext(); +const { values } :any = formikContext; + + + +useEffect(() => { + setInputValues((prevInputValues:any) => ({ + ...prevInputValues, + [14]: values?.info, + })); +}, [values?.info]) const add = () => { const newActiveKey = `${items.length + 1}`; @@ -48,11 +69,23 @@ const App: React.FC = () => { key: newActiveKey, label: `variable ${newActiveKey}`, }; + + // Get the values of the original tab + const originalValues = inputValues[targetKey] || ['', '', '', '']; + const newPanes = [...items, newItem]; setItems(newPanes); setActiveKey(newActiveKey); + + // Update the inputValues state with the original values for the new tab + setInputValues((prevInputValues) => ({ + ...prevInputValues, + [newActiveKey]: originalValues, + })); } }; + + const remove = (targetKey: string) => { let newActiveKey = activeKey; @@ -127,25 +160,72 @@ interface VariableTabsProps { onChange: (value: string[]) => void; } -const VariableTabs: React.FC = ({ value, onChange }) => { + +const VariableTabs: React.FC = ({ value, onChange } ) => { const handleInputChange = (index: number) => (e: React.ChangeEvent) => { const newValues = [...value]; newValues[index] = e.target.value; onChange(newValues); }; - const [t] = useTranslation() + //@ts-ignore + const SelecthandleChange = (index: number) => (Selectvalue:any) => { + const newValues = [...value]; + newValues[index] = Selectvalue; + onChange(newValues); + }; + const FilehandleChange = (index: number) => (data:any) => { + const newValues = [...value]; + newValues[index] = data; + onChange(newValues); +}; + + const [t] = useTranslation(); return ( -
- - - - - - -
+ <> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); }; diff --git a/src/Pages/Products/View/taps/SearchTabs.tsx b/src/Pages/Products/View/taps/SearchTabs.tsx new file mode 100644 index 0000000..37a0b16 --- /dev/null +++ b/src/Pages/Products/View/taps/SearchTabs.tsx @@ -0,0 +1,60 @@ +import React from 'react'; +import { Select } from 'antd'; +import { useTranslation } from 'react-i18next'; + +interface SearchTabsProps { + value: string; + onChange:any + name:any +} + +const SearchTabs: React.FC = ({ value, onChange ,name}) =>{ + const [t] = useTranslation() + + return ( +
+ + +