|
|
|
|
@ -9,21 +9,65 @@ import { WorkingPointPopup } from "./mode-popup/WorkingPointPopup";
|
|
|
|
|
import { FeatureProperties } from "./mode-popup/FeatureProperties";
|
|
|
|
|
import { usePopup } from "../../stores/usePopup.js";
|
|
|
|
|
import { PanoramaIcon } from "../../icons/PanoramaIcon";
|
|
|
|
|
import {usePostamatesAndPvzGroups} from "../../api.js";
|
|
|
|
|
import {useOtherGroups, usePostamatesAndPvzGroups} from "../../api.js";
|
|
|
|
|
import {useMemo} from "react";
|
|
|
|
|
import {getFilteredGroups} from "../../utils.js";
|
|
|
|
|
|
|
|
|
|
const SingleFeaturePopup = ({ feature, groups, categories }) => {
|
|
|
|
|
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 { mode } = useMode();
|
|
|
|
|
const isRivals =
|
|
|
|
|
feature.layer?.id === LAYER_IDS.pvz ||
|
|
|
|
|
feature.layer?.id === LAYER_IDS.other ||
|
|
|
|
|
feature.layer?.id.includes(LAYER_IDS.pvz);
|
|
|
|
|
feature.layer?.id.includes(LAYER_IDS.pvz) ||
|
|
|
|
|
feature.layer?.id.includes(LAYER_IDS.other);
|
|
|
|
|
const isPendingPoint = feature.properties.status === STATUSES.pending;
|
|
|
|
|
const isWorkingPoint = feature.properties.status === STATUSES.working;
|
|
|
|
|
|
|
|
|
|
console.log(feature)
|
|
|
|
|
if (isRivals) {
|
|
|
|
|
return <FeatureProperties feature={feature} groups={groups} categories={categories} />;
|
|
|
|
|
const { name, groupName } = getRivalsName(feature);
|
|
|
|
|
return <FeatureProperties feature={feature} name={name} groupName={groupName} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode === MODES.ON_APPROVAL && !isPendingPoint) {
|
|
|
|
|
@ -40,7 +84,7 @@ const SingleFeaturePopup = ({ feature, groups, categories }) => {
|
|
|
|
|
return <FeatureProperties feature={feature} />;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const MultipleFeaturesPopup = ({ features, categories }) => {
|
|
|
|
|
const MultipleFeaturesPopup = ({ features }) => {
|
|
|
|
|
const { setPopup } = usePopup();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
@ -69,7 +113,7 @@ const MultipleFeaturesPopup = ({ features, categories }) => {
|
|
|
|
|
<div className="flex w-full">
|
|
|
|
|
<span className="truncate">
|
|
|
|
|
{feature.properties.name ?? feature.properties.category}
|
|
|
|
|
{feature.properties.category_id && categories.find(c => c.id === feature.properties.category_id).name}
|
|
|
|
|
{feature.properties.category_id && getRivalsName(feature).name}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
@ -92,26 +136,13 @@ const YandexPanoramaLink = ({ lat, lng }) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const MapPopup = ({ features, lat, lng, onClose }) => {
|
|
|
|
|
const { data: postamatesAndPvzGroups } = usePostamatesAndPvzGroups();
|
|
|
|
|
|
|
|
|
|
const filteredPostamatesCategories = useMemo(() => {
|
|
|
|
|
return getFilteredGroups(postamatesAndPvzGroups);
|
|
|
|
|
}, [postamatesAndPvzGroups]);
|
|
|
|
|
|
|
|
|
|
const postamatesGroups = useMemo(() => {
|
|
|
|
|
if (!filteredPostamatesCategories) return [];
|
|
|
|
|
return filteredPostamatesCategories
|
|
|
|
|
.map((category) => {
|
|
|
|
|
return [...category.groups]
|
|
|
|
|
}).flat();
|
|
|
|
|
}, [filteredPostamatesCategories]);
|
|
|
|
|
|
|
|
|
|
const getContent = () => {
|
|
|
|
|
if (features.length === 1) {
|
|
|
|
|
return <SingleFeaturePopup feature={features[0]} groups={postamatesGroups} categories={filteredPostamatesCategories} />;
|
|
|
|
|
return <SingleFeaturePopup feature={features[0]} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <MultipleFeaturesPopup features={features} categories={filteredPostamatesCategories} />;
|
|
|
|
|
return <MultipleFeaturesPopup features={features} />;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|