Skip to content

Commit

Permalink
2785 update events apis (#653)
Browse files Browse the repository at this point in the history
* 🛠️ Updated People to use new events API

* Updated evetHelper to send presenter request in kebab casing

* Updated getPresenterEvents to use the new API

* Removed console log

* 🔒 Updated readme to include instructions about populating environment files using Keeper record

* 🔒 Added new website API secret to .env.template

* Removed unused date filter prop

* - 🎨 broke hyphenate method for presenter names off into a separate helper function
- ✅ Updated event APIs to use new WEBSITE_API GitHub secret

* Updated home page to use correct endpoint for fetching all upcoming events

* Fixed upcoming speaker filter not rendering due to missing environment variable

* removed PAST_EVENTS_API environment variable

---------

Co-authored-by: Calinator444 <caleb.williams5247@gmail.com>
  • Loading branch information
Calinator444 and Calinator444 authored Jul 24, 2024
1 parent 920b02a commit 4eee52f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GOOGLE_ANALYTICS=#{GOOGLE_ANALYTICS}
YOUTUBE_API_KEY=#{YOUTUBE_API_KEY}
VERSION_DEPLOYED=#{VERSION_DEPLOYED}
CHINA_BUILD=FALSE
EVENTS_API=#{EVENTS_API}
WEBSITE_API=#{WEBSITE_API}
CRM_APP_ID=#{CRM_APP_ID}
CRM_TENANT=#{CRM_TENANT}
CRM_TENANT_ID=#{CRM_TENANT_ID}
Expand Down
20 changes: 2 additions & 18 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,8 @@ This is a Gatsby generated site pulling data from:

- Clone the repo from <https://github.com/SSWConsulting/SSW.People>
- Run *yarn* (or *npm install*) to install packages
- Create environment files (.env.development and .env.production) and fill out the values for the following keys:

``` env
GOOGLE_ANALYTICS=
DATA_API_TENANT=
YOUTUBE_API_KEY=
VERSION_DEPLOYED=#{VERSION_DEPLOYED}
CHINA_BUILD=FALSE
EVENTS_API=https://www.ssw.com.au/ssw/SharePointEventsService.aspx
CRM_APP_ID=
CRM_TENANT=
CRM_TENANT_ID=
CRM_APP_SECRET=
CRM_SCOPE=
CRM_VIEW_CURRENT=
CRM_VIEW_PAST=
APPLICATIONINSIGHTS_CONNECTION_STRING=#{APPLICATIONINSIGHTS_CONNECTION_STRING}
```
- Create environment files (.env.development and .env.production) and copy the environment variables for SSW People on Keeper into both files
- **Note**: You will need to update .env.template as well as the keeper record if you add any new environment variables

### Development

Expand Down
5 changes: 2 additions & 3 deletions src/components/people-filters/people-filters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import React, { useEffect, useState } from 'react';
import Filter from '../filter/filter';

const PeopleFilters = ({
Expand All @@ -14,7 +14,6 @@ const PeopleFilters = ({
const [selectedSkills, setSelectedSkills] = useState([]);
const [selectedRoles, setSelectedRoles] = useState([]);
const [selectedEvents, setSelectedEvents] = useState([]);

useEffect(() => {
onFilterChange([
{ name: 'roles', selected: selectedRoles },
Expand All @@ -35,7 +34,7 @@ const PeopleFilters = ({
filterCounts={rolesCount}
/>
</div>
{!!allEvents.length && process.env.EVENTS_API?.length > 4 && (
{!!allEvents.length && (
<div className="w-full sm:w-1/2 lg:w-full mt-0 lg:mt-4">
<Filter
filterTitle="Upcoming speakers"
Expand Down
81 changes: 33 additions & 48 deletions src/helpers/eventHelper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import moment from 'moment';
import { hyphenate } from './hyphenate';
const EventsApi = process.env.WEBSITE_API;

const EventsApi = process.env.EVENTS_API;
async function getEventsPresenters() {
let dateFilter = new Date().toISOString();
let oDataFilterOngoing = `$filter=Enabled ne false and EndDateTime ge datetime'${dateFilter}'%26$select=StartDateTime,Presenter,CalendarType%26$orderby=StartDateTime asc%26$top=50`;
let presentersEvents;
await fetch(`${EventsApi}?odataFilter=${oDataFilterOngoing}`)
await fetch(`${EventsApi}events/upcoming?top=${50}`)
.then((response) => response.json())
.then((result) => {
presentersEvents = result.map((element) => {
Expand All @@ -14,38 +13,32 @@ async function getEventsPresenters() {
presenter: element.Presenter,
};
});

presentersEvents = presentersEvents.sort(
(a, b) => a.eventtype - b.eventtype
);
});

return presentersEvents;
}

async function getEventsForPresenter(name, nickname) {
const dateFilter = new Date().toISOString();
const oDataFilterOngoing = `$filter=(substringof('${name}',Presenter) or substringof('${nickname}',Presenter)) and Enabled ne false and EndDateTime ge datetime'${dateFilter}'%26$select=StartDateTime,EndDateTime,Category,CalendarType,Title,Url,Thumbnail,Presenter,EventShortDescription%26$orderby=StartDateTime asc%26$top=50`;
return await fetchFromSharepoint(oDataFilterOngoing, 'asc');
async function getEventsForPresenter(name) {
name = hyphenate(name);
const url = `${EventsApi}events/upcoming?presenterName=${name}`;
return await fetchEvents(url, 'asc');
}

async function getPastEventsForPresenter(name, nickname) {
const dateFilter = new Date().toISOString();
const oDataFilterOngoing = `$filter=(substringof('${name}',Presenter) or substringof('${nickname}',Presenter)) and Enabled ne false and EndDateTime lt datetime'${dateFilter}'%26$select=StartDateTime,EndDateTime,Category,CalendarType,Title,Url,Thumbnail,Presenter,EventShortDescription%26$orderby=StartDateTime desc%26$top=50`;
return await fetchFromSharepoint(oDataFilterOngoing, 'desc');
async function getPastEventsForPresenter(name) {
name = hyphenate(name);
const url = `${EventsApi}events/past?presenterName=${name}`;
return await fetchEvents(url, 'desc');
}

async function fetchFromSharepoint(oDataFilterOngoing, sort) {
async function fetchEvents(url, sort) {
var events;
await fetch(`${EventsApi}?odataFilter=${encodeURI(oDataFilterOngoing)}`)
.then((response) => response.text())
await fetch(url)
.then((response) => response.json())
.then((result) => {
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(result, 'application/xml');
var eventsXml = xmlDoc.getElementsByTagName('properties');
events = Array.prototype.map.call(eventsXml, (element) =>
mapXmlToEventObj(element)
);
events = Array.prototype.map.call(result, (element) => mapEvent(element));

if (sort === 'asc') {
events = events.sort((a, b) =>
moment(a.startdatetime, 'DD MMM YYYY').diff(
Expand All @@ -60,42 +53,34 @@ async function fetchFromSharepoint(oDataFilterOngoing, sort) {
);
}
})
.catch(() => (events = []));
.catch((error) => {
events = [];
});
return events;
}

function mapXmlToEventObj(properties) {
function mapEvent(properties) {
const today = moment().local().format('DD MMM YYYY');
const endDateTimeXml =
properties.getElementsByTagName('EndDateTime')[0].textContent;
const startdatetimeXml =
properties.getElementsByTagName('StartDateTime')[0].textContent;
const endDateTimeXml = properties.EndDateTime;
const startdatetimeXml = properties.StartDateTime;
const startdatetime = moment(startdatetimeXml).local().format('DD MMM YYYY');
const endDateTime = moment(endDateTimeXml).local().format('DD MMM YYYY');

return {
url: properties
.getElementsByTagName('Url')[0]
.getElementsByTagName('Url')[0]
.textContent.replace('http:', 'https:'),
image: properties
.getElementsByTagName('Thumbnail')[0]
.getElementsByTagName('Url')[0]
.textContent.replace('http:', 'https:'),
title: properties
.getElementsByTagName('Url')[0]
.getElementsByTagName('Description')[0].textContent,
url: properties.Url.Url.replace('http:', 'https:'),

image: properties.Thumbnail.Url.replace('http:', 'https:'),
title: properties.Url.Description,
startdatetime: startdatetime,
endDateTime: endDateTime,
isSameDay: startdatetime === endDateTime,
daysToGo: moment(startdatetime).diff(moment(today), 'days'),
technologycategory:
properties.getElementsByTagName('Category')[0].textContent,
eventtype: properties.getElementsByTagName('CalendarType')[0].textContent,
presenter: properties.getElementsByTagName('Presenter')[0].textContent,
technologycategory: properties.Category,
eventtype: properties.CalendarType,
presenter: properties.Presenter,

presenterprofileurl: null,
description: properties.getElementsByTagName('EventShortDescription')[0]
.textContent,
description: properties.EventShortDescription,
};
}

Expand Down Expand Up @@ -133,10 +118,10 @@ const isPresenterOfEventType = (eventType, profile, events) => {
};

export {
getEventsPresenters,
getEventsForPresenter,
getEventsPresenters,
getPastEventsForPresenter,
isInPresenters,
getPresentersOfEventType,
isInPresenters,
isPresenterOfEventType,
};
3 changes: 3 additions & 0 deletions src/helpers/hyphenate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const hyphenate = (name) => {
return name.toLowerCase().replace(' ', '-');
};

0 comments on commit 4eee52f

Please sign in to comment.