| line-height: 16px; | line-height: 16px; | ||||
| font-size: 12px; | font-size: 12px; | ||||
| position: relative; | position: relative; | ||||
| max-width: 120px; | |||||
| overflow: hidden; | |||||
| text-overflow: ellipsis; | |||||
| white-space: nowrap; | |||||
| max-height: 16px; | |||||
| top: -2px; | top: -2px; | ||||
| left: 3px; | left: 3px; | ||||
| `; | `; |
| const sorting = props?.sorting; | const sorting = props?.sorting; | ||||
| const headerString = useSelector(selectHeaderString); | const headerString = useSelector(selectHeaderString); | ||||
| const { isMobile } = useIsMobile(); | const { isMobile } = useIsMobile(); | ||||
| // Changing header string on refresh or on load | |||||
| // Changing header string on refresh or on load | |||||
| const altString = useMemo(() => { | const altString = useMemo(() => { | ||||
| if (!props?.users) { | if (!props?.users) { | ||||
| if (sorting?.selectedSortOption === sortEnum.OLD) { | if (sorting?.selectedSortOption === sortEnum.OLD) { | ||||
| }); | }); | ||||
| const handleChangeSelect = (event) => { | const handleChangeSelect = (event) => { | ||||
| console.log(sorting); | |||||
| if (!props.users) sorting?.changeSorting(event.target.value); | if (!props.users) sorting?.changeSorting(event.target.value); | ||||
| }; | }; | ||||
| const handleClickCategory = () => { | const handleClickCategory = () => { | ||||
| <SelectOption style={{ display: "none" }} value="default"> | <SelectOption style={{ display: "none" }} value="default"> | ||||
| {t("reviews.sortBy")} | {t("reviews.sortBy")} | ||||
| </SelectOption> | </SelectOption> | ||||
| {Object.keys(sortEnum).map((property) => { | |||||
| if (sortEnum[property].value === 0) return; | |||||
| {Object.keys(sorting?.sortOptions).map((property) => { | |||||
| if (sorting?.sortOptions[property].value === 0) return; | |||||
| return ( | return ( | ||||
| <SelectOption | <SelectOption | ||||
| value={sortEnum[property]} | |||||
| key={sortEnum[property].value} | |||||
| value={sorting?.sortOptions[property]} | |||||
| key={sorting?.sortOptions[property].value} | |||||
| > | > | ||||
| {sortEnum[property].mainText} | |||||
| {sorting?.sortOptions[property].mainText} | |||||
| </SelectOption> | </SelectOption> | ||||
| ); | ); | ||||
| })} | })} |
| value: 2, | value: 2, | ||||
| mainText: "Dobijene" | mainText: "Dobijene" | ||||
| } | } | ||||
| } | |||||
| export const sortCategoriesEnum = { | |||||
| INITIAL: { | |||||
| value: 0, | |||||
| mainText: "Sortiraj po", | |||||
| queryString: "" | |||||
| }, | |||||
| POPULAR: { | |||||
| value: 1, | |||||
| mainText: "Najpopularnije", | |||||
| queryString: "popular" | |||||
| }, | |||||
| NEW: { | |||||
| value: 2, | |||||
| mainText: "Najskorije dodate", | |||||
| queryString: "newest" | |||||
| }, | |||||
| OLD: { | |||||
| value: 3, | |||||
| mainText: "Najstarije dodate", | |||||
| queryString: "oldest" | |||||
| } | |||||
| } | } |
| import { useMemo } from "react"; | |||||
| import { useEffect, useState } from "react"; | import { useEffect, useState } from "react"; | ||||
| import { useDispatch, useSelector } from "react-redux"; | import { useDispatch, useSelector } from "react-redux"; | ||||
| import { | import { | ||||
| import { setFilteredSortOption } from "../../store/actions/filters/filtersActions"; | import { setFilteredSortOption } from "../../store/actions/filters/filtersActions"; | ||||
| import { selectSelectedSortOption } from "../../store/selectors/filtersSelectors"; | import { selectSelectedSortOption } from "../../store/selectors/filtersSelectors"; | ||||
| const useSorting = (applyAllFilters) => { | |||||
| const useSorting = (applyAllFilters, newSortOptions = sortEnum) => { | |||||
| const selectedSortOption = useSelector(selectSelectedSortOption); | const selectedSortOption = useSelector(selectSelectedSortOption); | ||||
| const [selectedSortOptionLocally, setSelectedSortOptionLocally] = useState( | const [selectedSortOptionLocally, setSelectedSortOptionLocally] = useState( | ||||
| sortEnum.INITIAL | sortEnum.INITIAL | ||||
| ); | ); | ||||
| const [isInitiallyLoaded, setIsInitallyLoaded] = useState(false); | const [isInitiallyLoaded, setIsInitallyLoaded] = useState(false); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const sortOptions = useMemo(() => { | |||||
| return newSortOptions || sortEnum; | |||||
| }, [newSortOptions]) | |||||
| // On every change of sorting option, new request to backend should be sent | // On every change of sorting option, new request to backend should be sent | ||||
| useEffect(() => { | useEffect(() => { | ||||
| changeSortingFromName, | changeSortingFromName, | ||||
| apply, | apply, | ||||
| clear, | clear, | ||||
| sortOptions | |||||
| }; | }; | ||||
| }; | }; | ||||
| export default useSorting; | export default useSorting; |
| import selectedTheme from "../../../themes"; | import selectedTheme from "../../../themes"; | ||||
| import { useState } from "react"; | import { useState } from "react"; | ||||
| import EditCategory from "../../../components/Modals/EditCategory/EditCategory"; | import EditCategory from "../../../components/Modals/EditCategory/EditCategory"; | ||||
| import useSorting from "../../../hooks/useOffers/useSorting"; | |||||
| import { sortCategoriesEnum } from "../../../enums/sortEnum"; | |||||
| import { adminSortMethod } from "../../../util/helpers/adminSortHelper"; | |||||
| const AdminCategoriesPage = () => { | const AdminCategoriesPage = () => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const sorting = useSorting(() => {}, sortCategoriesEnum); | |||||
| const categories = useSelector(selectCategories); | const categories = useSelector(selectCategories); | ||||
| const manualSearchString = useSelector(selectManualSearchString); | const manualSearchString = useSelector(selectManualSearchString); | ||||
| const [openedAddModal, setOpenedAddModal] = useState(false); | const [openedAddModal, setOpenedAddModal] = useState(false); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch(fetchCategories()); | dispatch(fetchCategories()); | ||||
| return () => { | |||||
| dispatch(setManualSearchString("")); | |||||
| sorting.clear(); | |||||
| }; | |||||
| }, []); | }, []); | ||||
| const handleSearch = (value) => { | const handleSearch = (value) => { | ||||
| console.log(value); | console.log(value); | ||||
| }; | }; | ||||
| const categoriesToShow = useMemo(() => { | const categoriesToShow = useMemo(() => { | ||||
| if (categories) { | if (categories) { | ||||
| if (manualSearchString) | |||||
| return categories.filter((item) => | |||||
| item.name.toLowerCase().includes(manualSearchString.toLowerCase()) | |||||
| ); | |||||
| return categories; | |||||
| return adminSortMethod(categories, manualSearchString, sorting); | |||||
| } | } | ||||
| return []; | return []; | ||||
| }, [categories, manualSearchString]); | |||||
| }, [categories, manualSearchString, sorting.selectedSortOptionLocally]); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <AdminCategoriesPageContainer> | <AdminCategoriesPageContainer> | ||||
| categories | categories | ||||
| hideGrid | hideGrid | ||||
| isAdmin | isAdmin | ||||
| sorting={sorting} | |||||
| hideBackButton | hideBackButton | ||||
| /> | /> | ||||
| <CategoriesList> | <CategoriesList> |
| import EditCategory from "../../../components/Modals/EditCategory/EditCategory"; | import EditCategory from "../../../components/Modals/EditCategory/EditCategory"; | ||||
| import { setManualSearchString } from "../../../store/actions/filters/filtersActions"; | import { setManualSearchString } from "../../../store/actions/filters/filtersActions"; | ||||
| import { selectManualSearchString } from "../../../store/selectors/filtersSelectors"; | import { selectManualSearchString } from "../../../store/selectors/filtersSelectors"; | ||||
| import useSorting from "../../../hooks/useOffers/useSorting"; | |||||
| import { sortCategoriesEnum } from "../../../enums/sortEnum"; | |||||
| import { adminSortMethod } from "../../../util/helpers/adminSortHelper"; | |||||
| const AdminLocationsPage = () => { | const AdminLocationsPage = () => { | ||||
| const [openedAddModal, setOpenedAddModal] = useState(false); | const [openedAddModal, setOpenedAddModal] = useState(false); | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const sorting = useSorting(() => {}, sortCategoriesEnum); | |||||
| const locations = useSelector(selectLocations); | const locations = useSelector(selectLocations); | ||||
| const manualSearchString = useSelector(selectManualSearchString); | const manualSearchString = useSelector(selectManualSearchString); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch(fetchLocations()); | dispatch(fetchLocations()); | ||||
| return () => { | |||||
| dispatch(setManualSearchString("")); | |||||
| sorting.clear(); | |||||
| }; | |||||
| }, []); | }, []); | ||||
| const handleSearch = (value) => { | const handleSearch = (value) => { | ||||
| console.log(value); | console.log(value); | ||||
| }; | }; | ||||
| const locationsToShow = useMemo(() => { | const locationsToShow = useMemo(() => { | ||||
| if (locations) { | if (locations) { | ||||
| if (manualSearchString) | |||||
| return locations.filter((item) => | |||||
| item.city.toLowerCase().includes(manualSearchString.toLowerCase()) | |||||
| ); | |||||
| return locations; | |||||
| return adminSortMethod(locations, manualSearchString, sorting); | |||||
| } | } | ||||
| }, [locations, manualSearchString]); | |||||
| }, [locations, manualSearchString, sorting.selectedSortOptionLocally]); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <AdminLocationsPageContainer> | <AdminLocationsPageContainer> | ||||
| hideGrid | hideGrid | ||||
| isAdmin | isAdmin | ||||
| hideBackButton | hideBackButton | ||||
| sorting={sorting} | |||||
| /> | /> | ||||
| <LocationsList> | <LocationsList> | ||||
| {locationsToShow.map((category) => ( | {locationsToShow.map((category) => ( |
| import selectedTheme from "../../../themes"; | import selectedTheme from "../../../themes"; | ||||
| import { useState } from "react"; | import { useState } from "react"; | ||||
| import EditCategory from "../../../components/Modals/EditCategory/EditCategory"; | import EditCategory from "../../../components/Modals/EditCategory/EditCategory"; | ||||
| import useSorting from "../../../hooks/useOffers/useSorting"; | |||||
| import { sortCategoriesEnum } from "../../../enums/sortEnum"; | |||||
| import { adminSortMethod } from "../../../util/helpers/adminSortHelper"; | |||||
| const AdminSubcategoriesPage = () => { | const AdminSubcategoriesPage = () => { | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
| const categories = useSelector(selectCategories); | const categories = useSelector(selectCategories); | ||||
| const routeMatch = useRouteMatch(); | const routeMatch = useRouteMatch(); | ||||
| const sorting = useSorting(() => {}, sortCategoriesEnum); | |||||
| const manualSearchString = useSelector(selectManualSearchString); | const manualSearchString = useSelector(selectManualSearchString); | ||||
| const [openedAddModal, setOpenedAddModal] = useState(false); | const [openedAddModal, setOpenedAddModal] = useState(false); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| dispatch(fetchCategories()); | dispatch(fetchCategories()); | ||||
| return () => dispatch(setManualSearchString("")); | |||||
| }, []); | }, []); | ||||
| const handleSearch = (value) => { | const handleSearch = (value) => { | ||||
| const subcategories = useMemo(() => { | const subcategories = useMemo(() => { | ||||
| if (category) { | if (category) { | ||||
| if (manualSearchString) | |||||
| return category.subcategories.filter((subcategory) => | |||||
| subcategory.name | |||||
| .toLowerCase() | |||||
| .includes(manualSearchString.toLowerCase()) | |||||
| ); | |||||
| return category.subcategories; | |||||
| return adminSortMethod( | |||||
| category.subcategories, | |||||
| manualSearchString, | |||||
| sorting | |||||
| ); | |||||
| } | } | ||||
| return []; | return []; | ||||
| }, [category, manualSearchString]); | |||||
| }, [category, manualSearchString, sorting.selectedSortOptionLocally]); | |||||
| console.log("subc", categories); | console.log("subc", categories); | ||||
| return ( | return ( | ||||
| /> | /> | ||||
| </SubcategoriesList> | </SubcategoriesList> | ||||
| <AdminSubcategoriesHeader | <AdminSubcategoriesHeader | ||||
| hideSorting | |||||
| sorting={sorting} | |||||
| myOffers | myOffers | ||||
| subcategories | subcategories | ||||
| hideGrid | hideGrid |
| <AdminUsersSearchField | <AdminUsersSearchField | ||||
| isAdmin | isAdmin | ||||
| handleSearch={handleSearch} | handleSearch={handleSearch} | ||||
| placeholder={t("admin.subcategories.placeholder")} | |||||
| placeholder={t("admin.users.searchPlaceholder")} | |||||
| /> | /> | ||||
| <AdminUsersHeader | <AdminUsersHeader | ||||
| myOffers | myOffers | ||||
| hideSorting | |||||
| category | category | ||||
| hideGrid | hideGrid | ||||
| isAdmin | isAdmin |
| // baseURL: "http://192.168.88.150:3001/", // DJOLE | // baseURL: "http://192.168.88.150:3001/", // DJOLE | ||||
| // baseURL: "http://192.168.88.175:3005/", | // baseURL: "http://192.168.88.175:3005/", | ||||
| // baseURL: "http://192.168.88.143:3001/", // DULE | // baseURL: "http://192.168.88.143:3001/", // DULE | ||||
| // baseURL: "https://trampa-api-test.dilig.net/", | |||||
| baseURL: "http://localhost:3001/", | |||||
| baseURL: "https://trampa-api-test.dilig.net/", | |||||
| // baseURL: "http://localhost:3001/", | |||||
| // baseURL: process.env.REACT_APP_BASE_API_URL, | // baseURL: process.env.REACT_APP_BASE_API_URL, | ||||
| headers: { | headers: { | ||||
| "Content-Type": "application/json", | "Content-Type": "application/json", |
| if (typeof payload.payload.firmLogo !== "string") | if (typeof payload.payload.firmLogo !== "string") | ||||
| requestBody.append("file", payload.payload.firmLogo); | requestBody.append("file", payload.payload.firmLogo); | ||||
| requestBody.append("company[name]", payload.payload.firmName); | requestBody.append("company[name]", payload.payload.firmName); | ||||
| requestBody.append("company[PIB]", payload.payload.firmPIB); | |||||
| // requestBody.append("company[PIB]", payload.payload.firmPIB); | |||||
| if (payload.payload.firmPhone.toString().length !== 0) | if (payload.payload.firmPhone.toString().length !== 0) | ||||
| requestBody.append( | requestBody.append( | ||||
| "company[contacts][telephone]", | "company[contacts][telephone]", |
| import { sortCategoriesEnum } from "../../enums/sortEnum"; | |||||
| export const adminSortMethod = (arrayOfItems, manualSearchString, sorting) => { | |||||
| console.log(arrayOfItems); | |||||
| console.log(sorting); | |||||
| let arrayOfItemsToReturn = [...arrayOfItems]; | |||||
| if (manualSearchString) | |||||
| arrayOfItemsToReturn = arrayOfItems.filter( | |||||
| (item) => | |||||
| item?.city?.toLowerCase()?.includes(manualSearchString.toLowerCase()) || | |||||
| item?.name?.toLowerCase()?.includes(manualSearchString.toLowerCase()) | |||||
| ); | |||||
| if (sorting?.selectedSortOptionLocally !== sortCategoriesEnum.INITIAL) { | |||||
| if (sorting?.selectedSortOptionLocally === sortCategoriesEnum.POPULAR) { | |||||
| arrayOfItemsToReturn.sort((a, b) => b.offerCount - a.offerCount); | |||||
| } | |||||
| if (sorting?.selectedSortOptionLocally === sortCategoriesEnum.OLD) { | |||||
| arrayOfItemsToReturn.sort((a, b) => { | |||||
| const firstCreated = new Date( | |||||
| a?._created || new Date(1970, 1).toISOString() | |||||
| ); | |||||
| const secondCreated = new Date( | |||||
| b?._created || new Date(1970, 1).toISOString() | |||||
| ); | |||||
| console.log(firstCreated); | |||||
| return firstCreated - secondCreated; | |||||
| }); | |||||
| } | |||||
| if (sorting?.selectedSortOptionLocally === sortCategoriesEnum.NEW) { | |||||
| arrayOfItemsToReturn.sort((a, b) => { | |||||
| const firstCreated = new Date( | |||||
| a?._created || new Date(1970, 1).toISOString() | |||||
| ); | |||||
| const secondCreated = new Date( | |||||
| b?._created || new Date(1970, 1).toISOString() | |||||
| ); | |||||
| return secondCreated - firstCreated; | |||||
| }); | |||||
| } | |||||
| } | |||||
| return arrayOfItemsToReturn; | |||||
| }; |