| @@ -236,6 +236,11 @@ export const DetailText = styled(Typography)` | |||
| line-height: 16px; | |||
| font-size: 12px; | |||
| position: relative; | |||
| max-width: 120px; | |||
| overflow: hidden; | |||
| text-overflow: ellipsis; | |||
| white-space: nowrap; | |||
| max-height: 16px; | |||
| top: -2px; | |||
| left: 3px; | |||
| `; | |||
| @@ -56,8 +56,8 @@ const Header = (props) => { | |||
| const sorting = props?.sorting; | |||
| const headerString = useSelector(selectHeaderString); | |||
| const { isMobile } = useIsMobile(); | |||
| // Changing header string on refresh or on load | |||
| // Changing header string on refresh or on load | |||
| const altString = useMemo(() => { | |||
| if (!props?.users) { | |||
| if (sorting?.selectedSortOption === sortEnum.OLD) { | |||
| @@ -104,6 +104,7 @@ const Header = (props) => { | |||
| }); | |||
| const handleChangeSelect = (event) => { | |||
| console.log(sorting); | |||
| if (!props.users) sorting?.changeSorting(event.target.value); | |||
| }; | |||
| const handleClickCategory = () => { | |||
| @@ -227,14 +228,14 @@ const Header = (props) => { | |||
| <SelectOption style={{ display: "none" }} value="default"> | |||
| {t("reviews.sortBy")} | |||
| </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 ( | |||
| <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> | |||
| ); | |||
| })} | |||
| @@ -33,4 +33,26 @@ export const sortAdminEnum = { | |||
| value: 2, | |||
| 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" | |||
| } | |||
| } | |||
| @@ -1,3 +1,4 @@ | |||
| import { useMemo } from "react"; | |||
| import { useEffect, useState } from "react"; | |||
| import { useDispatch, useSelector } from "react-redux"; | |||
| import { | |||
| @@ -9,13 +10,16 @@ import { sortEnum } from "../../enums/sortEnum"; | |||
| import { setFilteredSortOption } from "../../store/actions/filters/filtersActions"; | |||
| import { selectSelectedSortOption } from "../../store/selectors/filtersSelectors"; | |||
| const useSorting = (applyAllFilters) => { | |||
| const useSorting = (applyAllFilters, newSortOptions = sortEnum) => { | |||
| const selectedSortOption = useSelector(selectSelectedSortOption); | |||
| const [selectedSortOptionLocally, setSelectedSortOptionLocally] = useState( | |||
| sortEnum.INITIAL | |||
| ); | |||
| const [isInitiallyLoaded, setIsInitallyLoaded] = useState(false); | |||
| const dispatch = useDispatch(); | |||
| const sortOptions = useMemo(() => { | |||
| return newSortOptions || sortEnum; | |||
| }, [newSortOptions]) | |||
| // On every change of sorting option, new request to backend should be sent | |||
| useEffect(() => { | |||
| @@ -60,6 +64,7 @@ const useSorting = (applyAllFilters) => { | |||
| changeSortingFromName, | |||
| apply, | |||
| clear, | |||
| sortOptions | |||
| }; | |||
| }; | |||
| export default useSorting; | |||
| @@ -19,15 +19,23 @@ import { setManualSearchString } from "../../../store/actions/filters/filtersAct | |||
| import selectedTheme from "../../../themes"; | |||
| import { useState } from "react"; | |||
| 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 { t } = useTranslation(); | |||
| const dispatch = useDispatch(); | |||
| const sorting = useSorting(() => {}, sortCategoriesEnum); | |||
| const categories = useSelector(selectCategories); | |||
| const manualSearchString = useSelector(selectManualSearchString); | |||
| const [openedAddModal, setOpenedAddModal] = useState(false); | |||
| useEffect(() => { | |||
| dispatch(fetchCategories()); | |||
| return () => { | |||
| dispatch(setManualSearchString("")); | |||
| sorting.clear(); | |||
| }; | |||
| }, []); | |||
| const handleSearch = (value) => { | |||
| console.log(value); | |||
| @@ -35,14 +43,10 @@ const AdminCategoriesPage = () => { | |||
| }; | |||
| const categoriesToShow = useMemo(() => { | |||
| if (categories) { | |||
| if (manualSearchString) | |||
| return categories.filter((item) => | |||
| item.name.toLowerCase().includes(manualSearchString.toLowerCase()) | |||
| ); | |||
| return categories; | |||
| return adminSortMethod(categories, manualSearchString, sorting); | |||
| } | |||
| return []; | |||
| }, [categories, manualSearchString]); | |||
| }, [categories, manualSearchString, sorting.selectedSortOptionLocally]); | |||
| return ( | |||
| <> | |||
| <AdminCategoriesPageContainer> | |||
| @@ -56,6 +60,7 @@ const AdminCategoriesPage = () => { | |||
| categories | |||
| hideGrid | |||
| isAdmin | |||
| sorting={sorting} | |||
| hideBackButton | |||
| /> | |||
| <CategoriesList> | |||
| @@ -16,15 +16,23 @@ import selectedTheme from "../../../themes"; | |||
| import EditCategory from "../../../components/Modals/EditCategory/EditCategory"; | |||
| import { setManualSearchString } from "../../../store/actions/filters/filtersActions"; | |||
| 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 [openedAddModal, setOpenedAddModal] = useState(false); | |||
| const { t } = useTranslation(); | |||
| const dispatch = useDispatch(); | |||
| const sorting = useSorting(() => {}, sortCategoriesEnum); | |||
| const locations = useSelector(selectLocations); | |||
| const manualSearchString = useSelector(selectManualSearchString); | |||
| useEffect(() => { | |||
| dispatch(fetchLocations()); | |||
| return () => { | |||
| dispatch(setManualSearchString("")); | |||
| sorting.clear(); | |||
| }; | |||
| }, []); | |||
| const handleSearch = (value) => { | |||
| console.log(value); | |||
| @@ -32,13 +40,9 @@ const AdminLocationsPage = () => { | |||
| }; | |||
| const locationsToShow = useMemo(() => { | |||
| 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 ( | |||
| <> | |||
| <AdminLocationsPageContainer> | |||
| @@ -53,6 +57,7 @@ const AdminLocationsPage = () => { | |||
| hideGrid | |||
| isAdmin | |||
| hideBackButton | |||
| sorting={sorting} | |||
| /> | |||
| <LocationsList> | |||
| {locationsToShow.map((category) => ( | |||
| @@ -21,17 +21,22 @@ import CategoryCard from "../../../components/Cards/CategoryCard/CategoryCard"; | |||
| import selectedTheme from "../../../themes"; | |||
| import { useState } from "react"; | |||
| 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 { t } = useTranslation(); | |||
| const dispatch = useDispatch(); | |||
| const categories = useSelector(selectCategories); | |||
| const routeMatch = useRouteMatch(); | |||
| const sorting = useSorting(() => {}, sortCategoriesEnum); | |||
| const manualSearchString = useSelector(selectManualSearchString); | |||
| const [openedAddModal, setOpenedAddModal] = useState(false); | |||
| useEffect(() => { | |||
| dispatch(fetchCategories()); | |||
| return () => dispatch(setManualSearchString("")); | |||
| }, []); | |||
| const handleSearch = (value) => { | |||
| @@ -49,16 +54,14 @@ const AdminSubcategoriesPage = () => { | |||
| const subcategories = useMemo(() => { | |||
| 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 []; | |||
| }, [category, manualSearchString]); | |||
| }, [category, manualSearchString, sorting.selectedSortOptionLocally]); | |||
| console.log("subc", categories); | |||
| return ( | |||
| @@ -87,7 +90,7 @@ const AdminSubcategoriesPage = () => { | |||
| /> | |||
| </SubcategoriesList> | |||
| <AdminSubcategoriesHeader | |||
| hideSorting | |||
| sorting={sorting} | |||
| myOffers | |||
| subcategories | |||
| hideGrid | |||
| @@ -32,10 +32,11 @@ const AdminUsersPage = () => { | |||
| <AdminUsersSearchField | |||
| isAdmin | |||
| handleSearch={handleSearch} | |||
| placeholder={t("admin.subcategories.placeholder")} | |||
| placeholder={t("admin.users.searchPlaceholder")} | |||
| /> | |||
| <AdminUsersHeader | |||
| myOffers | |||
| hideSorting | |||
| category | |||
| hideGrid | |||
| isAdmin | |||
| @@ -5,8 +5,8 @@ const request = axios.create({ | |||
| // baseURL: "http://192.168.88.150:3001/", // DJOLE | |||
| // baseURL: "http://192.168.88.175:3005/", | |||
| // 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, | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| @@ -84,7 +84,7 @@ function* changeMineProfile(payload) { | |||
| if (typeof payload.payload.firmLogo !== "string") | |||
| requestBody.append("file", payload.payload.firmLogo); | |||
| 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) | |||
| requestBody.append( | |||
| "company[contacts][telephone]", | |||
| @@ -0,0 +1,42 @@ | |||
| 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; | |||
| }; | |||