Skip to content

Commit

Permalink
Api route protection & Item editing
Browse files Browse the repository at this point in the history
Added
- ability to edit items including ability to add images to items
- corresponding api routes to complete aforementioned actions

Updated:
- Api route protection to follow workflow recommended by the 'NextAuth'-library
- Multiple links across app to avoid react hydration errors

+ some minor changes and updated libraries
  • Loading branch information
eerosahlberg committed Mar 31, 2024
1 parent e6a1355 commit 4cf09d4
Show file tree
Hide file tree
Showing 30 changed files with 1,426 additions and 1,206 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["next/babel"],
"plugins": ["superjson-next"]
"presets": ["next/babel"],
"plugins": ["superjson-next"]
}
12 changes: 0 additions & 12 deletions components/Link.js

This file was deleted.

20 changes: 10 additions & 10 deletions components/NotAuthenticated.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Heading, Button } from '@chakra-ui/react';
import Link from '../components/Link';
import { Heading, Button, Link } from '@chakra-ui/react';
import NextLink from 'next/link';

export default function NotAuthenticated() {
return (
<>
<Heading>Ei käyttöoikeutta</Heading>
<Link href='/'>
<Button>Palaa etusivulle</Button>
</Link>
</>
);
return (
<>
<Heading>Ei käyttöoikeutta</Heading>
<Link as={NextLink} href='/'>
<Button>Palaa etusivulle</Button>
</Link>
</>
);
}
65 changes: 38 additions & 27 deletions components/ReservationTable.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
import React from 'react';

import { Table, Thead, Tbody, Tr, Th, Td, TableContainer } from '@chakra-ui/react';
import { Table, Thead, Tbody, Tr, Th, Td, TableContainer, Link } from '@chakra-ui/react';

import Link from './Link';
import NextLink from 'next/link';
import { useSession } from 'next-auth/react';

const DateTimeToString = (date) => {
return date.toLocaleString('fi-FI');
return date.toLocaleString('fi-FI');
};

export default function ReservationTable({ reservations }) {
return (
<TableContainer>
<Table>
<Thead>
<Tr>
<Th>Alku</Th>
<Th>Loppu</Th>
<Th>Määrä</Th>
</Tr>
</Thead>
<Tbody>
{reservations.map((reservation) => {
return (
<Tr key={reservation.id}>
<Td>{DateTimeToString(reservation.loan.startTime)}</Td>
<Td>{DateTimeToString(reservation.loan.endTime)}</Td>
<Td>{reservation.amount}</Td>
</Tr>
);
})}
</Tbody>
</Table>
</TableContainer>
);
const { data: session } = useSession();

return (
<TableContainer>
<Table>
<Thead>
<Tr>
{session?.user?.group === 'ADMIN' ? <Th>Varaaja</Th> : null}
<Th>Alku</Th>
<Th>Loppu</Th>
<Th>Määrä</Th>
</Tr>
</Thead>
<Tbody>
{reservations.map((reservation) => {
return (
<Tr key={reservation.id}>
{session?.user?.group === 'ADMIN' ? (
<Td>
<Link as={NextLink} href={`/loan/${reservation.loan.id}`}>
{reservation.loan.user.name}
</Link>
</Td>
) : null}
<Td>{DateTimeToString(reservation.loan.startTime)}</Td>
<Td>{DateTimeToString(reservation.loan.endTime)}</Td>
<Td>{reservation.amount}</Td>
</Tr>
);
})}
</Tbody>
</Table>
</TableContainer>
);
}
76 changes: 34 additions & 42 deletions components/ReservationTableLoanView.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,43 @@
import React from 'react';

import {
Table,
Thead,
Tbody,
Tr,
Th,
Td,
TableContainer,
} from '@chakra-ui/react';
import { Table, Thead, Tbody, Tr, Th, Td, TableContainer, Link } from '@chakra-ui/react';

import Link from './Link';
import NextLink from 'next/link';

const DateTimeToString = (date) => {
return date.toLocaleString('fi-FI');
return date.toLocaleString('fi-FI');
};

export default function ReservationTableLoanView({ loan }) {
return (
<TableContainer>
<Table>
<Thead>
<Tr>
<Th>Nimi</Th>
<Th>Alku</Th>
<Th>Loppu</Th>
<Th>Määrä</Th>
<Th></Th>
</Tr>
</Thead>
<Tbody>
{loan.reservations.map((reservation) => {
return (
<Tr key={reservation.id}>
<Td>
<Link href={`/item/${reservation.item.id}`}>
{reservation.item.name}
</Link>
</Td>
<Td>{DateTimeToString(loan.startTime)}</Td>
<Td>{DateTimeToString(loan.endTime)}</Td>
<Td>{reservation.amount}</Td>
</Tr>
);
})}
</Tbody>
</Table>
</TableContainer>
);
return (
<TableContainer>
<Table>
<Thead>
<Tr>
<Th>Nimi</Th>
<Th>Alku</Th>
<Th>Loppu</Th>
<Th>Määrä</Th>
<Th></Th>
</Tr>
</Thead>
<Tbody>
{loan.reservations.map((reservation) => {
return (
<Tr key={reservation.id}>
<Td>
<Link as={NextLink} href={`/item/${reservation.item.id}`}>
{reservation.item.name}
</Link>
</Td>
<Td>{DateTimeToString(loan.startTime)}</Td>
<Td>{DateTimeToString(loan.endTime)}</Td>
<Td>{reservation.amount}</Td>
</Tr>
);
})}
</Tbody>
</Table>
</TableContainer>
);
}
Loading

0 comments on commit 4cf09d4

Please sign in to comment.