From 4b64c3a0c809f93669b30269e7ba40308abd2efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20P=C3=B6hland?= Date: Wed, 21 Aug 2024 13:51:29 +0200 Subject: [PATCH] update --- src/email/event-email.tsx | 9 +++++++-- src/email/types.ts | 5 +++-- src/index.ts | 1 + src/utils.ts | 11 +++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/utils.ts diff --git a/src/email/event-email.tsx b/src/email/event-email.tsx index 1d404c4..6609968 100644 --- a/src/email/event-email.tsx +++ b/src/email/event-email.tsx @@ -12,6 +12,7 @@ import { } from '@react-email/components' import { createTranslator } from 'use-intl' +import { getOnlineLocation } from '../utils' import type { IEvent } from './types' import type { IHost, Translations, WithUnsubscribeToken } from './utils' import { @@ -73,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.lng}` + const mapsLink = `https://maps.google.com/?q=${event.location.lat},${event.location.long}` return ( - {event.location.value} + + {event.location.onlineLink + ? getOnlineLocation(event.location.onlineLink) + : event.location.address} + diff --git a/src/email/types.ts b/src/email/types.ts index 00f3b13..cbb200e 100644 --- a/src/email/types.ts +++ b/src/email/types.ts @@ -94,8 +94,9 @@ export interface IEvent { time: string location: { lat: number - lng: number - value: string + long: number + address: string + onlineLink?: string } ticketId: string eventId: string diff --git a/src/index.ts b/src/index.ts index dbb9872..5d53f29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,3 +5,4 @@ export * from './users' export * from './staking' export * from './utils/api' export * from './common' +export * from './utils' diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..e41d96c --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,11 @@ +export function getDomain(hostname: string) { + const host = hostname.split('.') + host.reverse() + return `${host[1]}.${host[0]}` +} + +export function getOnlineLocation(onlineLink: string) { + const subHost = new URL(onlineLink).hostname + const host = getDomain(subHost) + return { 'google.com': 'Google Meet', 'zoom.us': 'Zoom' }[host] ?? 'Online' +}