Skip to content

Commit

Permalink
fix: navbar and navigation for new layers
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Dec 10, 2024
1 parent 887e229 commit 83d5d2c
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 135 deletions.
12 changes: 12 additions & 0 deletions backend/src/database/open_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import (
log "github.com/sirupsen/logrus"
)

func (db *DB) GetOpenContent(all bool) ([]models.OpenContentProvider, error) {
tx := db.Model(&models.OpenContentProvider{})
if !all {
tx = tx.Where("currently_enabled = ?", true)
}
openContent := make([]models.OpenContentProvider, 0, 3)
if err := tx.Find(&openContent).Error; err != nil {
return nil, newNotFoundDBError(err, "open_content_providers")
}
return openContent, nil
}

func (db *DB) FindKolibriInstance() (*models.ProviderPlatform, error) {
kolibri := models.ProviderPlatform{}
if err := db.First(&kolibri, "type = ?", "kolibri").Error; err != nil {
Expand Down
15 changes: 15 additions & 0 deletions backend/src/handlers/open_content_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@ package handlers
import (
"UnlockEdv2/src/models"
"net/http"
"strings"
)

func (srv *Server) registerOpenContentRoutes() []routeDef {
axx := models.Feature(models.OpenContentAccess)
return []routeDef{
{"GET /api/open-content/favorites", srv.handleGetUserFavoriteOpenContent, false, axx},
{"GET /api/open-content", srv.handleIndexOpenContent, false, axx},
}
}

func (srv *Server) handleIndexOpenContent(w http.ResponseWriter, r *http.Request, log sLog) error {
only := r.URL.Query().Get("all")
var all bool
if userIsAdmin(r) && strings.ToLower(strings.TrimSpace(only)) == "true" {
all = true
}
content, err := srv.Db.GetOpenContent(all)
if err != nil {
return newDatabaseServiceError(err)
}
return writeJsonResponse(w, http.StatusOK, content)
}

func (srv *Server) handleGetUserFavoriteOpenContent(w http.ResponseWriter, r *http.Request, log sLog) error {
page, perPage := srv.getPaginationInfo(r)
total, favorites, err := srv.Db.GetUserFavorites(srv.getUserID(r), page, perPage)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/FeatureLevelCheckboxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function FeatureLevelCheckboxes({
toaster(resp.message, ToastState.success);
const user = await fetchUser();
setUser(user);
navigate('/admin-dashboard');
navigate('/authcallback');
};

return (
Expand Down
41 changes: 31 additions & 10 deletions frontend/src/Components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export default function Navbar({
const { toaster } = useToast();
const confirmSeedModal = useRef<HTMLDialogElement | null>(null);
const [seedInProgress, setSeedInProgress] = useState<boolean>(false);

const dashboardTitle = new Map([
['/admin-dashboard', 'Learning'],
['/knowledge-center-dashboard', 'Knowledge'],
['/operational-insights', 'Operational']
]);
const handleSeedDemoData = async () => {
setSeedInProgress(true);
const resp = await API.post<null, object>(`auth/demo-seed`, {});
Expand Down Expand Up @@ -107,15 +111,21 @@ export default function Navbar({
<li className="mt-16">
<Link to={getDashboardLink(user)}>
<ULIComponent icon={HomeIcon} />
Dashboard
</Link>
</li>
<li>
<Link to="/operational-insights">
<ULIComponent icon={CogIcon} />
Operational Insights
{dashboardTitle.get(
getDashboardLink(user)
) ?? 'Operational'}{' '}
Insights
</Link>
</li>
{/* this acts as the dashboard in the case there are no features enabled */}
{user.feature_access.length > 0 && (
<li>
<Link to="/operational-insights">
<ULIComponent icon={CogIcon} />
Operational Insights
</Link>
</li>
)}
{hasFeature(
user,
FeatureAccess.ProviderAccess
Expand Down Expand Up @@ -147,7 +157,7 @@ export default function Navbar({
<li>
<Link to="/programs">
<ULIComponent
icon={CloudIcon}
icon={DocumentTextIcon}
/>
Programs
</Link>
Expand All @@ -159,6 +169,17 @@ export default function Navbar({
FeatureAccess.OpenContentAccess
) && (
<>
{/* in the case where this is the only feature, this would otherwise be the dashboard */}
{user.feature_access.length > 1 && (
<li>
<Link to="/knowledge-center-dashboard">
<ULIComponent
icon={BookOpenIcon}
/>
Knowledge Insights
</Link>
</li>
)}
<li>
<Link to="/knowledge-center-management/libraries">
<ULIComponent
Expand Down Expand Up @@ -205,7 +226,7 @@ export default function Navbar({
FeatureAccess.ProviderAccess
) && (
<>
<li className="mt-16">
<li>
<Link to="/student-activity">
<ULIComponent icon={HomeIcon} />
My Learning
Expand Down
38 changes: 3 additions & 35 deletions frontend/src/Components/forms/EditUserForm.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { ServerResponseOne, User, UserRole } from '@/common.ts';
import { useState } from 'react';
import { SubmitHandler, useForm } from 'react-hook-form';
import {
TextInput,
DropdownInput,
SubmitButton,
CloseX
} from '@/Components/inputs';
import { TextInput, SubmitButton, CloseX } from '@/Components/inputs';
import API from '@/api/api';

interface Inputs {
[key: string]: string | UserRole;
name_first: string;
name_last: string;
username: string;
role: UserRole;
email: string;
}

Expand All @@ -36,7 +29,6 @@ export default function EditUserForm({
defaultValues: {
name_first: user.name_first,
name_last: user.name_last,
username: user.username,
role: user.role,
email: user.email
}
Expand Down Expand Up @@ -64,18 +56,10 @@ export default function EditUserForm({
)) as ServerResponseOne<User>;
if (!resp.success) {
switch (resp.message) {
case 'userexists': {
setError('username', {
type: 'custom',
message: 'Username already exists'
});
break;
}
case 'alphanum': {
setError('username', {
setError('name', {
type: 'custom',
message:
'Name + Username must contain letters and numbers only'
message: 'Name must contain letters and spaces only'
});
break;
}
Expand Down Expand Up @@ -112,14 +96,6 @@ export default function EditUserForm({
errors={errors}
register={register}
/>
<TextInput
label={'Username'}
interfaceRef={'username'}
required
length={50}
errors={errors}
register={register}
/>
<TextInput
label={'Email'}
interfaceRef={'email'}
Expand All @@ -128,14 +104,6 @@ export default function EditUserForm({
errors={errors}
register={register}
/>
<DropdownInput
label={'Role'}
interfaceRef={'role'}
required
errors={errors}
register={register}
enumType={UserRole}
/>
<SubmitButton errorMessage={errorMessage} />
</form>
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Pages/StudentDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@/Components/dashboard';
import ResourcesSideBar from '@/Components/ResourcesSideBar';

export default function StudentDashboard() {
export default function StudentLayer2() {
const { user } = useAuth();
const navigate = useNavigate();
if (!user) {
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/Pages/StudentLayer0.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useAuth } from '@/useAuth';

export default function StudentLayer0() {
const { user } = useAuth();
return (
<div className="card card-title">
<h1 className="text-2xl"> Hi, {user?.name_first ?? 'Student'}! </h1>
<h2 className="text-xl"> Welcome to UnlockEd</h2>
<img
src="/ul-logo.png"
alt="UnlockEd Logo"
className="w-125px h-125px"
/>
<div className="card card-row-padding"></div>
</div>
);
}
47 changes: 19 additions & 28 deletions frontend/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import Loading from './Components/Loading';
import AuthenticatedLayout from './Layouts/AuthenticatedLayout.tsx';
import { PathValueProvider } from '@/Context/PathValueCtx';
import AdminDashboard from './Pages/AdminDashboard.tsx';
import StudentDashboard from './Pages/StudentDashboard.tsx';
import {
getFacilities,
getOpenContentDashboardData,
Expand All @@ -55,6 +54,8 @@ import FavoritesPage from './Pages/Favorites.tsx';
import OpenContentLevelDashboard from './Pages/OpenContentLevelDashboard.tsx';
import OperationalInsightsPage from './Pages/OperationalInsights.tsx';
import HelpfulLinksManagement from './Pages/HelpfulLinksManagement.tsx';
import StudentLayer0 from './Pages/StudentLayer0.tsx';
import StudentLayer2 from './Pages/StudentDashboard.tsx';

const WithAuth: React.FC = () => {
return (
Expand Down Expand Up @@ -140,6 +141,14 @@ const router = createBrowserRouter([
path: ['consent']
}
},
{
path: 'home',
element: <StudentLayer0 />,
handle: {
title: 'UnlockEd',
path: ['home']
}
},
{
path: '',
element: (
Expand Down Expand Up @@ -237,7 +246,7 @@ const router = createBrowserRouter([
children: [
{
path: 'student-activity',
element: <StudentDashboard />,
element: <StudentLayer2 />,
loader: getRightSidebarData,
handle: {
title: 'Student Activity',
Expand Down Expand Up @@ -271,15 +280,6 @@ const router = createBrowserRouter([
),
errorElement: <Error />,
children: [
{
path: 'student-activity',
element: <StudentDashboard />,
loader: getRightSidebarData,
handle: {
title: 'Student Activity',
path: ['student-activity']
}
},
{
path: 'programs',
element: <Programs />,
Expand Down Expand Up @@ -337,6 +337,14 @@ const router = createBrowserRouter([
path: ['admins']
}
},
{
path: 'facilities',
element: <FacilityManagement />,
handle: {
title: 'Facilities',
path: ['facilities']
}
},
{
path: '',
element: (
Expand Down Expand Up @@ -381,26 +389,9 @@ const router = createBrowserRouter([
title: 'Course Catalog',
path: ['course-catalog']
}
},
{
path: 'student-activity',
element: <StudentDashboard />,
loader: getRightSidebarData,
handle: {
title: 'Student Activity',
path: ['student-activity']
}
}
]
},
{
path: 'facilities',
element: <FacilityManagement />,
handle: {
title: 'Facilities',
path: ['facilities']
}
},
{
path: '',
element: (
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/routeLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
OpenContentItem,
OpenContentProvider,
ServerResponse,
HelpfulLink,
HelpfulLinkAndSort,
Library
} from './common';
Expand Down Expand Up @@ -61,7 +60,7 @@ export const getRightSidebarData: LoaderFunction = async () => {
]);

const resourcesData = resourcesResp.success
? (resourcesResp.data as HelpfulLink[])
? (resourcesResp.data as HelpfulLinkAndSort).helpful_links
: [];
const openContentData = openContentResp.success
? (openContentResp.data as OpenContentProvider[])
Expand Down
Loading

0 comments on commit 83d5d2c

Please sign in to comment.