diff --git a/package.json b/package.json index b7b7e65..22c3dd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/poap-family", - "version": "1.12.11", + "version": "1.12.12", "author": { "name": "POAP", "url": "https://poap.xyz" diff --git a/src/loaders/api.js b/src/loaders/api.js index 5bd7c39..e94e608 100644 --- a/src/loaders/api.js +++ b/src/loaders/api.js @@ -256,11 +256,11 @@ async function getEventsOwners(eventIds, abortSignal, expiryDates) { if (!FAMILY_API_KEY) { return null } - const queryString = expiryDates ? encodeExpiryDates(expiryDates) : '' + const encodedExpiryDates = expiryDates ? encodeExpiryDates(expiryDates) : '' const response = await fetch( `${FAMILY_API_URL}/events` + `/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}` + - `/owners${queryString ? `?${queryString}` : ''}`, + `/owners${encodedExpiryDates ? `?${encodedExpiryDates}` : ''}`, { signal: abortSignal instanceof AbortSignal ? abortSignal : null, headers: { @@ -317,12 +317,15 @@ async function getEventMetrics(eventId, abortSignal, refresh = false) { return EventMetrics(body) } -async function getEventsMetrics(eventIds, abortSignal) { +async function getEventsMetrics(eventIds, abortSignal, expiryDates) { if (!FAMILY_API_KEY) { throw new Error(`Events (${eventIds.length}) metrics could not be fetched, configure Family API key`) } + const encodedExpiryDates = expiryDates ? encodeExpiryDates(expiryDates) : '' const response = await fetch( - `${FAMILY_API_URL}/events/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}/metrics`, + `${FAMILY_API_URL}/events` + + `/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}` + + `/metrics${encodedExpiryDates ? `?${encodedExpiryDates}` : ''}`, { signal: abortSignal instanceof AbortSignal ? abortSignal : null, headers: { diff --git a/src/models/event.js b/src/models/event.js index 9f07713..558ca3c 100644 --- a/src/models/event.js +++ b/src/models/event.js @@ -1,3 +1,5 @@ +import { parseEndOfDayDate } from '../utils/date' + function Event(event, includeDescription) { return { id: event.id, @@ -88,7 +90,7 @@ function parseExpiryDates(events) { ([eventId, event]) => ([ eventId, event?.expiry_date - ? new Date(event.expiry_date.replace(/-/g, '/') + ' 23:59:00 UTC') + ? parseEndOfDayDate(event.expiry_date) : undefined, ]) ) diff --git a/src/pages/Events.js b/src/pages/Events.js index 6f0a096..c404537 100644 --- a/src/pages/Events.js +++ b/src/pages/Events.js @@ -344,7 +344,7 @@ function Events() { const expiryDates = parseExpiryDates(events) Promise.all([ getEventsOwners(eventIds, controller.signal, expiryDates), - getEventsMetrics(eventIds, controller.signal), + getEventsMetrics(eventIds, controller.signal, expiryDates), ]).then( ([eventsOwners, eventsMetrics]) => { if (eventsMetrics) { diff --git a/src/utils/date.js b/src/utils/date.js index 1ebc659..17b1e3a 100644 --- a/src/utils/date.js +++ b/src/utils/date.js @@ -24,3 +24,7 @@ export function secondsInTheFuture(secs) { export function formatMonthYear(d) { return dayjs(d).format('MMM \'YY') } + +export function parseEndOfDayDate(date) { + return dayjs(date).endOf('day').toDate() +}