Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

51 registruojant izuvinima ivedant telkinio informacija issoka pakartotinis popup #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/components/fields/LocationInput.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import { isEmpty } from 'lodash';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import styled from 'styled-components';
import { useRecentLocations } from '../../utils/hooks';
import { inputLabels } from '../../utils/texts';
import Icon from '../other/Icon';
import FieldWrapper from './components/FieldWrapper';
import TextFieldInput from './components/TextFieldInput';
import { Location } from '../../utils/types';

const LocationInput = ({ onChange, error, disabled, value, handleSelectMap }: any) => {
export interface LocationInputProps {
onOpen: () => void;
handleSelectMap: () => void;
onChange: (recentLocation: Location) => void;
error?: string;
value?: string;
disabled?: boolean;
}

const LocationInput = ({
onChange,
error,
disabled,
value,
handleSelectMap,
onOpen,
}: LocationInputProps) => {
const [showSelect, setShowSelect] = useState(false);

const recentLocations = useRecentLocations();
Expand All @@ -21,6 +38,10 @@ const LocationInput = ({ onChange, error, disabled, value, handleSelectMap }: an
!disabled && setShowSelect(!showSelect);
};

useEffect(() => {
showSelect && onOpen && onOpen();
}, [showSelect, onOpen]);

return (
<FieldWrapper
onClick={handleToggleSelect}
Expand Down Expand Up @@ -50,7 +71,7 @@ const LocationInput = ({ onChange, error, disabled, value, handleSelectMap }: an
{!isEmpty(recentLocations) && (
<>
<HistoryTitle>Paskutinės paieškos</HistoryTitle>
{recentLocations.map((recentLocation: any) => {
{recentLocations.map((recentLocation: Location) => {
return (
<OptionRowContainer
onClick={() => onChange(recentLocation)}
Expand Down
7 changes: 7 additions & 0 deletions src/components/forms/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const RegistrationForm = ({
disabled?: boolean;
}) => {
const [showMap, setShowMap] = useState(false);
const [isMapPreviewMode, toggleMapPreviewMode] = useState(false);
const [queryString, setQueryString] = useState('');
const isMobile = useMediaQuery(device.mobileL);
const fishAges = useFishAges();
Expand Down Expand Up @@ -237,11 +238,16 @@ const RegistrationForm = ({
error={errors.location}
disabled={disabled}
value={values?.location?.name}
onOpen={() => toggleMapPreviewMode(true)}
handleSelectMap={() => {
toggleMapPreviewMode(false);
setQueryString(queryStrings.draw);
setShowMap(true);
setFieldValue('geom', undefined);
setFieldValue('location', undefined);
}}
onChange={(location: any) => {
toggleMapPreviewMode(true);
const { geom, ...rest } = location;
iframeRef?.current?.contentWindow?.postMessage(JSON.stringify({ geom }), '*');
setFieldValue('geom', geom);
Expand Down Expand Up @@ -428,6 +434,7 @@ const RegistrationForm = ({
</StyledForm>
<Map
iframeRef={iframeRef}
isMapPreviewMode={isMapPreviewMode}
display={!isMobile || showMap}
onClose={() => setShowMap(false)}
value={values.geom}
Expand Down
20 changes: 18 additions & 2 deletions src/components/other/RegistrationMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,31 @@ export interface MapProps {
value?: string;
display: boolean;
iframeRef: any;
isMapPreviewMode: boolean;
}

const Map = ({ height, onSave, onClose, value, display, iframeRef }: MapProps) => {
const Map = ({
isMapPreviewMode,
height,
onSave,
onClose,
value,
display,
iframeRef,
}: MapProps) => {
const [showModal, setShowModal] = useState(false);
const [geom, setGeom] = useState<any[]>();
const [loading, setLoading] = useState(true);
const isMobile = useMediaQuery(device.mobileL);

const src = `${Url.DRAW}`;
const getMapUrl = () => {
const url = new URL(Url.DRAW);
const params = new URLSearchParams(url.search);
params.append('preview', isMapPreviewMode ? 'true' : 'false');
url.search = params.toString();
return url.href;
};
const src = getMapUrl();

const handleLoadMap = () => {
setLoading(false);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export interface FishBatch {
reviewAmount?: number;
}

export interface Location {
cadastral_id: string;
geom: any;
municipality: { id: string; name: string };
name: string;
}

export interface FishStocking {
id: number;
geom: any;
Expand Down
Loading