Skip to content

feat: misc quality of life improvements #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/pages/dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function Dashboard() {
const [loading, setLoading] = useState(false);
const [showOnboarding, setShowOnboarding] = useState(false);
const [showUpgradeModal, setShowUpgradeModal] = useState(false);

const [role, setRole] = useState(false);
const exampleObjectives = [
{
completed: false,
Expand Down Expand Up @@ -114,9 +114,21 @@ export default function Dashboard() {
}
};

const fetchAccountDetails = async() => {
request(`${process.env.NEXT_PUBLIC_API_URL}/account`, 'GET', null)
.then((data) => {

setRole(data.role);
})
.catch((err) => {
console.log(err);
});
}


fetchRecommendedChallenges();
fetchPopularChallenges();
fetchAccountDetails();
request(`${process.env.NEXT_PUBLIC_API_URL}/activityFeed/`, 'GET', null).then(response => {
console.log(response)
setActivities(response.activityFeed);
Expand Down Expand Up @@ -274,10 +286,13 @@ export default function Dashboard() {


</ul>
</div>
</div>


<div className='w-full pb-4 pl-4 pr-4 relative'>
<h1 className='text-2xl text-neutral-100 tracking-wide font-semibold mb-4'>
{ role == "USER" &&
<div className='mb-10'>
<h1 className='text-2xl text-neutral-100 tracking-wide font-semibold mb-4'>
Sponsor Messaging
</h1>
<div
Expand All @@ -300,8 +315,9 @@ export default function Dashboard() {


</div>

<h1 className='text-2xl text-neutral-100 tracking-wide font-semibold mt-10 mb-4'>
</div>
}
<h1 className='text-2xl text-neutral-100 tracking-wide font-semibold mb-4'>
Connect with CTFGuide
</h1>
<div class='break-inside relative overflow-hidden flex flex-col justify-between text-sm rounded-xl max-w-[23rem] px-6 py-4 mb-4 bg-indigo-800 text-white'>
Expand Down
57 changes: 28 additions & 29 deletions src/pages/forgot-password.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { useState, useEffect } from 'react';
import { useRouter } from 'next/router'; // Import useRouter

import AuthFooter from '@/components/auth/AuthFooter'
export default function Forgot() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
Expand Down Expand Up @@ -131,26 +131,12 @@ export default function Forgot() {
style={{ fontFamily: 'Poppins, sans-serif' }}
className="flex min-h-full flex-col justify-center py-12 sm:px-6 lg:px-8"
>
<div className="sm:mx-auto sm:w-full sm:max-w-md">
<Link href="../">
<img
className="mx-auto h-20 w-auto"
src="../darkLogo.png"
alt="CTFGuide"
/>
</Link>
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-white">
Forgot your password?
</h2>
<p className="mt-2 text-center text-sm text-gray-200">
No worries - we'll get you back to your account in no time.
</p>
</div>


<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
<div
style={{ backgroundColor: '#212121' }}
className=" pb-8 pt-1 px-4 shadow sm:rounded-lg sm:px-10"
className=" pb-8 pt-1 px-4 shadow border-t-4 border-blue-600 sm:px-10"
>
<div className="space-y-6">
<div
Expand All @@ -173,8 +159,10 @@ export default function Forgot() {

{
validToken ?
<>
<div>
<h1 className='text-white text-xl'>Update your credentials </h1>

<div className='mt-3'>
<label
htmlFor="password"
className="block text-sm font-medium text-gray-200"
Expand All @@ -187,14 +175,14 @@ export default function Forgot() {
type="password"
onChange={(e) => setPassword(e.target.value)}
required
className="block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 text-white placeholder-gray-400 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-blue-500 sm:text-sm"
className="block w-full appearance-none border border-gray-300 px-3 py-2 text-white placeholder-gray-400 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-blue-500 sm:text-sm"
/>
</div>
</div>
<div>
<label
htmlFor="password"
className="block text-sm font-medium text-gray-200"
className="mt-4 block text-sm font-medium text-gray-200"
>
Confirm Password
</label>
Expand All @@ -204,18 +192,23 @@ export default function Forgot() {
type="password"
onChange={(e) => setConfirmPassword(e.target.value)}
required
className="block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 text-white placeholder-gray-400 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-blue-500 sm:text-sm"
className="block w-full appearance-none border border-gray-300 px-3 py-2 text-white placeholder-gray-400 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-blue-500 sm:text-sm"
/>
</div>
</div>

</>
</div>

:
<div>
<div className=''>

<h1 className='text-white text-xl'>Account Recovery </h1>
<p className='text-white tracking-tight text-xs'>No worries - we'll get you back to your account in no time.</p>
</div>
<label
htmlFor="email"
className="block text-sm font-medium text-gray-200"
className="mt-4 block text-sm font-medium text-gray-200"
>
Email
</label>
Expand All @@ -228,7 +221,7 @@ export default function Forgot() {
onChange={(e) => setEmail(e.target.value)}
autoComplete="email"
required
className="block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 text-white placeholder-gray-400 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-blue-500 sm:text-sm"
className="block w-full appearance-none border border-gray-300 px-3 py-2 text-white placeholder-gray-400 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-blue-500 sm:text-sm"
/>
</div>
</div>
Expand All @@ -240,7 +233,7 @@ export default function Forgot() {
<button
onClick={reset}
type="submit"
className="flex w-full justify-center rounded-md border border-transparent bg-blue-600 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
className="flex w-full justify-center border border-transparent bg-blue-700 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
>
Reset Password
</button>
Expand All @@ -250,22 +243,28 @@ export default function Forgot() {
<button
onClick={resetPassword}
type="submit"
className="flex w-full justify-center rounded-md border border-transparent bg-blue-600 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
className="flex w-full justify-center border border-transparent bg-blue-700 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
>
Send Password Reset Email
</button>
</div>
}

<div className='text-center mx-auto'>
<a href="./login" className='text-center text-sm mx-auto text-white mt-10 hover:text-gray-300'>← Return to login?</a>
<div className=''>
<a href="./login" className='text-center text-sm mx-auto text-blue-500 mt-10 hover:text-blue-400'>Return to login?</a>

</div> </div>


</div>
<AuthFooter/>

</div>




</div>


<ToastContainer
position="bottom-right"
Expand Down
34 changes: 34 additions & 0 deletions src/pages/users/[user].jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import Head from 'next/head';
import { useState, useEffect, useRef } from 'react';
import { Context } from '@/context';
Expand Down Expand Up @@ -153,6 +154,8 @@ export default function Create() {
const [followerPage, setFollowerPage] = useState(0); // Initial page
const [totalFollowerPages, setTotalFollowerPages] = useState(0); // Total pages

const [points, setPoints] = useState("0");

const [following, setFollowing] = useState(0);
const [followingPage, setFollowingPage] = useState(0); // Initial page
const [totalFollowingPages, setTotalFollowingPages] = useState(0); // Total pages
Expand Down Expand Up @@ -683,6 +686,30 @@ export default function Create() {
}
}, [user, followingPage]);


useEffect(() => {
const fetchUserPoints = async () => {
try {
const endPoint = `${process.env.NEXT_PUBLIC_API_URL}/users/${user.username}/points`;
console.log('Fetching user points:', endPoint);

const response = await request(endPoint, 'GET');
if (response && response.totalPoints) {
setPoints(response.totalPoints);
console.log('User points:', response.totalPoints);
}
throw new Error('Failed to fetch user points');
} catch (error) {
console.error('Failed to fetch user points:', error);
}
};

if (user && user.username) {
fetchUserPoints();
}
}, [user]);


const userData = { user, ownUser: true };

// Follower
Expand Down Expand Up @@ -967,6 +994,13 @@ export default function Create() {
)}
</h1>
<p className="text-white">

{user && points && (
<span className="mr-2 font-bold rounded-sm bg-gradient-to-br from-green-400 to-blue-600 px-2 py-1 text-sm text-white">
<i className=""></i> Points: {points}
</span>
)}

<i className="fas fa-map-marker-alt mt-2"></i>{' '}
{(user && user.location) || (
<Skeleton
Expand Down