From 7cc1be3b93d7254b94019599650d407c6953bf64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20P=C3=B6hland?= Date: Mon, 26 Aug 2024 15:59:46 +0200 Subject: [PATCH] improve --- src/email/event-email.tsx | 12 +++++++----- src/email/types.ts | 9 ++------- src/types/event.ts | 1 + src/utils.ts | 6 ++++++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/email/event-email.tsx b/src/email/event-email.tsx index 1ae3fe9..53f51a0 100644 --- a/src/email/event-email.tsx +++ b/src/email/event-email.tsx @@ -12,7 +12,7 @@ import { } from '@react-email/components' import { createTranslator } from 'use-intl' -import { getOnlineLocation } from '../utils' +import { getMapsLink, getOnlineLocation } from '../utils' import type { IEvent } from './types' import type { IHost, Translations, WithUnsubscribeToken } from './utils' import { @@ -74,7 +74,7 @@ const EventEmail = ({ const href = `${HOST}/event/${event.eventId}?guest=${event.ticketId}` - const mapsLink = `https://maps.google.com/?q=${event.location.lat},${event.location.long}` + const mapsLink = getMapsLink(event.location) return ( - - {t('maps')} - + {event.location.address && event.location.placeId && ( + + {t('maps')} + + )}
diff --git a/src/email/types.ts b/src/email/types.ts index cbb200e..eb4e090 100644 --- a/src/email/types.ts +++ b/src/email/types.ts @@ -1,4 +1,4 @@ -import { NftActivityType } from '../types' +import { IEventDoc, NftActivityType } from '../types' export const offerTradeTypes = [ NftActivityType.OFFER_TRADE, @@ -92,12 +92,7 @@ export interface IEvent { backgroundImage: string ticketImage: string time: string - location: { - lat: number - long: number - address: string - onlineLink?: string - } + location: IEventDoc['location'] ticketId: string eventId: string } diff --git a/src/types/event.ts b/src/types/event.ts index 7d6e501..1e271f6 100644 --- a/src/types/event.ts +++ b/src/types/event.ts @@ -12,6 +12,7 @@ export interface IEventDoc { startTime: number endTime: number location: { + placeId?: string address?: string lat?: number long?: number diff --git a/src/utils.ts b/src/utils.ts index e41d96c..197b6fa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,5 @@ +import { IEventDoc } from './types' + export function getDomain(hostname: string) { const host = hostname.split('.') host.reverse() @@ -9,3 +11,7 @@ export function getOnlineLocation(onlineLink: string) { const host = getDomain(subHost) return { 'google.com': 'Google Meet', 'zoom.us': 'Zoom' }[host] ?? 'Online' } + +export function getMapsLink(location: IEventDoc['location']) { + return `https://maps.google.com/?query=${location.address}&query_place_id=${location.placeId}` +}