|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import { Button } from "antd";
|
|
|
|
|
import {Button, Spin} from "antd";
|
|
|
|
|
import { CATEGORIES, MODES, STATUSES } from "../../config";
|
|
|
|
|
import { useMode } from "../../stores/useMode";
|
|
|
|
|
import { LAYER_IDS } from "../Layers/constants";
|
|
|
|
|
@ -9,57 +9,13 @@ import { WorkingPointPopup } from "./mode-popup/WorkingPointPopup";
|
|
|
|
|
import { FeatureProperties } from "./mode-popup/FeatureProperties";
|
|
|
|
|
import { usePopup } from "../../stores/usePopup.js";
|
|
|
|
|
import { PanoramaIcon } from "../../icons/PanoramaIcon";
|
|
|
|
|
import {useOtherGroups, usePostamatesAndPvzGroups} from "../../api.js";
|
|
|
|
|
import {useMemo} from "react";
|
|
|
|
|
import {doesMatchFilter, getFilteredGroups} from "../../utils.js";
|
|
|
|
|
import { useGetPopupPoints } from "../../api.js";
|
|
|
|
|
import { doesMatchFilter } from "../../utils.js";
|
|
|
|
|
import Checkbox from "antd/es/checkbox/Checkbox";
|
|
|
|
|
import {usePointSelection} from "../../stores/usePointSelection.js";
|
|
|
|
|
import {usePendingPointsFilters} from "../../stores/usePendingPointsFilters.js";
|
|
|
|
|
import { usePointSelection } from "../../stores/usePointSelection.js";
|
|
|
|
|
import { usePendingPointsFilters } from "../../stores/usePendingPointsFilters.js";
|
|
|
|
|
|
|
|
|
|
const getRivalsName = (feature) => {
|
|
|
|
|
const { data: postamatesAndPvzGroups } = usePostamatesAndPvzGroups();
|
|
|
|
|
const { data: otherGroups } = useOtherGroups();
|
|
|
|
|
|
|
|
|
|
const filteredPostamatesCategories = useMemo(() => {
|
|
|
|
|
return getFilteredGroups(postamatesAndPvzGroups);
|
|
|
|
|
}, [postamatesAndPvzGroups]);
|
|
|
|
|
|
|
|
|
|
const filteredOtherCategories = useMemo(() => {
|
|
|
|
|
return getFilteredGroups(otherGroups);
|
|
|
|
|
}, [otherGroups]);
|
|
|
|
|
|
|
|
|
|
const filteredPostamatesGroups = useMemo(() => {
|
|
|
|
|
if (!filteredPostamatesCategories) return [];
|
|
|
|
|
return filteredPostamatesCategories
|
|
|
|
|
.map((category) => {
|
|
|
|
|
return [...category.groups]
|
|
|
|
|
}).flat();
|
|
|
|
|
}, [filteredPostamatesCategories]);
|
|
|
|
|
|
|
|
|
|
const filteredOtherGroups = useMemo(() => {
|
|
|
|
|
if (!filteredOtherCategories) return [];
|
|
|
|
|
return filteredOtherCategories
|
|
|
|
|
.map((category) => {
|
|
|
|
|
return [...category.groups]
|
|
|
|
|
}).flat();
|
|
|
|
|
}, [filteredOtherCategories]);
|
|
|
|
|
|
|
|
|
|
const isOther = feature.layer?.id.includes(LAYER_IDS.other);
|
|
|
|
|
const name = isOther ?
|
|
|
|
|
filteredOtherCategories.find(c => c.id === feature.properties.category_id)?.name :
|
|
|
|
|
filteredPostamatesCategories.find(c => c.id === feature.properties.category_id)?.name;
|
|
|
|
|
|
|
|
|
|
const groupName = isOther ?
|
|
|
|
|
filteredOtherGroups.find(c => c.id === feature.properties.group_id)?.name :
|
|
|
|
|
filteredPostamatesGroups.find(c => c.id === feature.properties.group_id)?.name;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
name,
|
|
|
|
|
groupName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SingleFeaturePopup = ({ feature }) => {
|
|
|
|
|
const SingleFeaturePopup = ({ feature, point }) => {
|
|
|
|
|
const { mode } = useMode();
|
|
|
|
|
const isRivals =
|
|
|
|
|
feature.layer?.id.includes(LAYER_IDS.pvz) ||
|
|
|
|
|
@ -68,25 +24,24 @@ const SingleFeaturePopup = ({ feature }) => {
|
|
|
|
|
const isWorkingPoint = feature.properties.status === STATUSES.working;
|
|
|
|
|
|
|
|
|
|
if (isRivals) {
|
|
|
|
|
const { name, groupName } = getRivalsName(feature);
|
|
|
|
|
return <FeatureProperties feature={feature} name={name} groupName={groupName} />;
|
|
|
|
|
return <FeatureProperties feature={feature} point={point} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode === MODES.ON_APPROVAL && !isPendingPoint) {
|
|
|
|
|
return <OnApprovalPointPopup feature={feature} />;
|
|
|
|
|
return <OnApprovalPointPopup feature={feature} point={point} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode === MODES.WORKING && isWorkingPoint) {
|
|
|
|
|
return <WorkingPointPopup feature={feature} />;
|
|
|
|
|
return <WorkingPointPopup feature={feature} point={point} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode === MODES.PENDING && isPendingPoint)
|
|
|
|
|
return <PendingPointPopup feature={feature} />;
|
|
|
|
|
return <PendingPointPopup feature={feature} point={point} />;
|
|
|
|
|
|
|
|
|
|
return <FeatureProperties feature={feature} />;
|
|
|
|
|
return <FeatureProperties feature={feature} point={point} />;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const MultipleFeaturesPopup = ({ features }) => {
|
|
|
|
|
const MultipleFeaturesPopup = ({ features, points }) => {
|
|
|
|
|
const { setPopup } = usePopup();
|
|
|
|
|
const { selection, include, exclude } = usePointSelection();
|
|
|
|
|
const { filters, ranges } = usePendingPointsFilters();
|
|
|
|
|
@ -95,8 +50,10 @@ const MultipleFeaturesPopup = ({ features }) => {
|
|
|
|
|
<div className="space-y-2 p-1">
|
|
|
|
|
{features.map((feature) => {
|
|
|
|
|
const featureId = feature.properties.id;
|
|
|
|
|
const point = points.find(p => p.id = featureId);
|
|
|
|
|
const isSelected = (doesMatchFilter(filters, ranges, feature) && !selection.excluded.has(featureId)) ||
|
|
|
|
|
selection.included.has(featureId);
|
|
|
|
|
console.log(isSelected, doesMatchFilter(filters, ranges, feature));
|
|
|
|
|
const handleSelect = () => {
|
|
|
|
|
if (isSelected) {
|
|
|
|
|
exclude(featureId);
|
|
|
|
|
@ -127,15 +84,15 @@ const MultipleFeaturesPopup = ({ features }) => {
|
|
|
|
|
{feature.properties.category === CATEGORIES.residential ? (
|
|
|
|
|
<div className="space-x-2 flex items-center w-full">
|
|
|
|
|
<span className="flex-1 truncate inline-block">
|
|
|
|
|
{feature.properties.address}
|
|
|
|
|
{point.address}
|
|
|
|
|
</span>
|
|
|
|
|
<span>{feature.properties.name}</span>
|
|
|
|
|
<span>{point.name}</span>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex w-full">
|
|
|
|
|
<span className="truncate">
|
|
|
|
|
{feature.properties.name ?? feature.properties.category}
|
|
|
|
|
{feature.properties.category_id && getRivalsName(feature).name}
|
|
|
|
|
{point.name ?? point.category}
|
|
|
|
|
{point.category_id && getRivalsName(feature).name}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
@ -159,19 +116,20 @@ const YandexPanoramaLink = ({ lat, lng }) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const MapPopup = ({ features, lat, lng, onClose }) => {
|
|
|
|
|
const {data: points, isLoading} = useGetPopupPoints(features);
|
|
|
|
|
|
|
|
|
|
const getContent = () => {
|
|
|
|
|
if (features.length === 1) {
|
|
|
|
|
return <SingleFeaturePopup feature={features[0]} />;
|
|
|
|
|
return <SingleFeaturePopup feature={features[0]} point={points[0]}/>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <MultipleFeaturesPopup features={features} />;
|
|
|
|
|
return <MultipleFeaturesPopup features={features} points={points} />;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<PopupWrapper lat={lat} lng={lng} onClose={onClose}>
|
|
|
|
|
<YandexPanoramaLink lat={lat} lng={lng}/>
|
|
|
|
|
{getContent()}
|
|
|
|
|
{isLoading ? <Spin /> : getContent()}
|
|
|
|
|
</PopupWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|