diff --git a/src/App.tsx b/src/App.tsx
index 18ac09d..94e2441 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -5,7 +5,7 @@ import { Routes, Route } from "react-router-dom";
import axios from "axios";
import { initializeApp } from "firebase/app";
import { setPersistence, getAuth, inMemoryPersistence } from "firebase/auth";
-import { useLogin, LoadingScreen, AuthProvider } from "@hex-labs/core";
+import { useLogin, LoadingScreen, AuthProvider, Header, Footer } from "@hex-labs/core";
import UserData from './components/UserData';
@@ -48,12 +48,12 @@ export const App = () => {
// useAuth hook to retrieve the user's login details.
return (
-
+
{/* Setting up our React Router to route to all the different pages we may have */}
} />
-
+
);
};
diff --git a/src/components/UserCard.tsx b/src/components/UserCard.tsx
index d552982..78445ce 100644
--- a/src/components/UserCard.tsx
+++ b/src/components/UserCard.tsx
@@ -3,13 +3,28 @@ import {
Flex,
HStack,
Text,
+ Modal,
+ ModalOverlay,
+ ModalContent,
+ ModalHeader,
+ ModalCloseButton,
+ ModalBody,
+ Link,
+ Button
} from "@chakra-ui/react";
-import React from "react";
+import React, { useState } from "react";
+import axios from "axios";
+import { apiUrl, Service } from "@hex-labs/core";
type Props = {
user: any;
};
+type ModalProps = {
+ isOpen: boolean;
+ onClose: () => void;
+ user: any;
+};
// TODO: right now, the UserCard only displays the user's name and email. Create a new modal component that
// pops up when the card is clicked. In this modal, list all the user's information including name, email, phoneNumber,
@@ -23,9 +38,50 @@ type Props = {
// the hexathons that the user has applied to. You can use the /applications endpoint of the registration service to do this
// and the /hexathons endpoint of the hexathons service to get a list of all the hexathons.
+const UserModal: React.FC = (props: ModalProps) => {
+ const [hexathons, setHexathons] = useState(null);
+ const getHexathons = async () => {
+ const res = await axios.get(apiUrl(Service.HEXATHONS, `/hexathons`));
+ const data = res.data;
+ const applications = await Promise.all(data.map(async (hexathon: any) => {
+ const app = await axios.get(apiUrl(Service.REGISTRATION, '/applications'), { params: {
+ hexathon: hexathon.id, userId: props.user.userId
+ }});
+ return { hexathon, application: app.data };
+ }));
+ setHexathons(applications.filter((item: any) => item !== null));
+ };
+ return (
+
+
+
+ {`${props.user.name.first} ${props.user.name.last}`}
+
+
+ Email: {props.user.email}
+ Phone: {props.user.phoneNumber}
+ User ID: {props.user.userId}
+
+ {hexathons && (
+
+ {hexathons.map((item: any) => (
+ {item.hexathon.name}
+ ))}
+
+ )}
+
+
+
+ )
+};
+
const UserCard: React.FC = (props: Props) => {
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const onClose = () => setIsModalOpen(false);
+
return (
+ <>
= (props: Props) => {
height="175px"
fontWeight="bold"
alignItems="center"
+ onClick={() => setIsModalOpen(true)}
+ cursor="pointer"
>
@@ -48,6 +106,8 @@ const UserCard: React.FC = (props: Props) => {
+
+ >
);
};
diff --git a/src/components/UserData.tsx b/src/components/UserData.tsx
index d5aeb78..245bba2 100644
--- a/src/components/UserData.tsx
+++ b/src/components/UserData.tsx
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { apiUrl, Service } from "@hex-labs/core";
-import { SimpleGrid, Text } from "@chakra-ui/react";
+import { SimpleGrid, Text, Button} from "@chakra-ui/react";
import axios from "axios";
import UserCard from "./UserCard";
@@ -38,10 +38,12 @@ const UserData: React.FC = () => {
// this is the endpoint you want to hit, but don't just hit it directly using axios, use the apiUrl() function to make the request
const URL = 'https://users.api.hexlabs.org/users/hexlabs';
-
+ const res = await axios.get(apiUrl(Service.USERS, '/users/hexlabs?limit=100'));
+ const users = res.data;
+ const filteredUsers = users.filter((user: any) => user.phoneNumber && user.phoneNumber.startsWith('470'));
// uncomment the line below to test if you have successfully made the API call and retrieved the data. The below line takes
// the raw request response and extracts the actual data that we need from it.
- // setUsers(data?.data?.profiles);
+ setUsers(filteredUsers);
};
document.title = "Hexlabs Users"
getUsers();
@@ -55,12 +57,17 @@ const UserData: React.FC = () => {
// TODO: Create a function that sorts the users array based on the first name of the users. Then, create a button that
// calls this function and sorts the users alphabetically by first name. You can use the built in sort() function to do this.
+ function sortUsers() {
+ const sortedUsers = [...users].sort((a, b) => a.name.first.localeCompare(b.name.first));
+ setUsers(sortedUsers);
+ }
+
return (
<>
Hexlabs UsersThis is an example of a page that makes an API call to the Hexlabs API to get a list of users.
-
+