-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from ClickPop/release/1.0.0-alpha.8
Version 1.0.0-alpha.8
- Loading branch information
Showing
9 changed files
with
386 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ yarn-debug.log* | |
yarn-error.log* | ||
|
||
.eslintcache | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from 'react'; | ||
import ReactMapGL, { Marker } from 'react-map-gl'; | ||
const apiKey = process.env.REACT_APP_MAPBOX_KEY; | ||
|
||
export const ResponseMap = ({ responses }) => { | ||
const [latitude, longitude] = responses.filter((r) => r.geo)[0]?.geo?.ll; | ||
const [viewport, setViewport] = useState({ | ||
width: '100%', | ||
height: 200, | ||
latitude, | ||
longitude, | ||
zoom: 1, | ||
}); | ||
|
||
return ( | ||
<div className="mb-4 rounded-3 overflow-hidden"> | ||
<ReactMapGL | ||
mapboxApiAccessToken={apiKey} | ||
{...viewport} | ||
mapStyle="mapbox://styles/mapbox/streets-v8" | ||
onViewportChange={(nextViewport) => setViewport(nextViewport)} | ||
> | ||
{responses | ||
.filter((r) => r.geo && r.geo.ll) | ||
.map((response) => ( | ||
<Marker | ||
key={response.id} | ||
latitude={response.geo.ll[0]} | ||
longitude={response.geo.ll[1]} | ||
offsetLeft={viewport.zoom - 10} | ||
offsetTop={viewport.zoom - 10} | ||
> | ||
<span role="img" aria-label="reponse map pin"> | ||
📍 | ||
</span> | ||
</Marker> | ||
))} | ||
</ReactMapGL> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import * as axios from 'axios'; | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import Moment from 'react-moment'; | ||
import { Card } from '../components/Card'; | ||
import { context } from '../context/Context'; | ||
|
||
export const Admin = () => { | ||
const [view, setView] = useState(null); | ||
const [users, setUsers] = useState([]); | ||
const [surveys, setSurveys] = useState([]); | ||
const [userCount, setUserCount] = useState(0); | ||
const [surveyCount, setSurveyCount] = useState(0); | ||
const [responseCount, setResponseCount] = useState(0); | ||
const { state } = useContext(context); | ||
useEffect(() => { | ||
const fetchData = async () => { | ||
const totalUsers = await axios.get('/api/v1/admin/users', { | ||
headers: { Authorization: `Bearer ${state.token}` }, | ||
}); | ||
|
||
const totalSurveys = await axios.get('/api/v1/admin/surveys', { | ||
headers: { Authorization: `Bearer ${state.token}` }, | ||
}); | ||
|
||
setUserCount(totalUsers.data.results.length); | ||
setSurveyCount(totalSurveys.data.results.length); | ||
setResponseCount( | ||
totalSurveys.data.results.reduce( | ||
(sum, survey) => survey.Responses.length + sum, | ||
0, | ||
), | ||
); | ||
setUsers(totalUsers.data.results); | ||
setSurveys(totalSurveys.data.results); | ||
}; | ||
|
||
fetchData(); | ||
}, [state.token]); | ||
|
||
return ( | ||
<div className="container"> | ||
<div className="row"> | ||
<div className="col-12 order-sm-2 col-sm-6 col-lg-4"> | ||
<h2 className="h3 mb-3">Show me</h2> | ||
{users.length > 0 && ( | ||
<div> | ||
<p | ||
className="card-text" | ||
onClick={() => setView('users')} | ||
style={{ cursor: 'pointer' }} | ||
> | ||
Users: {userCount} | ||
</p> | ||
<p | ||
className="card-text" | ||
onClick={() => setView('surveys')} | ||
style={{ cursor: 'pointer' }} | ||
> | ||
Surveys: {surveyCount} | ||
</p> | ||
<p className="card-text">Responses: {responseCount}</p> | ||
</div> | ||
)} | ||
</div> | ||
<div className="col-12 order-sm-1 col-sm-6 col-lg-8 pr-sm-4"> | ||
<h1 className="mb-4">Results</h1> | ||
{view === 'users' && | ||
users && | ||
users.map((user) => ( | ||
<Card key={user.id} title={user.name} className="mb-2"> | ||
<p className="card-text">Email: {user.email}</p> | ||
<p className="text-muted"> | ||
<strong> | ||
Sign-up Date:{' '} | ||
<Moment format="MMM D, YYYY">{user.createdAt}</Moment>{' '} | ||
<Moment format="h:mm a">{user.createdAt}</Moment> | ||
</strong> | ||
</p> | ||
</Card> | ||
))} | ||
{view === 'surveys' && | ||
surveys && | ||
surveys.map((survey) => ( | ||
<Card key={survey.id} title={survey.title} className="mb-2"> | ||
<p className="card-text"> | ||
Questions: {survey.Questions.length} | ||
</p> | ||
<p className="card-text"> | ||
Responses: {survey.Responses.length} | ||
</p> | ||
<p className="text-muted"> | ||
<strong> | ||
Created At:{' '} | ||
<Moment format="MMM D, YYYY">{survey.createdAt}</Moment>{' '} | ||
<Moment format="h:mm a">{survey.createdAt}</Moment> | ||
</strong> | ||
</p> | ||
</Card> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.