diff --git a/src/Components/ValidationField/View/Date.tsx b/src/Components/ValidationField/View/Date.tsx index dfb5757..1732085 100644 --- a/src/Components/ValidationField/View/Date.tsx +++ b/src/Components/ValidationField/View/Date.tsx @@ -3,7 +3,7 @@ import React from 'react' import useFormField from '../../../Hooks/useFormField'; import dayjs from 'dayjs'; -const Date = ({ name, label,picker="date" ,isDisabled,props,onChange,placeholder ,className}: any) => { +const Date = ({ name, label,picker="date" ,isDisabled,props,onChange,placeholder ,className,Format}: any) => { const { errorMsg, isError, t, formik } = useFormField(name, props) const onCalendarChange = (value: any) => { @@ -15,7 +15,7 @@ const Date = ({ name, label,picker="date" ,isDisabled,props,onChange,placeholder
diff --git a/src/Components/ValidationField/View/SearchField.tsx b/src/Components/ValidationField/View/SearchField.tsx index 51f954d..498a783 100644 --- a/src/Components/ValidationField/View/SearchField.tsx +++ b/src/Components/ValidationField/View/SearchField.tsx @@ -1,11 +1,13 @@ import { Form, Select } from 'antd'; import React, { useEffect, useState } from 'react'; import useFormField from '../../../Hooks/useFormField'; -import { useNavigate } from 'react-router-dom'; +import { useLocation, useNavigate } from 'react-router-dom'; const SearchField = ({ name, label, placeholder, isDisabled, searchBy, option, isMulti, onChange, className, props }: any) => { const { errorMsg, isError, t, formik } = useFormField(name, props); const [searchQuery, setSearchQuery] = useState(''); + const location = useLocation() + const navigate = useNavigate() useEffect(() => { const searchParams = new URLSearchParams(window?.location?.search); @@ -17,9 +19,16 @@ const SearchField = ({ name, label, placeholder, isDisabled, searchBy, option, i const SelecthandleChange = (value: { value: string; label: React.ReactNode }) => { formik?.setFieldValue(name, value); + console.log(value); }; const SearchHandleChange = (value:any) => { - navigate(`${window?.location?.pathname}?${searchBy}=${value}`, { replace: true }); + if (value || value !== "") { + navigate(`${window?.location?.pathname}?${searchBy}=${value}`, { replace: true }); + } else { + const params = new URLSearchParams(location.search); + params.delete(searchBy ?? "search"); + navigate(`${window?.location.pathname}?${params.toString()}`, { replace: true }); + } }; diff --git a/src/Components/ValidationField/View/SelectField.tsx b/src/Components/ValidationField/View/SelectField.tsx index b208b48..77a0450 100644 --- a/src/Components/ValidationField/View/SelectField.tsx +++ b/src/Components/ValidationField/View/SelectField.tsx @@ -25,7 +25,7 @@ const SelectField = ({ name, label, placeholder, isDisabled,option,isMulti,onCha options={option} size="large" className={`${className} w-100`} - defaultValue={formik.values[name]} + defaultValue={formik.values?.name} allowClear {...(isMulti && { mode: "multiple" })} onChange={onChange || SelecthandleChange} diff --git a/src/Components/ValidationField/types.ts b/src/Components/ValidationField/types.ts index 17fe1b0..cda23c1 100644 --- a/src/Components/ValidationField/types.ts +++ b/src/Components/ValidationField/types.ts @@ -33,7 +33,7 @@ label?: string; className?: string; isDisabled?: boolean; - onChange?: (value: any) => void; + onChange?:any; dir?:'ltr' | "rtl"; option: any[]; isMulti?: boolean; @@ -75,6 +75,8 @@ onChange?: (value: any) => void; dir?:'ltr' | "rtl" picker?: "data" | "week" | "month" | "quarter" | "year"; + Format?: "YYYY/MM/DD" | "MM/DD" | "YYYY/MM" | "YYYY-MM-DD HH:mm:ss.SSS" | "YYYY-MM-DD HH:MM:SS"; + } diff --git a/src/Hooks/imageUrlToFile.tsx b/src/Hooks/imageUrlToFile.tsx new file mode 100644 index 0000000..255055b --- /dev/null +++ b/src/Hooks/imageUrlToFile.tsx @@ -0,0 +1,13 @@ +export async function fetchImage(imageUrl:any) { + try { + const response = await fetch(imageUrl); + if (!response.ok) { + throw new Error(`Failed to fetch image: ${response.status} ${response.statusText}`); + } + const blob = await response.blob(); + return new File([blob], 'image.png', { type: 'image/png' }); + } catch (error) { + console.error('Error fetching image:', error); + return null; + } + } diff --git a/src/Hooks/useFormatToSelect.tsx b/src/Hooks/useFormatToSelect.tsx index 74fe0f2..2c9980d 100644 --- a/src/Hooks/useFormatToSelect.tsx +++ b/src/Hooks/useFormatToSelect.tsx @@ -1,9 +1,11 @@ const useFormatToSelect = (Data : any) => { const format = (data :any) => { if (!data) return []; + const language = localStorage.getItem("language") ?? "en"; + return data.map((item :any) => ({ value: item?.id, - label: item?.name, + label: item?.name[language], })); }; diff --git a/src/Layout/Dashboard/SearchField.tsx b/src/Layout/Dashboard/SearchField.tsx index 333146d..8137d71 100644 --- a/src/Layout/Dashboard/SearchField.tsx +++ b/src/Layout/Dashboard/SearchField.tsx @@ -5,25 +5,34 @@ import { useTranslation } from 'react-i18next'; import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'; const { Search } = Input; -const SearchField = ({searchBy } : any) => { +const SearchField = ({ searchBy }: any) => { const navigate = useNavigate() const [searchParams,] = useSearchParams(); - const location =useLocation() - const {t} = useTranslation(); - console.log(searchBy,"searchBy"); - - - const [searchValue, setSearchValue] = useState(searchParams.get('search')|| ""); + const location = useLocation() + const { t } = useTranslation(); + + + const [searchValue, setSearchValue] = useState(searchParams.get(searchBy ?? "search") || ""); const onSearch: SearchProps['onSearch'] = (value, _e, info) => { - // console.log(value); - - navigate(`${location?.pathname}?${searchBy ?? "search"}=${value}`, { replace: true }); + if (value || value !== "") { + navigate(`${location?.pathname}?${searchBy ?? "search"}=${value}`, { replace: true }); + } else { + const params = new URLSearchParams(location.search); + params.delete(searchBy ?? "search"); + navigate(`${location.pathname}?${params.toString()}`, { replace: true }); + } } - const onChange = (e :any) => { - setSearchValue(e.target.value); - } + const onChange = (e: any) => { + const value = e.target.value + setSearchValue(e.target.value); + if (value === "") { + const params = new URLSearchParams(location.search); + params.delete(searchBy ?? "search"); + navigate(`${location.pathname}?${params.toString()}`, { replace: true }); + } + } return ( @@ -33,12 +42,12 @@ const SearchField = ({searchBy } : any) => { allowClear enterButton={t("search")} size="middle" - placeholder={t("search")} + placeholder={t(searchBy ?? "search")} onSearch={onSearch} - style={{ width: 250 }} + style={{ width: 250 }} value={searchValue} onChange={onChange} - /> + />
) diff --git a/src/Layout/Dashboard/ViewPage.tsx b/src/Layout/Dashboard/ViewPage.tsx index 0eaf775..f52b257 100644 --- a/src/Layout/Dashboard/ViewPage.tsx +++ b/src/Layout/Dashboard/ViewPage.tsx @@ -30,7 +30,7 @@ const ViewPage: React.FC= ({children,getInitialValues, getValidation {t("View_information")} - + { diff --git a/src/Pages/Categories/View/Add/AttributeTab/AttributeTabs.tsx b/src/Pages/Categories/View/Add/AttributeTab/AttributeTabs.tsx index 4e9d8e8..64729d4 100644 --- a/src/Pages/Categories/View/Add/AttributeTab/AttributeTabs.tsx +++ b/src/Pages/Categories/View/Add/AttributeTab/AttributeTabs.tsx @@ -28,7 +28,7 @@ export const AttributeTabs: React.FC = ({ tabKey }) => { return ( <> -
{t("Attributes")} {tabKey}
+
{t("Attribute")} {tabKey}
{ }; return (
- + + diff --git a/src/Pages/Categories/View/Add/AttributeTab/Field/FormItem.tsx b/src/Pages/Categories/View/Add/AttributeTab/Field/FormItem.tsx index 91b4c0b..cc9b2d1 100644 --- a/src/Pages/Categories/View/Add/AttributeTab/Field/FormItem.tsx +++ b/src/Pages/Categories/View/Add/AttributeTab/Field/FormItem.tsx @@ -13,7 +13,7 @@ export const FormItem: React.FC = ({ label, value, onChange ,type return ( <> - + ); }; diff --git a/src/Pages/Categories/View/Add/AttributeTab/Field/Select.tsx b/src/Pages/Categories/View/Add/AttributeTab/Field/Select.tsx index 06cc975..cc2aecf 100644 --- a/src/Pages/Categories/View/Add/AttributeTab/Field/Select.tsx +++ b/src/Pages/Categories/View/Add/AttributeTab/Field/Select.tsx @@ -13,16 +13,16 @@ const SelectField = ({tabKey}: any) => { const onChange = (value:any) => { formik.setFieldValue(Formikname,value) console.log(value); + console.log(formik?.errors,"errors"); + } const Data = [{label: "color",value :"color"},{label: "text",value :"text"},{label: "image",value :"image"}] return (
-