Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5108fce
MSPCA-51: add volunteer helpers, getVolunteer, and useVolunteerId
Juwang110 Nov 5, 2026
f36f43e
MSPCA-51: add responsive Navbar component
Juwang110 Nov 5, 2026
f69239a
MSPCA-51: render Navbar in shared app layout
Juwang110 Nov 5, 2026
7434226
MSPCA-51: use URL volunteer ID for match requests
Juwang110 Nov 5, 2026
5156e6a
MSPCA-51: keep navbar on page errors and fix double-height scroll
Juwang110 Nov 5, 2026
fe7cf19
MSPCA-51: reject unsafe volunteer IDs and warn on failed volunteer fetch
Juwang110 Nov 6, 2026
0d55633
MSPCA-51: remove navbar, modal, and route specs
Juwang110 Nov 9, 2026
d2205d5
Merge pk/mspca-46-animal-availability-frontend-endpoint into jw/mspca…
Juwang110 Nov 9, 2026
a538b06
MSPCA-51: remove unneeded comments
Juwang110 Nov 10, 2026
cb4eaba
MSPCA-51: mirror the full GET /volunteers/:id response in Volunteer type
Juwang110 Nov 10, 2026
df4a2f6
MSPCA-51: remove comments from types.ts
Juwang110 Nov 10, 2026
e7d44b8
MSPCA-51: restore types.ts comments except the Volunteer shape note
Juwang110 Nov 10, 2026
2d99608
MSPCA-51: remove /test route and Test component
Juwang110 Nov 10, 2026
ce83158
MSPCA-51: use Chakra Button in Navbar, inline avatar, drop hover unde…
Juwang110 Nov 10, 2026
ccbde66
MSPCA-51: fix app spec so it passes in CI
Juwang110 Nov 10, 2026
dc0299c
MSPCA-51: add frontend test workflow, rename jest workflow to backend…
Juwang110 Nov 10, 2026
a1bd83a
Merge pk/mspca-46-animal-availability-frontend-endpoint into jw/mspca…
Juwang110 Nov 10, 2026
fd94b4b
MSPCA-51: use Trello label colors for volunteer avatars
Juwang110 Nov 12, 2026
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Jest run
name: Backend tests

on:
push:
Expand All @@ -7,7 +7,7 @@ on:
branches: ['**']

jobs:
jest-tests:
backend-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/frontend_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Frontend tests

on:
push:
branches: ['**']
pull_request:
branches: ['**']

jobs:
frontend-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24.x
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: npx vitest run --root apps/frontend
6 changes: 5 additions & 1 deletion apps/frontend/src/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { type AxiosInstance } from 'axios';
import { fetchAuthSession } from 'aws-amplify/auth';

import { isAuthEnabled } from '../auth/auth.config';
import type { Animal, CreateMatchBody, Match } from '../types';
import type { Animal, CreateMatchBody, Match, Volunteer } from '../types';

const defaultBaseUrl =
import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:3000';
Expand Down Expand Up @@ -50,6 +50,10 @@ export class ApiClient {
return this.get('/api/animals') as Promise<Animal[]>;
}

public async getVolunteer(volunteerId: number): Promise<Volunteer> {
return this.get(`/api/volunteers/${volunteerId}`) as Promise<Volunteer>;
}

public async createMatch(body: CreateMatchBody): Promise<Match> {
return this.post('/api/matches', body) as Promise<Match>;
}
Expand Down
9 changes: 4 additions & 5 deletions apps/frontend/src/app.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { render } from '@testing-library/react';

import App from './app';

vi.mock('@api/apiClient', () => ({
default: { getHello: vi.fn().mockResolvedValue('hello') },
}));

describe('App', () => {
it('should render successfully', () => {
const { baseElement } = render(<App />);
expect(baseElement).toBeTruthy();
});

it('should have a greeting as the title', () => {
const { getByText } = render(<App />);
expect(getByText(/Welcome frontend/gi)).toBeTruthy();
});
});
36 changes: 27 additions & 9 deletions apps/frontend/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
import { useEffect } from 'react';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import {
createBrowserRouter,
RouterProvider,
type RouteObject,
} from 'react-router-dom';

import apiClient from '@api/apiClient';
import Root from '@containers/root';
import Layout from '@containers/Layout';
import NotFound from '@containers/404';
import AnimalAvailability from '@pages/AnimalAvailability';
import { ROUTES } from './routes';

const router = createBrowserRouter([
Comment thread
Juwang110 marked this conversation as resolved.
Resolved
// Every page is a child of Layout so the navbar renders once, above all pages.
// Page errors are caught by the inner errorElement so the navbar stays put;
// the outer one only catches errors from the layout itself.
export const routes: RouteObject[] = [
{
path: '/',
element: <Root />,
element: <Layout />,
errorElement: <NotFound />,
children: [
{
errorElement: <NotFound />,
children: [
{ path: '/', element: <Root /> },
{
path: ROUTES.ANIMAL_AVAILABILITY,
element: <AnimalAvailability />,
},
{ path: '*', element: <NotFound /> },
],
},
],
},
{
path: ROUTES.ANIMAL_AVAILABILITY,
element: <AnimalAvailability />,
},
]);
];

const router = createBrowserRouter(routes);

export const App: React.FC = () => {
useEffect(() => {
Expand Down
97 changes: 97 additions & 0 deletions apps/frontend/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { useEffect, useState } from 'react';
import { Button, Flex, Image, Text } from '@chakra-ui/react';

import apiClient from '@api/apiClient';
import type { Volunteer } from '../types';
import { useVolunteerId } from '@utils/useVolunteerId';
import { getAvatarColor, getInitials } from '@utils/volunteer';
import logo from '../assets/mspca-logo.png';

/** Site-wide header: MSPCA logo and the current volunteer's profile button. */
const Navbar: React.FC = () => {
const volunteerId = useVolunteerId();
const [loaded, setLoaded] = useState<Volunteer | null>(null);
const volunteer = loaded?.volunteerId === volunteerId ? loaded : null;

useEffect(() => {
if (volunteerId === null) return;

let cancelled = false;
apiClient
.getVolunteer(volunteerId)
.then((result) => {
if (!cancelled) setLoaded(result);
})
.catch((err: unknown) => {
console.warn(`Could not load volunteer ${volunteerId}`, err);
});
return () => {
cancelled = true;
};
}, [volunteerId]);

return (
<Flex
as="header"
px={{ base: '4', md: '8' }}
py="4"
minH={{ md: '120px' }}
bg="gray.50"
boxShadow="card"
justify="space-between"
align="center"
>
<Image
src={logo}
alt="MSPCA - Kindness and Care for Animals"
w={{ base: '142px', md: '196px' }}
h={{ base: '64px', md: '88px' }}
objectFit="contain"
/>
{/* TODO: link to the volunteer profile page once it exists. */}
<Button
type="button"
aria-label="My Profile"
variant="plain"
display="flex"
alignItems="center"
gap="4"
h="auto"
cursor="pointer"
>
<Flex
data-testid="navbar-avatar"
boxSize={{ base: '50px', md: '66px' }}
flexShrink={0}
align="center"
justify="center"
bg={volunteer ? getAvatarColor(volunteer.volunteerId) : 'gray.300'}
color="white"
borderRadius="full"
boxShadow="card"
outline="3px solid"
outlineColor="neutrals.black"
outlineOffset="-3px"
fontSize={{ base: '20px', md: '24px' }}
fontWeight="semibold"
lineHeight="1"
>
{volunteer
? getInitials(volunteer.firstName, volunteer.lastName)
: ''}
</Flex>
<Text
display={{ base: 'none', md: 'block' }}
color="neutrals.black"
fontSize="24px"
fontWeight="semibold"
lineHeight="36px"
>
My Profile
</Text>
</Button>
</Flex>
);
};

export default Navbar;
12 changes: 6 additions & 6 deletions apps/frontend/src/components/modals/AnimalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ import { ExternalLink, House } from 'lucide-react';
import apiClient from '@api/apiClient';
import type { Animal } from '../../types';
import { HOMEBASE_ADDRESSES, formatAge } from '@utils/animals';
import { useVolunteerId } from '@utils/useVolunteerId';
import { PLACEHOLDER_IMAGE } from '../AnimalCard';
import RestrictionTag from '../RestrictionTag';

// TODO: replace with the logged-in volunteer's ID once the frontend has access
// to the current user's profile.
const CURRENT_VOLUNTEER_ID = 1;

interface AnimalModalProps {
animal: Animal | null;
onClose: () => void;
Expand All @@ -42,6 +39,8 @@ const AnimalModal: React.FC<AnimalModalProps> = ({ animal, onClose }) => {
const [submitting, setSubmitting] = useState(false);
const [requested, setRequested] = useState(false);
const [error, setError] = useState<string | null>(null);
// TEMPORARY: comes from the URL until sign-in is implemented.
const volunteerId = useVolunteerId();

// Reset the form when a different animal is opened.
const [formAnimalId, setFormAnimalId] = useState(animal?.animalId);
Expand All @@ -54,12 +53,12 @@ const AnimalModal: React.FC<AnimalModalProps> = ({ animal, onClose }) => {
}

const handleRequest = async () => {
if (!animal) return;
if (!animal || volunteerId === null) return;
setSubmitting(true);
setError(null);
try {
await apiClient.createMatch({
volunteerId: CURRENT_VOLUNTEER_ID,
volunteerId,
chameleonAnimalId: animal.chameleonAnimalId,
additionalComments: comments.trim() || undefined,
});
Expand Down Expand Up @@ -328,6 +327,7 @@ const AnimalModal: React.FC<AnimalModalProps> = ({ animal, onClose }) => {
lineHeight="24px"
onClick={handleRequest}
loading={submitting}
disabled={volunteerId === null}
>
Apply
</Button>
Expand Down
14 changes: 12 additions & 2 deletions apps/frontend/src/containers/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ import { useRouteError } from 'react-router-dom';
import { getErrorMessage } from '@utils/router';

const NotFound: React.FC = () => {
const errorMessage = getErrorMessage(useRouteError());
const error = useRouteError();

// Rendered by the catch-all route for unknown URLs, so there is no error.
if (error == null) {
return (
<div id="error-page">
<h1>Page not found</h1>
<p>Sorry, we couldn't find the page you're looking for.</p>
</div>
);
}

return (
<div id="error-page">
<h1>Oops!</h1>
<p>Sorry, an unexpected error has occurred.</p>
<p>
<i>{errorMessage}</i>
<i>{getErrorMessage(error)}</i>
</p>
</div>
);
Expand Down
17 changes: 17 additions & 0 deletions apps/frontend/src/containers/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Flex } from '@chakra-ui/react';
import { Outlet } from 'react-router-dom';

import Navbar from '@components/Navbar';

/**
* Shared app shell: the navbar sits above every page. The column fills the
* viewport so pages can grow into the remaining height with `flex="1"`.
*/
const Layout: React.FC = () => (
<Flex direction="column" minH="100vh">
<Navbar />
<Outlet />
</Flex>
);

export default Layout;
Loading
Loading