From c3f0508a2e6fba6ee9780c2ad7c582559600725c Mon Sep 17 00:00:00 2001 From: aelassas Date: Thu, 2 Jan 2025 19:28:13 +0100 Subject: [PATCH] Add MapDialog, ViewOnMapButton components and map view to checkout page --- frontend/src/assets/css/checkout.css | 5 ++ frontend/src/assets/css/map-dialog.css | 12 +++ frontend/src/assets/css/search.css | 25 ------ .../src/assets/css/view-on-map-button.css | 25 ++++++ frontend/src/components/Map.tsx | 10 +-- frontend/src/components/MapDialog.tsx | 78 +++++++++++++++++++ frontend/src/components/ViewOnMapButton.tsx | 23 ++++++ frontend/src/lang/search.ts | 2 - frontend/src/lang/view-on-map-button.ts | 14 ++++ frontend/src/pages/Checkout.tsx | 21 +++++ frontend/src/pages/Search.tsx | 73 ++--------------- 11 files changed, 190 insertions(+), 98 deletions(-) create mode 100644 frontend/src/assets/css/map-dialog.css create mode 100644 frontend/src/assets/css/view-on-map-button.css create mode 100644 frontend/src/components/MapDialog.tsx create mode 100644 frontend/src/components/ViewOnMapButton.tsx create mode 100644 frontend/src/lang/view-on-map-button.ts diff --git a/frontend/src/assets/css/checkout.css b/frontend/src/assets/css/checkout.css index 12611901..12c93975 100644 --- a/frontend/src/assets/css/checkout.css +++ b/frontend/src/assets/css/checkout.css @@ -8,6 +8,11 @@ div.checkout { margin: 80px 0 200px 0; } +div.checkout .map { + min-height: 0; + height: 340px; +} + @media only screen and (width <=960px) { div.checkout { flex: 0 1 auto; diff --git a/frontend/src/assets/css/map-dialog.css b/frontend/src/assets/css/map-dialog.css new file mode 100644 index 00000000..9f4adedb --- /dev/null +++ b/frontend/src/assets/css/map-dialog.css @@ -0,0 +1,12 @@ +.map-dialog { + width: 90%; + height: 90%; +} + +.map-dialog-content { + margin: 0; + width: 100%; + display: flex; + align-items: center; + justify-content: center; +} diff --git a/frontend/src/assets/css/search.css b/frontend/src/assets/css/search.css index 3af34373..5c7a8db9 100644 --- a/frontend/src/assets/css/search.css +++ b/frontend/src/assets/css/search.css @@ -17,31 +17,6 @@ div.properties div.col-1 .map { margin-bottom: 3px; } -div.properties div.col-1 .map .view-on-map { - position: absolute; - top: 10px; - right: 10px; - z-index: 10000; - background-color: #062638; - color: #fff; - border: 0; - padding: 5px 10px; - display: flex; - flex-direction: row; - border-radius: 5px; - cursor: pointer; -} - -div.properties div.col-1 .map .view-on-map img { - max-width: 20px; - max-height: 20px; - margin-right: 2px; -} - -div.properties div.col-1 .map .view-on-map span { - margin-top: 2px; -} - div.properties div.col-1 .filter, div.properties div.col-1 div.info-box { background-color: #fff; diff --git a/frontend/src/assets/css/view-on-map-button.css b/frontend/src/assets/css/view-on-map-button.css new file mode 100644 index 00000000..5edea309 --- /dev/null +++ b/frontend/src/assets/css/view-on-map-button.css @@ -0,0 +1,25 @@ +.view-on-map { + position: absolute; + top: 10px; + right: 10px; + z-index: 10000; + /* background-color: #062638; */ + background-color: #1a1a1a; + color: #fff; + border: 0; + padding: 5px 10px; + display: flex; + flex-direction: row; + border-radius: 5px; + cursor: pointer; +} + +.view-on-map img { + max-width: 20px; + max-height: 20px; + margin-right: 2px; +} + +.view-on-map span { + margin-top: 2px; +} diff --git a/frontend/src/components/Map.tsx b/frontend/src/components/Map.tsx index 996f2eed..f8c3e4df 100644 --- a/frontend/src/components/Map.tsx +++ b/frontend/src/components/Map.tsx @@ -4,7 +4,7 @@ import L, { LatLngExpression } from 'leaflet' import icon from 'leaflet/dist/images/marker-icon.png' import iconShadow from 'leaflet/dist/images/marker-shadow.png' import * as movininTypes from ':movinin-types' -import * as UserService from '@/services/UserService' +// import * as UserService from '@/services/UserService' import { strings } from '@/lang/map' import * as LocationService from '@/services/LocationService' import * as helper from '@/common/helper' @@ -94,15 +94,13 @@ const Map = ({ // // Tile server // - const language = UserService.getLanguage() - let tileURL = 'https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png' + const tileURL = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' + // const language = UserService.getLanguage() + // let tileURL = 'https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png' // if (language === 'fr') { // tileURL = 'https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png' // } - if (language === 'el') { - tileURL = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' - } const getLocationMarkers = (): Marker[] => ( (locations diff --git a/frontend/src/components/MapDialog.tsx b/frontend/src/components/MapDialog.tsx new file mode 100644 index 00000000..14eaf3a1 --- /dev/null +++ b/frontend/src/components/MapDialog.tsx @@ -0,0 +1,78 @@ +import React, { useCallback, useEffect, useState } from 'react' +import { Box, Dialog, DialogContent, DialogTitle, IconButton } from '@mui/material' +import { Close as CloseIcon } from '@mui/icons-material' +import * as movininTypes from ':movinin-types' +import env from '@/config/env.config' +import Map from '@/components/Map' + +import '@/assets/css/map-dialog.css' + +interface MapDialogProps { + location?: movininTypes.Location + openMapDialog: boolean + onClose: () => void +} + +const MapDialog = ({ + location, + openMapDialog: openMapDialogProp, + onClose, +}: MapDialogProps) => { + const [openMapDialog, setOpenMapDialog] = useState(openMapDialogProp) + + useEffect(() => { + setOpenMapDialog(openMapDialogProp) + }, [openMapDialogProp]) + + const close = useCallback(() => { + setOpenMapDialog(false) + if (onClose) { + onClose() + } + }, [onClose]) + + return ( + { + close() + }} + sx={{ + '& .MuiDialog-container': { + '& .MuiPaper-root': { + width: '90%', + height: '90%', + }, + }, + }} + > + + + + { + close() + }} + > + + + + + + + {location && ( + + )} + + + ) +} + +export default MapDialog diff --git a/frontend/src/components/ViewOnMapButton.tsx b/frontend/src/components/ViewOnMapButton.tsx new file mode 100644 index 00000000..db916236 --- /dev/null +++ b/frontend/src/components/ViewOnMapButton.tsx @@ -0,0 +1,23 @@ +import React from 'react' +import { strings } from '@/lang/view-on-map-button' + +import ViewOnMap from '@/assets/img/view-on-map.png' + +import '@/assets/css/view-on-map-button.css' + +interface ViewOnMapButtonProps { + onClick: (e?: React.MouseEvent) => void +} + +const ViewOnMapButton = ({ onClick }: ViewOnMapButtonProps) => ( + +) + +export default ViewOnMapButton diff --git a/frontend/src/lang/search.ts b/frontend/src/lang/search.ts index c0b3b170..86bb4f46 100644 --- a/frontend/src/lang/search.ts +++ b/frontend/src/lang/search.ts @@ -3,10 +3,8 @@ import * as langHelper from '@/common/langHelper' const strings = new LocalizedStrings({ fr: { - VIEW_ON_MAP: 'Voir sur la carte', }, en: { - VIEW_ON_MAP: 'View on map', }, }) diff --git a/frontend/src/lang/view-on-map-button.ts b/frontend/src/lang/view-on-map-button.ts new file mode 100644 index 00000000..c0b3b170 --- /dev/null +++ b/frontend/src/lang/view-on-map-button.ts @@ -0,0 +1,14 @@ +import LocalizedStrings from 'localized-strings' +import * as langHelper from '@/common/langHelper' + +const strings = new LocalizedStrings({ + fr: { + VIEW_ON_MAP: 'Voir sur la carte', + }, + en: { + VIEW_ON_MAP: 'View on map', + }, +}) + +langHelper.setLanguage(strings) +export { strings } diff --git a/frontend/src/pages/Checkout.tsx b/frontend/src/pages/Checkout.tsx index d1198c02..b6d2a762 100644 --- a/frontend/src/pages/Checkout.tsx +++ b/frontend/src/pages/Checkout.tsx @@ -47,6 +47,9 @@ import Info from './Info' import SocialLogin from '@/components/SocialLogin' import CheckoutOptions from '@/components/CheckoutOptions' import Footer from '@/components/Footer' +import Map from '@/components/Map' +import ViewOnMapButton from '@/components/ViewOnMapButton' +import MapDialog from '@/components/MapDialog' import '@/assets/css/checkout.css' @@ -94,6 +97,7 @@ const Checkout = () => { const [clientSecret, setClientSecret] = useState(null) const [bookingId, setBookingId] = useState() const [sessionId, setSessionId] = useState() + const [openMapDialog, setOpenMapDialog] = useState(false) const _fr = language === 'fr' const _locale = _fr ? fr : enUS @@ -402,6 +406,17 @@ const Checkout = () => {
+ {(location.latitude && location.longitude) && ( + + setOpenMapDialog(true)} /> + + )} + { )} {noMatch && } {success && } + + setOpenMapDialog(false)} + /> ) } diff --git a/frontend/src/pages/Search.tsx b/frontend/src/pages/Search.tsx index a32ec95c..c456682e 100644 --- a/frontend/src/pages/Search.tsx +++ b/frontend/src/pages/Search.tsx @@ -1,12 +1,8 @@ import React, { useState } from 'react' import { useLocation } from 'react-router-dom' -import { Box, Dialog, DialogContent, DialogTitle, IconButton } from '@mui/material' -import { Close as CloseIcon } from '@mui/icons-material' import * as movininTypes from ':movinin-types' import * as movininHelper from ':movinin-helper' -import env from '@/config/env.config' import * as helper from '@/common/helper' -import { strings } from '@/lang/search' import * as LocationService from '@/services/LocationService' import * as AgencyService from '@/services/AgencyService' import Layout from '@/components/Layout' @@ -17,8 +13,8 @@ import RentalTermFilter from '@/components/RentalTermFilter' import PropertyList from '@/components/PropertyList' import PropertyTypeFilter from '@/components/PropertyTypeFilter' import Map from '@/components/Map' - -import ViewOnMap from '@/assets/img/view-on-map.png' +import ViewOnMapButton from '@/components/ViewOnMapButton' +import MapDialog from '@/components/MapDialog' import '@/assets/css/search.css' @@ -112,16 +108,7 @@ const Properties = () => { locations={[location]} className="map" > - + setOpenMapDialog(true)} /> )} {
)} - { - setOpenMapDialog(false) - }} - sx={{ - '& .MuiDialog-container': { - '& .MuiPaper-root': { - width: '80%', - height: '800px', - }, - }, - }} - > - - - - { - setOpenMapDialog(false) - }} - > - - - - - - - {location && ( - - - - )} - - + setOpenMapDialog(false)} + /> {noMatch && }