From cc627fe1f39cecab46f6cc1907dc25c34359c002 Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Tue, 2 Jul 2024 12:28:50 +0200 Subject: [PATCH] update mantine and fix some other issues --- app/components/LeafletMap.client.tsx | 88 +++++++++--------- app/routes/$.tsx | 130 ++++++++++++++++++++------- app/routes/book.$handle.tsx | 40 +++++++-- app/routes/users._index.tsx | 2 +- package-lock.json | 74 +++++++-------- package.json | 12 +-- 6 files changed, 217 insertions(+), 129 deletions(-) diff --git a/app/components/LeafletMap.client.tsx b/app/components/LeafletMap.client.tsx index a4cdbea1..d445ae15 100644 --- a/app/components/LeafletMap.client.tsx +++ b/app/components/LeafletMap.client.tsx @@ -1,10 +1,15 @@ -import {Avatar, MantineProvider} from '@mantine/core'; +import {Avatar, Box, MantineProvider} from '@mantine/core'; import L, {divIcon, point} from 'leaflet'; import {useEffect} from 'react'; import {renderToStaticMarkup} from 'react-dom/server'; -import {MapContainer, Marker, Popup, TileLayer, useMap} from 'react-leaflet'; -import {type TreatmentsForCollectionFragment} from 'storefrontapi.generated'; -import {type CustomerLocationAllOfGeoLocation} from '~/lib/api/model'; +import { + Circle, + MapContainer, + Marker, + Popup, + TileLayer, + useMap, +} from 'react-leaflet'; export type Coordinates = { lat: number; @@ -29,50 +34,28 @@ const AutoCenterMap = ({markers}: {markers: Coordinates[]}) => { useEffect(() => { if (markers.length > 0) { const bounds = L.latLngBounds(markers); - map.fitBounds(bounds, {padding: [100, 100]}); + map.fitBounds(bounds, {padding: [1000, 1000]}); + map.zoomOut(12); } }, [markers, map]); return null; }; -export function LeafletMap({ - products, -}: { - products: TreatmentsForCollectionFragment[]; -}) { - const geoLocations = products.reduce((geos, product) => { - const newGeos = product.locations?.references?.nodes.reduce((geos, l) => { - if (l.geoLocation?.value) { - const value = JSON.parse( - l.geoLocation.value, - ) as CustomerLocationAllOfGeoLocation; - geos.push({ - lat: value.coordinates[1], - lng: value.coordinates[0], - image: product.user?.reference?.image?.reference?.image?.url || '', - }); - } - return geos; - }, [] as Coordinates[]); - if (newGeos) { - geos.push(...newGeos); - } - return geos; - }, [] as Coordinates[]); +export type LeafletMapMarker = { + id: string; + lng: number; + lat: number; + image: string; + radius: number | null; +}; +export function LeafletMap({markers}: {markers: Array}) { return ( -
+ @@ -80,21 +63,30 @@ export function LeafletMap({ attribution='© OpenStreetMap contributors' url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" /> - {geoLocations.map((geo) => { - return ( + {markers.map((geo) => + geo.radius ? ( + + Kører ud til de her områder. + + ) : ( - - A pretty CSS3 popup.
Easily customizable. -
+ Salon/Hjem position.
- ); - })} - + ), + )} +
-
+ ); } diff --git a/app/routes/$.tsx b/app/routes/$.tsx index 27c2fe30..5d3e2ee1 100644 --- a/app/routes/$.tsx +++ b/app/routes/$.tsx @@ -9,6 +9,7 @@ import { Flex, Grid, Group, + Loader, rem, Skeleton, Spoiler, @@ -18,13 +19,14 @@ import { UnstyledButton, } from '@mantine/core'; import '@mantine/tiptap/styles.css'; -import {Await, Link, Outlet, useLoaderData} from '@remix-run/react'; +import {Await, Link, useLoaderData} from '@remix-run/react'; import { defer, + type LinksFunction, type LoaderFunctionArgs, type MetaFunction, } from '@shopify/remix-oxygen'; -import {Suspense, useEffect, useMemo, useState} from 'react'; +import React, {Suspense, useEffect, useMemo, useState} from 'react'; import {parseGid} from '@shopify/hydrogen'; import {da} from 'date-fns/locale'; @@ -43,16 +45,38 @@ import type { } from 'storefrontapi.generated'; import {LocationIcon} from '~/components/LocationIcon'; -import {type CustomerScheduleSlot} from '~/lib/api/model'; +import { + type CustomerLocationAllOfGeoLocation, + type CustomerScheduleSlot, +} from '~/lib/api/model'; import {convertLocations} from '~/lib/convertLocations'; import {useDuration} from '~/lib/duration'; import {AE, DK, US} from 'country-flag-icons/react/3x2'; +import leafletStyles from 'leaflet/dist/leaflet.css?url'; import {useTranslation} from 'react-i18next'; +import {ClientOnly} from 'remix-utils/client-only'; +import { + LeafletMap, + type LeafletMapMarker, +} from '~/components/LeafletMap.client'; import {USER_METAOBJECT_QUERY} from '~/graphql/fragments/UserMetaobject'; import {GET_USER_PRODUCTS} from '~/graphql/queries/GetUserProducts'; import {UserProvider, useUser} from '~/hooks/use-user'; +import localLeafletStyles from '~/styles/leaflet.css?url'; + +export const links: LinksFunction = () => [ + { + rel: 'stylesheet', + href: leafletStyles, + }, + { + rel: 'stylesheet', + href: localLeafletStyles, + }, +]; + export const handle: Handle = { i18n: ['global', 'profile', 'professions', 'skills'], }; @@ -338,6 +362,7 @@ function UserTreatments() { {t('treatments_title')} + }> {({collection}) => { @@ -349,22 +374,28 @@ function UserTreatments() { collections[product.productType].push(product); return collections; }, {} as Record) || {}; + return ( - {Object.keys(collections).map((key) => ( - - - {key} - - - {collections[key].map((product) => ( - - ))} + {Object.keys(collections) + .sort() + .map((key) => ( + + + {key} + + + {collections[key].map((product) => ( + + ))} + - - ))} + ))} @@ -393,7 +424,6 @@ function UserTreatments() { ); }} - ); @@ -417,8 +447,32 @@ async function wordToColor(word: string) { function Schedule({schedule}: {schedule: ScheduleFragment}) { const {t} = useTranslation(['profile', 'global']); + const user = useUser(); const [scheduleColor, setScheduleColor] = useState('#fff'); + const markers = useMemo( + () => + schedule.locations?.references?.nodes.reduce((geos, l) => { + if (l.geoLocation?.value) { + const value = JSON.parse( + l.geoLocation.value, + ) as CustomerLocationAllOfGeoLocation; + geos.push({ + id: l.id, + lat: value.coordinates[1], + lng: value.coordinates[0], + radius: + l.locationType?.value === 'destination' + ? parseInt(l.maxDriveDistance?.value || '0') * 1000 + : null, + image: user.image.url, + }); + } + return geos; + }, [] as LeafletMapMarker[]) || [], + [schedule.locations?.references?.nodes, user.image.url], + ); + useEffect(() => { const fetchColor = async () => { const color = await wordToColor(schedule.handle || ''); @@ -443,7 +497,7 @@ function Schedule({schedule}: {schedule: ScheduleFragment}) { {t('openingtime')} - + {slots?.map((slot) => { return ( @@ -467,12 +521,13 @@ function Schedule({schedule}: {schedule: ScheduleFragment}) { ); })} - - - - - {schedule.locations?.references?.nodes.map((location) => ( - + + {schedule.locations?.references?.nodes.map((location) => ( + + + + + - { - location.fullAddress?.value?.split(',')[ - location.fullAddress?.value?.split(',').length - 1 - ] - } + + { + location.fullAddress?.value?.split(',')[ + location.fullAddress?.value?.split(',').length - 1 + ] + } + + Hvor skønhedseksperten kører ud til! ) : ( - <>{location.fullAddress?.value} + <> + {location.fullAddress?.value} + Hvor behandling finder sted! + )} - ))} - + + }> + {() => ( + m.id === location.id)} + /> + )} + + + + ))} ); } diff --git a/app/routes/book.$handle.tsx b/app/routes/book.$handle.tsx index 50937aac..a5a2a81d 100644 --- a/app/routes/book.$handle.tsx +++ b/app/routes/book.$handle.tsx @@ -1,6 +1,7 @@ import { ActionIcon, Affix, + Avatar, Box, Card, Container, @@ -33,6 +34,7 @@ import {useTranslation} from 'react-i18next'; import type { PickMoreTreatmentProductFragment, TreatmentOptionVariantFragment, + UserFragment, } from 'storefrontapi.generated'; import {LocationIcon} from '~/components/LocationIcon'; import { @@ -70,6 +72,7 @@ export function shouldRevalidate({ } export type OutletLoader = SerializeFrom & { + user: UserFragment; selectedLocation: CustomerLocation; pickedVariants: TreatmentOptionVariantFragment[]; summary: { @@ -217,13 +220,21 @@ export default function Booking() { )} - + + <Group gap="4px" justify="center"> + <Avatar + size="md" + style={{border: '3px solid #FFF'}} + src={ + user?.image?.reference?.image?.url || + 'https://placehold.co/400x600?text=Ekspert' + } + /> + <Title fz="md" fw="400"> + {user?.fullname?.value} + + + + + + {user.fullname?.value} + + + + {selectedLocation ? (
diff --git a/app/routes/users._index.tsx b/app/routes/users._index.tsx index eb439be2..a39a5572 100644 --- a/app/routes/users._index.tsx +++ b/app/routes/users._index.tsx @@ -237,7 +237,7 @@ export const UserCard = ({article}: {article: ArticleUserFragment}) => { /> )} - asd + {tags['city']} diff --git a/package-lock.json b/package-lock.json index d2991e59..04d8db19 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,12 +16,12 @@ "@fullcalendar/interaction": "^6.1.14", "@fullcalendar/react": "^6.1.14", "@fullcalendar/timegrid": "^6.1.14", - "@mantine/carousel": "^7.10.2", - "@mantine/core": "^7.10.2", - "@mantine/hooks": "^7.10.2", - "@mantine/modals": "^7.10.2", - "@mantine/nprogress": "^7.10.2", - "@mantine/tiptap": "^7.10.2", + "@mantine/carousel": "^7.11.0", + "@mantine/core": "^7.11.0", + "@mantine/hooks": "^7.11.0", + "@mantine/modals": "^7.11.0", + "@mantine/nprogress": "^7.11.0", + "@mantine/tiptap": "^7.11.0", "@remix-run/react": "^2.9.2", "@remix-run/server-runtime": "^2.9.2", "@shopify/cli": "^3.61.2", @@ -3587,21 +3587,21 @@ } }, "node_modules/@mantine/carousel": { - "version": "7.10.2", - "resolved": "https://registry.npmjs.org/@mantine/carousel/-/carousel-7.10.2.tgz", - "integrity": "sha512-/cj4ZSrLuKfJLloClpvmVXsj6WfkCOnG4ipBlleSFvEynzxmNUXC3z1eR6vgh6IRhzpjQPe2PM8YFiMGRljVQg==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@mantine/carousel/-/carousel-7.11.0.tgz", + "integrity": "sha512-NVyChCtBfi8HOZkN6i9FPC2ZGkjjaNTtZDsbu22rYb3iHteKDS76Hp5hy04b2eLGwglHERCMeZu4g5Nf2ZSa/Q==", "peerDependencies": { - "@mantine/core": "7.10.2", - "@mantine/hooks": "7.10.2", + "@mantine/core": "7.11.0", + "@mantine/hooks": "7.11.0", "embla-carousel-react": ">=7.0.0", "react": "^18.2.0", "react-dom": "^18.2.0" } }, "node_modules/@mantine/core": { - "version": "7.10.2", - "resolved": "https://registry.npmjs.org/@mantine/core/-/core-7.10.2.tgz", - "integrity": "sha512-sPqJY2A+zHAhi7/mJKL2EH92jKc6JDACJY17gXS+FcbIQgiaY1rxA/tdcybpq8FbswSgUYZO6CRL6XWEhatw5w==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@mantine/core/-/core-7.11.0.tgz", + "integrity": "sha512-yw2Llww9mw8rDWZtucdEuvkqqjHdreUibos7JCUpejL721FW1Tn9L91nsxO/YQFSS7jn4Q0CP+1YbQ/PMULmwA==", "dependencies": { "@floating-ui/react": "^0.26.9", "clsx": "^2.1.1", @@ -3611,59 +3611,59 @@ "type-fest": "^4.12.0" }, "peerDependencies": { - "@mantine/hooks": "7.10.2", + "@mantine/hooks": "7.11.0", "react": "^18.2.0", "react-dom": "^18.2.0" } }, "node_modules/@mantine/hooks": { - "version": "7.10.2", - "resolved": "https://registry.npmjs.org/@mantine/hooks/-/hooks-7.10.2.tgz", - "integrity": "sha512-3m4flbR2yv3Bl21pHl5BKOOnqrInp/gVD72rozLeu/jzIZqQy8yFRTY2bUWCebPwNem//OD1rCORsBXNXvq31g==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@mantine/hooks/-/hooks-7.11.0.tgz", + "integrity": "sha512-T3472GhUXFhuhXUHlxjHv0wfb73lFyNuaw631c7Ddtgvewq0WKtNqYd7j/Zz/k02DuS3r0QXA7e12/XgqHBZjg==", "peerDependencies": { "react": "^18.2.0" } }, "node_modules/@mantine/modals": { - "version": "7.10.2", - "resolved": "https://registry.npmjs.org/@mantine/modals/-/modals-7.10.2.tgz", - "integrity": "sha512-L/gjPnvokciHOuTXFZqkc5b+ECAGKe/0l0LXlDwM3PvGJs1/Wa4DBCSy3pdGhKv+rMwFr2HiBc8nibCfwaR7IQ==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@mantine/modals/-/modals-7.11.0.tgz", + "integrity": "sha512-I4bxdXirLNvVbmVcS9lhU9z1bknE8XlteGeSxAZ00SLUk9EowG+AX/9nK0TrSG2GBNDX82fFxp2z98/o7bTw5w==", "peerDependencies": { - "@mantine/core": "7.10.2", - "@mantine/hooks": "7.10.2", + "@mantine/core": "7.11.0", + "@mantine/hooks": "7.11.0", "react": "^18.2.0", "react-dom": "^18.2.0" } }, "node_modules/@mantine/nprogress": { - "version": "7.10.2", - "resolved": "https://registry.npmjs.org/@mantine/nprogress/-/nprogress-7.10.2.tgz", - "integrity": "sha512-hGOzGcESe2UjkMG7lYi7A4jF/w2SJstaCwwFazO51t6i/WbTUJrCiJ5YTbN8xrlLJWYVtkIO6PUc2ZMAHjx5KA==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@mantine/nprogress/-/nprogress-7.11.0.tgz", + "integrity": "sha512-xBUAT/oy179Km0Hl446usmuHNZcloZE96G++NRypCzz6Wzc0boc/p98SWcljPED/S2eeXtc6aXUOXyFKwp8lBg==", "dependencies": { - "@mantine/store": "7.10.2" + "@mantine/store": "7.11.0" }, "peerDependencies": { - "@mantine/core": "7.10.2", - "@mantine/hooks": "7.10.2", + "@mantine/core": "7.11.0", + "@mantine/hooks": "7.11.0", "react": "^18.2.0", "react-dom": "^18.2.0" } }, "node_modules/@mantine/store": { - "version": "7.10.2", - "resolved": "https://registry.npmjs.org/@mantine/store/-/store-7.10.2.tgz", - "integrity": "sha512-izT4ivE2Ka2NBTjy5Ck31F3sSybCBLXJhX/ESDCasVR9MKD2Ci2Y6nbm0UtBdPf4+PrDPZtaPwqQzL92uZLtCQ==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@mantine/store/-/store-7.11.0.tgz", + "integrity": "sha512-zPmOpdFgvkUqYKSK7NNKbhgXsh2QPw51m3iypTaj0mw+rZbk3WSH9vZvaEx59X0QG+ahwUg2/HezbjfXFUbvrA==", "peerDependencies": { "react": "^18.2.0" } }, "node_modules/@mantine/tiptap": { - "version": "7.10.2", - "resolved": "https://registry.npmjs.org/@mantine/tiptap/-/tiptap-7.10.2.tgz", - "integrity": "sha512-FvCzQ4+I7bB1qL3lsrFUB31irgihlWw+nsYUHqN66WeNUcSDVDiitaMJu4Kw56VrQ19l9vPp1qFQSgvz/aTTmw==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@mantine/tiptap/-/tiptap-7.11.0.tgz", + "integrity": "sha512-6AXSteD22B4gqscEKLejJ8v1QQsl7Q/2XLYSHwrT8T4l9JVeL881SG5wl23TOKp2K23BqULZbDmm4hhEKmnCZA==", "peerDependencies": { - "@mantine/core": "7.10.2", - "@mantine/hooks": "7.10.2", + "@mantine/core": "7.11.0", + "@mantine/hooks": "7.11.0", "@tiptap/extension-link": ">=2.1.12", "@tiptap/react": ">=2.1.12", "react": "^18.2.0", diff --git a/package.json b/package.json index 53727498..15c4714d 100644 --- a/package.json +++ b/package.json @@ -30,12 +30,12 @@ "@fullcalendar/interaction": "^6.1.14", "@fullcalendar/react": "^6.1.14", "@fullcalendar/timegrid": "^6.1.14", - "@mantine/carousel": "^7.10.2", - "@mantine/core": "^7.10.2", - "@mantine/hooks": "^7.10.2", - "@mantine/modals": "^7.10.2", - "@mantine/nprogress": "^7.10.2", - "@mantine/tiptap": "^7.10.2", + "@mantine/carousel": "^7.11.0", + "@mantine/core": "^7.11.0", + "@mantine/hooks": "^7.11.0", + "@mantine/modals": "^7.11.0", + "@mantine/nprogress": "^7.11.0", + "@mantine/tiptap": "^7.11.0", "@remix-run/react": "^2.9.2", "@remix-run/server-runtime": "^2.9.2", "@shopify/cli": "^3.61.2",