mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Update login to redirect to current user page
This commit is contained in:
5
.github/workflows/github-actions-demo.yml
vendored
5
.github/workflows/github-actions-demo.yml
vendored
@@ -18,8 +18,3 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
npm ci
|
npm ci
|
||||||
|
|
||||||
- name: Prettier Action
|
|
||||||
# You may pin to the exact commit or the version.
|
|
||||||
# uses: creyD/prettier_action@6602189cf8bac1ce73ffe601925f6127ab7f21ac
|
|
||||||
uses: creyD/prettier_action@v4.2
|
|
||||||
|
|||||||
@@ -29,9 +29,8 @@ const LoginForm = () => {
|
|||||||
|
|
||||||
const onSubmit: SubmitHandler<LoginT> = async (data) => {
|
const onSubmit: SubmitHandler<LoginT> = async (data) => {
|
||||||
try {
|
try {
|
||||||
const response = await sendLoginUserRequest(data);
|
await sendLoginUserRequest(data);
|
||||||
|
router.push(`/user/current`);
|
||||||
router.push(`/users/${response.id}`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
setResponseError(error.message);
|
setResponseError(error.message);
|
||||||
@@ -74,7 +73,7 @@ const LoginForm = () => {
|
|||||||
|
|
||||||
{responseError && <ErrorAlert error={responseError} setError={setResponseError} />}
|
{responseError && <ErrorAlert error={responseError} setError={setResponseError} />}
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<button type="submit" className="btn btn-primary w-full">
|
<button type="submit" className="btn-primary btn w-full">
|
||||||
Login
|
Login
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
|
|
||||||
interface SpinnerProps {
|
interface SpinnerProps {
|
||||||
size?: 'xs' | 'sm' | 'md' | 'lg';
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
||||||
}
|
}
|
||||||
|
|
||||||
const Spinner: FC<SpinnerProps> = ({ size = 'md' }) => {
|
const Spinner: FC<SpinnerProps> = ({ size = 'md' }) => {
|
||||||
@@ -10,13 +10,14 @@ const Spinner: FC<SpinnerProps> = ({ size = 'md' }) => {
|
|||||||
sm: 'w-[20px]',
|
sm: 'w-[20px]',
|
||||||
md: 'w-[100px]',
|
md: 'w-[100px]',
|
||||||
lg: 'w-[150px]',
|
lg: 'w-[150px]',
|
||||||
|
xl: 'w-[200px]',
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div role="status" className="flex flex-col items-center justify-center rounded-3xl">
|
<div role="status" className="flex flex-col items-center justify-center rounded-3xl">
|
||||||
<svg
|
<svg
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className={`${spinnerWidths[size]} animate-spin fill-success text-gray-500`}
|
className={`${spinnerWidths[size]} animate-spin fill-secondary text-primary`}
|
||||||
viewBox="0 0 100 101"
|
viewBox="0 0 100 101"
|
||||||
fill="none"
|
fill="none"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
|||||||
@@ -7,21 +7,29 @@ import { GetServerSideProps, NextPage } from 'next';
|
|||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
|
|
||||||
const ProtectedPage: NextPage = () => {
|
const ProtectedPage: NextPage = () => {
|
||||||
const { user, error, isLoading } = useContext(UserContext);
|
const { user, isLoading } = useContext(UserContext);
|
||||||
|
|
||||||
|
const currentTime = new Date().getHours();
|
||||||
|
|
||||||
|
const isMorning = currentTime > 5 && currentTime < 12;
|
||||||
|
const isAfternoon = currentTime > 12 && currentTime < 18;
|
||||||
|
const isEvening = currentTime > 18 && currentTime < 24;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<div className="flex h-full flex-col items-center justify-center">
|
<div className="flex h-full flex-col items-center justify-center space-y-3">
|
||||||
<h1 className="text-7xl font-bold text-white">Hello!</h1>
|
{isLoading && <Spinner size="xl" />}
|
||||||
<>
|
|
||||||
{isLoading && <Spinner />}
|
|
||||||
{error && <p>Something went wrong.</p>}
|
|
||||||
{user && (
|
{user && (
|
||||||
<div>
|
<>
|
||||||
<p>{user.username}</p>
|
<h1 className="text-7xl font-bold">
|
||||||
</div>
|
Good {isMorning && 'morning'}
|
||||||
)}
|
{isAfternoon && 'afternoon'}
|
||||||
|
{isEvening && 'evening'}
|
||||||
|
{`, ${user?.firstName}!`}
|
||||||
|
</h1>
|
||||||
|
<h2 className="text-4xl font-bold">Welcome to the Biergarten App!</h2>
|
||||||
</>
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user