diff --git a/src/App.tsx b/src/App.tsx
index 18ac09d..36036bd 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,14 @@ 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..b31d33d 100644
--- a/src/components/UserCard.tsx
+++ b/src/components/UserCard.tsx
@@ -1,15 +1,34 @@
import {
Box,
+ Button,
+ Code,
Flex,
HStack,
+ ListItem,
+ Modal,
+ ModalBody,
+ ModalCloseButton,
+ ModalContent,
+ ModalFooter,
+ ModalHeader,
+ ModalOverlay,
Text,
+ UnorderedList,
+ useDisclosure,
} from "@chakra-ui/react";
-import React from "react";
+import { apiUrl, Service } from "@hex-labs/core";
+import axios from "axios";
+import React, { useEffect, useState } from "react";
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 +42,64 @@ 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([]);
+
+ const getHexathons = async () => {
+ const res = await axios.get(apiUrl(Service.HEXATHONS, "/hexathons"));
+ const hexathons = res.data;
+ const userApps = await Promise.all(hexathons.map(async (hexathon: any) => {
+ const res = await axios.get(apiUrl(Service.REGISTRATION, "/applications"), {
+ params: {
+ hexathon: hexathon.id,
+ userId: props.user.userId
+ }
+ });
+ return res.data.length > 0 ? hexathon : null;
+ }));
+ setHexathons(userApps.filter((hexathon) => hexathon !== null));
+ }
+
+ useEffect(() => {
+ if (props.isOpen) {
+ getHexathons();
+ }
+ }, [props.isOpen]);
+
+ return (
+
+
+
+ User Details
+
+
+ Name: {`${props.user.name.first} ${props.user.name.last}`}
+ Email: {props.user.email}
+ Phone Number: {props.user.phoneNumber}
+ User ID:{props.user.userId}
+
+ Applied Hexathons:
+ { hexathons.length > 0?
+ (
+ {hexathons.map((hexathon) => (
+
+ {hexathon.name}
+
+ ))}
+ ) : No hexathons applied
+ }
+
+
+
+
+ );
+};
+
const UserCard: React.FC = (props: Props) => {
+ const { isOpen, onOpen, onClose } = useDisclosure();
return (
+ <>
= (props: Props) => {
height="175px"
fontWeight="bold"
alignItems="center"
+ onClick={onOpen}
>
@@ -48,6 +123,8 @@ const UserCard: React.FC = (props: Props) => {
+
+ >
);
};
diff --git a/src/components/UserData.tsx b/src/components/UserData.tsx
index d5aeb78..f1f723f 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";
@@ -39,9 +39,17 @@ 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"));
+ const data = res.data;
+ const filtered = data.filter((u: any) =>
+ String(u?.phoneNumber ?? "")
+ .replace(/\D/g, "")
+ .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(filtered);
};
document.title = "Hexlabs Users"
getUsers();
@@ -55,11 +63,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 sortByFirst() {
+ const sorted = [...users].sort((a, b) => a.name.first.localeCompare(b.name.first));
+ setUsers(sorted);
+ }
return (
<>
+
Hexlabs UsersThis is an example of a page that makes an API call to the Hexlabs API to get a list of users.
+