|
|
|
@@ -4,11 +4,8 @@ import { |
|
|
|
AdminPaymentPageContainer, |
|
|
|
AdminPaymentsHeader, |
|
|
|
AdminPaymentsSearchField, |
|
|
|
// FilterButtonIcon, |
|
|
|
// FilterButtonContainer, |
|
|
|
NewPaymentButton, |
|
|
|
PaymentsList, |
|
|
|
// FilterButton, |
|
|
|
} from "./AdminPaymentPage.styled"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import useSorting from "../../../hooks/useOffers/useSorting"; |
|
|
|
@@ -22,9 +19,9 @@ import { selectPayments } from "../../../store/selectors/paymentSelector"; |
|
|
|
import { selectManualSearchString } from "../../../store/selectors/filtersSelectors"; |
|
|
|
import { fetchPayments } from "../../../store/actions/payment/paymentActions"; |
|
|
|
import { adminSortMethod } from "../../../util/helpers/adminSortHelper"; |
|
|
|
import { useHistory } from "react-router-dom"; |
|
|
|
import { selectAllProfiles } from "../../../store/selectors/profileSelectors"; |
|
|
|
import { fetchAllProfiles } from "../../../store/actions/profile/profileActions"; |
|
|
|
import useQueryString from "../../../hooks/useOffers/useQueryString"; |
|
|
|
|
|
|
|
const AdminPaymentPage = () => { |
|
|
|
const { t } = useTranslation(); |
|
|
|
@@ -33,10 +30,8 @@ const AdminPaymentPage = () => { |
|
|
|
const payments = useSelector(selectPayments); |
|
|
|
const users = useSelector(selectAllProfiles); |
|
|
|
const manualSearchString = useSelector(selectManualSearchString); |
|
|
|
const history = useHistory(); |
|
|
|
const user = history?.location?.search?.split("=")[1]; |
|
|
|
const userName = user?.replaceAll("+", " "); |
|
|
|
const userId = users?.filter?.((user) => user.companyName === userName); |
|
|
|
const queryObject = useQueryString(); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
dispatch(fetchPayments()); |
|
|
|
dispatch(fetchAllProfiles()); |
|
|
|
@@ -45,21 +40,35 @@ const AdminPaymentPage = () => { |
|
|
|
sorting.clear(); |
|
|
|
}; |
|
|
|
}, []); |
|
|
|
|
|
|
|
const checkedUsers = useMemo(() => { |
|
|
|
if (queryObject.queryObject.companyName) { |
|
|
|
return users?.filter?.((user) => |
|
|
|
queryObject?.queryObject?.companyName?.includes(user.companyName) |
|
|
|
); |
|
|
|
} else { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
}, [users, queryObject?.queryObject]); |
|
|
|
|
|
|
|
const checkedUsersIds = |
|
|
|
checkedUsers && checkedUsers?.map((item) => item?._id); |
|
|
|
|
|
|
|
const paymentsToShow = useMemo(() => { |
|
|
|
if (payments && history?.location?.search === "") { |
|
|
|
if (payments && !queryObject?.queryObject?.companyName) { |
|
|
|
return adminSortMethod(payments, manualSearchString, sorting); |
|
|
|
} |
|
|
|
if (history.location.search) { |
|
|
|
const filteredPayments = payments?.filter( |
|
|
|
(payment) => payment?.user?._id === userId[0]?._id |
|
|
|
if (queryObject?.queryObject?.companyName.length > 0) { |
|
|
|
const filteredPayments = payments?.filter((payment) => |
|
|
|
checkedUsersIds.includes(payment?.user?._id) |
|
|
|
); |
|
|
|
return filteredPayments; |
|
|
|
return adminSortMethod(filteredPayments, manualSearchString, sorting); |
|
|
|
} |
|
|
|
}, [ |
|
|
|
payments, |
|
|
|
manualSearchString, |
|
|
|
sorting.selectedSortOptionLocally, |
|
|
|
history.location.search, |
|
|
|
queryObject.queryObject.companyName, |
|
|
|
]); |
|
|
|
|
|
|
|
const handleSearch = (value) => { |
|
|
|
@@ -84,11 +93,7 @@ const AdminPaymentPage = () => { |
|
|
|
> |
|
|
|
{t("admin.payment.addPayment")} |
|
|
|
</NewPaymentButton> |
|
|
|
{/* <FilterButtonContainer> |
|
|
|
<FilterButton> |
|
|
|
<FilterButtonIcon /> |
|
|
|
</FilterButton> |
|
|
|
</FilterButtonContainer> */} |
|
|
|
|
|
|
|
<AdminPaymentsHeader |
|
|
|
myOffers |
|
|
|
payments |