Skip to content

Commit

Permalink
Improve file/folder structure (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
JorWo authored May 31, 2024
1 parent 6a0a391 commit fac22c9
Show file tree
Hide file tree
Showing 55 changed files with 156 additions and 247 deletions.
2 changes: 1 addition & 1 deletion ui/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const config: Config = {
customExportConditions: []
},
setupFilesAfterEnv: [
'<rootDir>/tests/setupJest.ts'
'<rootDir>/tests/setup-jest.ts'
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
moduleDirectories: ['node_modules', '<rootDir>'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';
import { IronSession, getIronSession } from 'iron-session';
import { SessionData, SessionOptions } from './Session';
import User, { AnonymousUser } from './User';
import { validateTicket } from './Saml11Validator';
import { setRoles } from './AuthorizationService';
import { SessionData, SessionOptions } from './session';
import User, { AnonymousUser } from './user';
import { validateTicket } from './saml-11-validator';
import { setRoles } from './authorization';
import { isDeepStrictEqual } from 'util';

const casUrl = process.env.NEXT_PUBLIC_CAS_URL as string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use server';

import User from './User';
import Role from './Role';
import User from './user';
import Role from './role';

const apiBaseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import User, { AnonymousUser } from './User';
import User, { AnonymousUser } from './user';
import uniqid from 'uniqid';
import { format } from 'util';
import { transform } from 'camaro';
Expand Down
2 changes: 1 addition & 1 deletion ui/src/access/Session.ts → ui/src/access/session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import User from './User';
import User from './user';

export interface SessionData {
user: User;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/access/User.ts → ui/src/access/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MemberResult } from '@/groupings/GroupingsApiResults';
import Role from './Role';
import { MemberResult } from '@/models/groupings-api-results';
import Role from './role';

type User = {
roles: Role[]
Expand Down
6 changes: 3 additions & 3 deletions ui/src/services/EmailService.ts → ui/src/actions/email.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use server';

import { getCurrentUser } from '@/access/AuthenticationService';
import { ApiError } from '@/groupings/GroupingsApiResults';
import { postRequest } from './FetchService';
import { getCurrentUser } from '@/access/authentication';
import { ApiError } from '@/models/groupings-api-results';
import { postRequest } from './http-client';

const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL as string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server';

import { getCurrentUser } from '@/access/AuthenticationService';
import { getCurrentUser } from '@/access/authentication';
import {
Announcements,
ApiError,
Expand All @@ -19,7 +19,7 @@ import {
GroupingUpdateDescriptionResult,
MemberAttributeResults,
MembershipResults
} from '../groupings/GroupingsApiResults';
} from '@/models/groupings-api-results';
import {
deleteRequest,
deleteRequestAsync,
Expand All @@ -29,7 +29,7 @@ import {
postRequestRetry,
putRequest,
putRequestAsync
} from './FetchService';
} from './http-client';

const baseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use server';

import { ApiError } from '../groupings/GroupingsApiResults';
import { getCurrentUser } from '@/access/AuthenticationService';
import { sendStackTrace } from './EmailService';
import { ApiError } from '@/models/groupings-api-results';
import { getCurrentUser } from '@/access/authentication';
import { sendStackTrace } from './email';

const maxRetries = 3;
const baseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Role from '@/access/Role';
import Role from '@/access/role';
import Image from 'next/image';
import { KeyRound } from 'lucide-react';
import Link from 'next/link';
import { Button } from '@/components/ui/button';
import { getNumberOfGroupings, getNumberOfMemberships } from '@/services/GroupingsApiService';
import { getCurrentUser } from '@/access/AuthenticationService';
import { getNumberOfGroupings, getNumberOfMemberships } from '@/actions/groupings-api';
import { getCurrentUser } from '@/access/authentication';

const AfterLogin = async ()=>{
const AfterLogin = async () => {
const [currentUser, numberOfGroupings, numberOfMemberships] = await Promise.all([
getCurrentUser(),
getNumberOfGroupings(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { AlertCircle } from 'lucide-react';
import { getAnnouncements } from '@/services/GroupingsApiService';
import { getAnnouncements } from '@/actions/groupings-api';

const Announcements = async () => {
const announcements = await getAnnouncements();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button } from '@/components/ui/button';
import { ArrowRight } from 'lucide-react';
import UHGroupingsInfo from '@/components/UHGroupingsInfo';
import UHGroupingsInfo from '@/components/uh-groupings-info';

const BeforeLogin = () => (
<main className="bg-seafoam pb-10">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use client';

import { Button } from '@/components/ui/button';
import Role from '@/access/Role';
import User from '@/access/User';
import { login, logout } from '@/access/AuthenticationService';
import Role from '@/access/role';
import User from '@/access/user';
import { login, logout } from '@/access/authentication';

const LoginButton = ({
currentUser
Expand Down
12 changes: 6 additions & 6 deletions ui/src/app/(index)/page.tsx → ui/src/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Image from 'next/image';
import BeforeLogin from '@/app/(index)/_components/BeforeLogin';
import AfterLogin from '@/app/(index)/_components/AfterLogin';
import { getCurrentUser } from '@/access/AuthenticationService';
import Role from '@/access/Role';
import LoginButton from '@/app/(index)/_components/LoginButton';
import Announcements from '@/app/(index)/_components/Announcements';
import BeforeLogin from '@/app/(home)/_components/before-login';
import AfterLogin from '@/app/(home)/_components/after-login';
import { getCurrentUser } from '@/access/authentication';
import Role from '@/access/role';
import LoginButton from '@/app/(home)/_components/login-button';
import Announcements from '@/app/(home)/_components/announcements';

const Home = async () => {
const currentUser = await getCurrentUser();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
AlertDialogCancel
} from '@/components/ui/alert-dialog';
import { useIdleTimer } from 'react-idle-timer';
import { logout } from '@/access/AuthenticationService';
import User from '@/access/User';
import Role from '@/access/Role';
import { logout } from '@/access/authentication';
import User from '@/access/user';
import Role from '@/access/role';

const timeout = 1000 * 60 * 30; // Total timeout - 30 minutes in milliseconds
const promptBeforeIdle = 1000 * 60 * 5; // Time prior to timeout until modal opens - 5 minutes in milliseconds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client';

import { Button } from '@/components/ui/button';
import Role from '@/access/Role';
import User from '@/access/User';
import { login, logout } from '@/access/AuthenticationService';
import Role from '@/access/role';
import User from '@/access/user';
import { login, logout } from '@/access/authentication';
import { LogInIcon, LogOutIcon } from 'lucide-react';

const LoginButton = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
SheetContent,
SheetTrigger,
} from '@/components/ui/sheet'
import User from '@/access/User';
import User from '@/access/user';
import Link from 'next/link';
import { NavLinks } from './NavLinks';
import { NavLinks } from './nav-links';
import { useState } from 'react';
import Role from '@/access/Role';
import Role from '@/access/role';

const MobileNavbar = ({
currentUser
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Role from '@/access/Role';
import Role from '@/access/role';

export const NavLinks = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Link from 'next/link';
import Image from 'next/image';
import LoginButton from './LoginButton';
import { getCurrentUser } from '@/access/AuthenticationService';
import MobileNavbar from './MobileNavbar';
import { NavLinks } from './NavLinks';
import Role from '@/access/Role';
import TimeoutModal from '@/app/_components/layout/modal/TimeoutModal';
import Role from '@/access/role';
import { getCurrentUser } from '@/access/authentication';
import { NavLinks } from './nav-links';
import LoginButton from './login-button';
import MobileNavbar from './mobile-navbar';
import TimeoutModal from '../modal/timeout-modal';

const Navbar = async () => {
const currentUser = await getCurrentUser();
Expand All @@ -18,28 +18,28 @@ const Navbar = async () => {
<Link href="/" className="lg:inline hidden">
<Image
src="/uhgroupings/uh-groupings-logo.svg"
alt="UH Groupings Logo"
width={256}
alt="UH Groupings Logo"
width={256}
height={256} />
</Link>
<div className="flex lg:hidden">
<MobileNavbar currentUser={currentUser} />
<Link href="/">
<Image
src="/uhgroupings/uh-groupings-logo-large.svg"
alt="UH Groupings Logo"
width={56}
<Image
src="/uhgroupings/uh-groupings-logo-large.svg"
alt="UH Groupings Logo"
width={56}
height={56} />
</Link>
</div>
<div className="text-lg text-uh-black my-auto lg:space-x-5">
{NavLinks
.filter(navLink =>
.filter(navLink =>
currentUser.roles.includes(Role.ADMIN) || currentUser.roles.includes(navLink.role))
.map(navLink =>
<Link
href={navLink.link}
key={navLink.name}
.map(navLink =>
<Link
href={navLink.link}
key={navLink.name}
className="hover:text-uh-teal lg:inline hidden">
{navLink.name}
</Link>)}
Expand All @@ -51,5 +51,5 @@ const Navbar = async () => {
</>
);
}

export default Navbar;
8 changes: 4 additions & 4 deletions ui/src/app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UHGroupingsInfo from '@/components/UHGroupingsInfo';
import GeneralInfoSection from '@/app/about/_components/GeneralInfoSection';
import WhatHappensIfSection from '@/app/about/_components/WhatHappensIfSection';
import TechnicalInfoSection from '@/app/about/_components/TechnicalInfoSection';
import UHGroupingsInfo from '@/components/uh-groupings-info';
import GeneralInfoSection from '@/app/about/_components/general-info-section';
import WhatHappensIfSection from '@/app/about/_components/what-happens-if-section';
import TechnicalInfoSection from '@/app/about/_components/technical-info-section';

const About = () => (
<main>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/api/cas/login/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { redirect } from 'next/navigation';
import type { NextRequest } from 'next/server';
import { handleLogin } from '@/access/AuthenticationService';
import { handleLogin } from '@/access/authentication';

const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string;

Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/api/cas/logout/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { redirect } from 'next/navigation';
import { handleLogout } from '@/access/AuthenticationService';
import { handleLogout } from '@/access/authentication';

const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string;

Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import './globals.css';
import { Source_Sans_3 } from 'next/font/google';
import Footer from '@/app/_components/layout/footer/Footer';
import Navbar from './_components/navbar/navbar';
import Footer from './_components/footer/footer';
import type { Metadata } from 'next';
import Navbar from '@/app/_components/layout/navbar/Navbar';

const sourceSans3 = Source_Sans_3({
subsets: ['latin'],
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions ui/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cookies } from 'next/headers';
import { NextResponse, NextRequest } from 'next/server';
import { getIronSession } from 'iron-session';
import { SessionData, SessionOptions } from './access/Session';
import Role from './access/Role';
import { SessionData, SessionOptions } from '@/access/session';
import Role from '@/access/role';

/**
* Next.js middleware function that is called upon visiting a route that matches the config.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getCurrentUser, login, logout, handleLogin, handleLogout } from '@/access/AuthenticationService';
import { createMockSession } from '../setupJest';
import User, { AnonymousUser } from '@/access/User';
import { getCurrentUser, login, logout, handleLogin, handleLogout } from '@/access/authentication';
import { createMockSession } from '../setup-jest';
import User, { AnonymousUser } from '@/access/user';
import { redirect } from 'next/navigation';
import IronSession from 'iron-session';

Expand All @@ -9,7 +9,7 @@ const casUrl = process.env.NEXT_PUBLIC_CAS_URL as string;
const testUser: User = JSON.parse(process.env.TEST_USER_A as string);
const xmlSoapResponse = process.env.XML_SOAP_RESPONSE as string;

describe('AuthenticationService', () => {
describe('authentication', () => {

describe('getCurrentUser', () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { setRoles } from '@/access/AuthorizationService';
import Role from '@/access/Role';
import User, { AnonymousUser } from '@/access/User';
import { setRoles } from '@/access/authorization';
import Role from '@/access/role';
import User, { AnonymousUser } from '@/access/user';

const testUser: User = JSON.parse(process.env.TEST_USER_A as string);
const apiBaseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string;

describe('AuthorizationService', () => {
describe('authorization', () => {

describe('setRoles', () => {

Expand Down
4 changes: 2 additions & 2 deletions ui/tests/access/Role.test.ts → ui/tests/access/role.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Role from '@/access/Role';
import Role from '@/access/role';

describe('Role', () => {
describe('role', () => {

it('should have the same key and value', () => {
for (const [key, value] of Object.entries(Role)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { validateTicket } from '@/access/Saml11Validator';
import User, { AnonymousUser } from '@/access/User';
import { validateTicket } from '@/access/saml-11-validator';
import User, { AnonymousUser } from '@/access/user';

const testUser: User = JSON.parse(process.env.TEST_USER_A as string);
const xmlSoapResponse = process.env.XML_SOAP_RESPONSE as string;
const xmlSoapResponseRequestDenied = process.env.XML_SOAP_RESPONSE_REQUEST_DENIED as string;

describe('Saml11Validator', () => {
describe('saml-11-validator', () => {

describe('validateTicket', () => {

Expand Down
6 changes: 3 additions & 3 deletions ui/tests/access/User.test.ts → ui/tests/access/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Role from '@/access/Role';
import { AnonymousUser } from '@/access/User';
import Role from '@/access/role';
import { AnonymousUser } from '@/access/user';

describe('User', () => {
describe('user', () => {

describe('AnonymousUser', () => {

Expand Down
Loading

0 comments on commit fac22c9

Please sign in to comment.