From 206236f5b9fae189932b588ae6beb4ef90de19a5 Mon Sep 17 00:00:00 2001 From: Spectralitree <72747870+Spectralitree@users.noreply.github.com> Date: Sun, 8 Aug 2021 12:17:18 +0200 Subject: [PATCH] add member-only public pages --- src/Components/Public/ProfilePage.js | 2 +- src/Pages/MemberProfile.js | 54 ++++++++++++++++++++++++++++ src/Pages/Public.js | 41 +++++++++++++++++---- 3 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/Pages/MemberProfile.js diff --git a/src/Components/Public/ProfilePage.js b/src/Components/Public/ProfilePage.js index ec1eb771..c8707bc1 100644 --- a/src/Components/Public/ProfilePage.js +++ b/src/Components/Public/ProfilePage.js @@ -157,7 +157,7 @@ export default function ProfilePage(props) { { !member.banner || !localStorage.getItem("bottombanners") ? "" : } - Back + { props.list ? Back : ""} diff --git a/src/Pages/MemberProfile.js b/src/Pages/MemberProfile.js new file mode 100644 index 00000000..41665226 --- /dev/null +++ b/src/Pages/MemberProfile.js @@ -0,0 +1,54 @@ +import React, { useCallback, useEffect, useState } from 'react'; +import { useParams } from 'react-router-dom'; +import * as BS from 'react-bootstrap'; + +import Loading from '../Components/Loading'; +import API_URL from '../Constants/constants'; +import ProfilePage from '../Components/Public/ProfilePage'; + +const MemberProfile = () => { + const { memberID } = useParams(); + + const [isLoading, setIsLoading ] = useState(false); + const [isError, setIsError ] = useState(false); + const [isForbidden, setIsForbidden ] = useState(false); + const [ member, setMember ] = useState({}); + + const fetchMember = useCallback( () => { + setIsLoading(true); + setIsError(false); + + fetch(`${API_URL}m/${memberID}`,{ + method: 'GET', + }).then ( res => { + if (res.status === 403) { + throw new Error('Access denied!'); + } + return res.json() + } + ).then (data => { + setMember(data) + setIsLoading(false); + }) + .catch (error => { + if (error.message === 'Access denied!') { + setIsForbidden(true); + } else { + console.log(error); + setIsError(true); + } + setIsLoading(false); + }) + }, [memberID]) + + useEffect(() => { + fetchMember(); + }, [fetchMember]) + + return ( + isLoading ? : isError ? + Error fetching member. : isForbidden ? This member is private. : + ); +} + +export default MemberProfile; \ No newline at end of file diff --git a/src/Pages/Public.js b/src/Pages/Public.js index 5b2fc60c..b2928977 100644 --- a/src/Pages/Public.js +++ b/src/Pages/Public.js @@ -5,31 +5,55 @@ import { useForm } from "react-hook-form"; import history from "../History.js"; import { Switch, Route, useRouteMatch } from 'react-router-dom'; import Profile from '../Components/Public/Profile.js' +import MemberProfile from '../Pages/MemberProfile.js' export default function Public () { const { path, url } = useRouteMatch(); - const { register, handleSubmit } = useForm(); + const { register: registerSys, handleSubmit: handleSys } = useForm(); - const submitID = (data) => { + const submitSysID = (data) => { history.push(`${url}/${data.sysID}`); } + const { register: registerMember, handleSubmit: handleMember } = useForm(); + + const submitMemberID = (data) => { + history.push(`${url}/m/${data.memberID}`); + } + return ( - + Profile - + - Submit a system ID to view to that system's profile. + Submit a system ID to view to that system's profile. - + + + + Submit + + + + + + + + + + Alternatively, submit a member ID to view that member. + + + + Submit @@ -39,9 +63,12 @@ export default function Public () { + + + - + ) } \ No newline at end of file