From b6acf1243173a59aaeeaacb382fca6e89e8b34b8 Mon Sep 17 00:00:00 2001 From: Moaz Dawalibi Date: Tue, 15 Oct 2024 16:30:25 +0300 Subject: [PATCH] fix area bug and some fixes --- .../DataTable/SearchFieldWithSelect.tsx | 26 +++++++++++-------- src/Components/Layout/Navbar/Tooltip.tsx | 2 +- src/Layout/Ui/NavBar.tsx | 2 ++ src/Pages/Admin/Reseller/Edit/Page.tsx | 14 +++++++--- .../Admin/Reseller/Form/TitleDetailsForm.tsx | 8 +++--- src/Pages/Admin/Reseller/Form/formUtils.ts | 6 ++--- src/Pages/Admin/question/Model/Malty/Form.tsx | 4 +-- src/Pages/Admin/question/Page.tsx | 4 +-- src/Pages/Auth/LoginForm.tsx | 1 + src/Routes.tsx | 5 ++-- src/Styles/DataTable/SearchField.scss | 10 ++++--- src/translate/ar.json | 8 +++++- 12 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/Components/DataTable/SearchFieldWithSelect.tsx b/src/Components/DataTable/SearchFieldWithSelect.tsx index 747087c..0585e81 100644 --- a/src/Components/DataTable/SearchFieldWithSelect.tsx +++ b/src/Components/DataTable/SearchFieldWithSelect.tsx @@ -45,6 +45,7 @@ const SearchFieldWithSelect: React.FC = ({ const toggleDropdown = () => { setIsOpen(!isOpen); }; + const navigate = useNavigate(); const handleOptionClick = (option: Option) => { setSelectedOption(option); @@ -57,7 +58,7 @@ const SearchFieldWithSelect: React.FC = ({ const filteredOptions = options.filter((option) => option.label.toLowerCase().includes(searchTerm.toLowerCase()), ); - + const Type = localStorage.getItem('type'); return (
@@ -75,16 +76,19 @@ const SearchFieldWithSelect: React.FC = ({ {(isOpen || (searchTerm !== "" && filteredOptions.length > 0)) && (
- {filteredOptions.map((option) => ( -
handleOptionClick(option)} - > -
{option.label}
- {/* {withIcon && } */} -
- ))} + {filteredOptions.map((option) => { + console.log(option); + return( +
handleOptionClick(option)} + > +
{option.label}
+ {/* {withIcon && } */} +
+ ) + })}
)} diff --git a/src/Components/Layout/Navbar/Tooltip.tsx b/src/Components/Layout/Navbar/Tooltip.tsx index ba060fb..e4566df 100644 --- a/src/Components/Layout/Navbar/Tooltip.tsx +++ b/src/Components/Layout/Navbar/Tooltip.tsx @@ -22,7 +22,7 @@ const TooltipComp = ({ const { handel_open_model } = useModalHandler(); const handleEdit = () => { - handel_open_model(ModalEnum.CHANGE_PASSWORD); + // handel_open_model(ModalEnum.CHANGE_PASSWORD); }; return (
diff --git a/src/Layout/Ui/NavBar.tsx b/src/Layout/Ui/NavBar.tsx index c598d48..5ec38a7 100644 --- a/src/Layout/Ui/NavBar.tsx +++ b/src/Layout/Ui/NavBar.tsx @@ -17,6 +17,8 @@ const NavBar = ({ isOpen }: { isOpen: boolean }) => { const navigate = useNavigate(); const PrevPath = getPrevPathRoute(location.pathname); const [t] = useTranslation(); + console.log(search_array); + const translateArray = translateOptions(search_array, t); const handelNavigate = () => { diff --git a/src/Pages/Admin/Reseller/Edit/Page.tsx b/src/Pages/Admin/Reseller/Edit/Page.tsx index f02915c..ae255d2 100644 --- a/src/Pages/Admin/Reseller/Edit/Page.tsx +++ b/src/Pages/Admin/Reseller/Edit/Page.tsx @@ -21,10 +21,12 @@ const TableHeader = ({canEdit,ModelAbility}:{canEdit?: any;ModelAbility?: any;}) const { objectToEdit , setObjectToEdit } = useObjectToEdit(); const {mutate, isSuccess,status} = useUpdateReseller(); const Navigate = useNavigate() - console.log(objectToEdit); useSetPageTitle(t(`page_header.add_reseller`)); + const handleSubmit = (values: any) => { + console.log(values); + const DataToSend = { ...values, location: { @@ -32,6 +34,10 @@ const TableHeader = ({canEdit,ModelAbility}:{canEdit?: any;ModelAbility?: any;}) lng: values.lng, }, }; + + if (values.username === objectToEdit?.user?.username) { + delete DataToSend.username; + } mutate(DataToSend); }; useEffect(() => { @@ -66,9 +72,9 @@ const TableHeader = ({canEdit,ModelAbility}:{canEdit?: any;ModelAbility?: any;})
diff --git a/src/Pages/Admin/Reseller/Form/TitleDetailsForm.tsx b/src/Pages/Admin/Reseller/Form/TitleDetailsForm.tsx index a925fc4..69e5f4e 100644 --- a/src/Pages/Admin/Reseller/Form/TitleDetailsForm.tsx +++ b/src/Pages/Admin/Reseller/Form/TitleDetailsForm.tsx @@ -3,10 +3,12 @@ import { useTranslation } from "react-i18next"; import { FaRegAddressBook } from "react-icons/fa"; import ValidationField from "../../../../Components/ValidationField/ValidationField"; import { nationalities } from "../../../../types/App"; +import { useGetAllArea } from "../../../../api/Area"; const TitleDetailsForm = () => { const [t] = useTranslation(); - + const {data} = useGetAllArea(); + return (
@@ -18,8 +20,8 @@ const TitleDetailsForm = () => { name={"area_id"} placeholder={"_"} label={"city"} - // type="Select" - // option={nationalities} + type="Select" + option={data?.data} /> {/* */} diff --git a/src/Pages/Admin/Reseller/Form/formUtils.ts b/src/Pages/Admin/Reseller/Form/formUtils.ts index eebfd4b..1483d80 100644 --- a/src/Pages/Admin/Reseller/Form/formUtils.ts +++ b/src/Pages/Admin/Reseller/Form/formUtils.ts @@ -36,13 +36,14 @@ interface PersonalDetailsEditForm { contact_number2: string | null; card_number: string | null; user: User; - area_id: number | null; + area_id: any | null; lat:number, lng:number } export const getInitialValues = (objectToEdit: Partial) => { const location = objectToEdit?.location?.[0] || { lat: 33.5138, lng: 36.2765 }; + return { id: objectToEdit?.id ?? 0, first_name: objectToEdit?.first_name ?? null, @@ -71,14 +72,13 @@ export const getValidationSchema = () => { contact_number1: Yup.string().required('contact_number1 is required'), contact_number2: Yup.string().required('contact_number2 is required'), username: Yup.string().required('username is required'), - area_id: Yup.number().required('area_id is required'), + area_id: Yup.mixed().required('area_id is required'), }); }; export const getInitialValuesEdit = (objectToEdit: Partial) => { const location = objectToEdit?.location || { lat: 0, lng: 0 }; - console.log(objectToEdit); return { id: objectToEdit?.id ?? 0, diff --git a/src/Pages/Admin/question/Model/Malty/Form.tsx b/src/Pages/Admin/question/Model/Malty/Form.tsx index 6f92ef3..f1fbc7c 100644 --- a/src/Pages/Admin/question/Model/Malty/Form.tsx +++ b/src/Pages/Admin/question/Model/Malty/Form.tsx @@ -1,5 +1,5 @@ import { Row } from "reactstrap"; -import React, { useEffect } from "react"; +import { useEffect } from "react"; import { useFormikContext } from "formik"; import { FaCirclePlus } from "react-icons/fa6"; import { Choice } from "../../../../../types/Item"; @@ -15,7 +15,7 @@ import useUnsavedChangesWarning from "../../../../../Hooks/useUnsavedChangesWarn const Form = () => { const formik = useFormikContext(); const { setSuccess, Success ,ShowHint} = useObjectToEdit(); - + const handleAddChoice = ( parent_index: number, fromKeyCombination: boolean = false, diff --git a/src/Pages/Admin/question/Page.tsx b/src/Pages/Admin/question/Page.tsx index 18bfb61..aba42b1 100644 --- a/src/Pages/Admin/question/Page.tsx +++ b/src/Pages/Admin/question/Page.tsx @@ -58,8 +58,8 @@ const TableHeader = () => { if(objectToEdit){ setObjectToEdit(null) } -}, []) - + }, []); + return (
}> diff --git a/src/Pages/Auth/LoginForm.tsx b/src/Pages/Auth/LoginForm.tsx index 0a06888..f6dcf24 100644 --- a/src/Pages/Auth/LoginForm.tsx +++ b/src/Pages/Auth/LoginForm.tsx @@ -14,6 +14,7 @@ const LoginForm = () => { const [t] = useTranslation(); const handelSubmit = (values: FormValues) => { mutate(values); + // localStorage.setItem('type',) }; const { login } = useAuthState(); diff --git a/src/Routes.tsx b/src/Routes.tsx index 334298f..8119531 100644 --- a/src/Routes.tsx +++ b/src/Routes.tsx @@ -428,14 +428,15 @@ export const AppRoutes: Record = Object.fromEntries( export const CrudRoutes: any = Object.fromEntries( CrudRoute.map((route) => [route?.path, route?.header]), ); -export const search_array: { label: string; value: string }[] = menuItems +export const search_array: { label: string; value: string; type: string }[] = menuItems ?.filter((item: TMenuItem) => { return hasAbility(item.abilities, item.abilities_value); }) .map((item: TMenuItem) => ({ label: item.header as string, value: item.path as string, - })); + type: item.type ? item.type : "admin", + })) const AllRoute = [...menuItems, ...CrudRoute]; diff --git a/src/Styles/DataTable/SearchField.scss b/src/Styles/DataTable/SearchField.scss index 2886f12..f66ec3d 100644 --- a/src/Styles/DataTable/SearchField.scss +++ b/src/Styles/DataTable/SearchField.scss @@ -73,7 +73,10 @@ .search_select_icon.open { transform: rotate(180deg); } +.search-options{ + border: 1px solid var(--value); +} .search-options-list { max-height: 220px; overflow: auto; @@ -82,11 +85,12 @@ direction: rtl; scroll-behavior: smooth; scroll-padding: 10rem; - + @include Scrollbar; &::-webkit-scrollbar { - width: 10px; + // background: var(--value); + // width: 5px; } - + /* Handle */ &::-webkit-scrollbar-thumb { background-color: transparent; diff --git a/src/translate/ar.json b/src/translate/ar.json index 9927883..03e2ac6 100644 --- a/src/translate/ar.json +++ b/src/translate/ar.json @@ -1003,7 +1003,13 @@ "Area":"المنطقة", "Coupon":"قسيمة", "financial_collection":"التحصيلات", - "show_collection":"حصيلة" + "show_collection":"حصيلة", + "dashboard":"لوحة القيادة", + "reSeller":"البائعين", + "city":"مدينة", + "questionBank":"بنك الأسئلة", + "roles":"الدور", + "coupon":"قسيمة" }, "table": { "student": "قائمة الطلاب",