Skip to content

Commit

Permalink
Add not found page and check user type
Browse files Browse the repository at this point in the history
  • Loading branch information
jadmsaadaot committed Oct 31, 2024
1 parent 60c3339 commit 9998f00
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 191 deletions.
1 change: 0 additions & 1 deletion submit-api/src/submit_api/resources/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class User(Resource):
def get(guid):
"""Fetch an account by id."""
user = UserService.get_by_auth_guid(guid)
print(UserSchema().dump(user))
if not user:
return ResourceNotFoundError(f"User with guid {guid} not found")
return UserSchema().dump(user), HTTPStatus.OK
152 changes: 0 additions & 152 deletions submit-web/src/components/App/Users/UserModal.tsx

This file was deleted.

23 changes: 2 additions & 21 deletions submit-web/src/hooks/api/useAccounts.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OnErrorType, submitRequest } from "@/utils/axiosUtils";
import { queryOptions, useMutation, useQuery } from "@tanstack/react-query";
import { defaultUseQueryOptions, QUERY_KEY } from "./constants";
import { User } from "@/models/User";

type CreateAccountRequest = {
first_name: string;
Expand All @@ -23,28 +24,8 @@ const createAccount = (account: CreateAccountRequest) => {
});
};

type GetUserResponse = {
id: number;
auth_guid: string;
type: string;
account_user: {
first_name: string;
last_name: string;
position: string;
work_contact_number: string;
work_email_address: string;
created_at: string;
updated_at: string;
account_id: number;
account: {
id: number;
proponent_id: number;
};
};
};
const getUserByGuid = (guid?: string) => {
console.log("guid", guid);
return submitRequest<GetUserResponse>({ url: `/users/guid/${guid}` });
return submitRequest<User>({ url: `/users/guid/${guid}` });
};

type CreateAccountOptions = {
Expand Down
14 changes: 4 additions & 10 deletions submit-web/src/models/Account.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
export interface User {
id: number;
first_name: string;
last_name: string;
username: string;
email_address: string;
contact_number: string;
description: string;
}

export type Account = {
id: number;
proponent_id: number;
};
3 changes: 3 additions & 0 deletions submit-web/src/models/AccountUser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Account } from "./Account";

export type AccountUser = {
id: number;
account_id: number;
Expand All @@ -8,4 +10,5 @@ export type AccountUser = {
work_email_address: string;
work_contact_number: string;
auth_guid: string;
account: Account;
};
2 changes: 0 additions & 2 deletions submit-web/src/models/Submission.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { User } from "./User";

export type SubmissionStatus =
| "NEW_SUBMISSION"
| "COMPLETED"
Expand Down
18 changes: 18 additions & 0 deletions submit-web/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createFileRoute } from '@tanstack/react-router'

import { Route as rootRoute } from './routes/__root'
import { Route as RegistrationImport } from './routes/registration'
import { Route as NotFoundImport } from './routes/not-found'
import { Route as ErrorImport } from './routes/error'
import { Route as AuthenticatedImport } from './routes/_authenticated'
import { Route as IndexImport } from './routes/index'
Expand Down Expand Up @@ -59,6 +60,11 @@ const RegistrationRoute = RegistrationImport.update({
getParentRoute: () => rootRoute,
} as any)

const NotFoundRoute = NotFoundImport.update({
path: '/not-found',
getParentRoute: () => rootRoute,
} as any)

const ErrorRoute = ErrorImport.update({
path: '/error',
getParentRoute: () => rootRoute,
Expand Down Expand Up @@ -222,6 +228,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ErrorImport
parentRoute: typeof rootRoute
}
'/not-found': {
id: '/not-found'
path: '/not-found'
fullPath: '/not-found'
preLoaderRoute: typeof NotFoundImport
parentRoute: typeof rootRoute
}
'/registration': {
id: '/registration'
path: '/registration'
Expand Down Expand Up @@ -402,6 +415,7 @@ export const routeTree = rootRoute.addChildren({
AuthenticatedRegistrationCreateAccountRoute,
}),
ErrorRoute,
NotFoundRoute,
RegistrationRoute,
OidcCallbackStaffRoute,
ProponentRoute: ProponentRoute.addChildren({}),
Expand All @@ -419,6 +433,7 @@ export const routeTree = rootRoute.addChildren({
"/",
"/_authenticated",
"/error",
"/not-found",
"/registration",
"/oidc-callback/staff",
"/proponent",
Expand All @@ -440,6 +455,9 @@ export const routeTree = rootRoute.addChildren({
"/error": {
"filePath": "error.tsx"
},
"/not-found": {
"filePath": "not-found.tsx"
},
"/registration": {
"filePath": "registration.tsx"
},
Expand Down
7 changes: 6 additions & 1 deletion submit-web/src/routes/_authenticated.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PageLoader } from "@/components/Shared/PageLoader";
import { useGetUserByGuid } from "@/hooks/api/useAccounts";
import { USER_TYPE } from "@/models/User";
import { useAccount } from "@/store/accountStore";
import { createFileRoute, Navigate, Outlet } from "@tanstack/react-router";
import { useEffect } from "react";
Expand Down Expand Up @@ -48,7 +49,11 @@ function Auth() {
}

if (!isAuthenticated) {
return <Navigate to={"/"} />;
return <Navigate to={"/not-found"} />;
}

if (userData?.type !== USER_TYPE.PROPONENT) {
return <Navigate to={"/error"} />;
}

return <Outlet />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export default function SubmissionPage() {
PACKAGE_STATUS.SUBMITTED.value,
);

console.log(accountProject?.project?.ea_certificate);
return (
<PageGrid>
<Grid item xs={12}>
Expand Down
10 changes: 10 additions & 0 deletions submit-web/src/routes/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import PageNotFound from "@/components/Shared/PageNotFound";
import { createFileRoute } from "@tanstack/react-router";

export const Route = createFileRoute("/not-found")({
component: NotFound,
});

function NotFound() {
return <PageNotFound />;
}
3 changes: 0 additions & 3 deletions submit-web/src/routes/oidc-callback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ function OidcCallback() {
});

if (getAuthError) {
console.log("auth error", getAuthError);
return <Navigate to="/error" />;
}

console.log(userData);

if (userData?.account_user.account_id) {
return <Navigate to="/projects" />;
}
Expand Down

0 comments on commit 9998f00

Please sign in to comment.