Skip to content

Commit

Permalink
Refactor/app cleanup (#20)
Browse files Browse the repository at this point in the history
* refactor: 🚚 Move hooks into usecases

Hooks makes more sense as usecases and reposiories can handle different API protocols like GraphQL etc

* refactor: ♻️ authprovider

* refactor: 🧑‍💻 use enum

* feat: 🔧 use env to set api endpoint

* feat: ✨ Global error handler, form validations

Use zod library for form validations.
Global error handler to display API error messages.

* refactor: 🔥 rm duplicate toTask
  • Loading branch information
lakshmaji authored Jul 13, 2024
1 parent 1be3c30 commit e5aa551
Show file tree
Hide file tree
Showing 57 changed files with 556 additions and 481 deletions.
6 changes: 5 additions & 1 deletion client-app/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
PORT=3000
PORT=3000
REACT_APP_CLIENT_ID=webapp_id
# The secret will be removed once we moved to PKCE. currently its in review
REACT_APP_CLIENT_SECRET=web_app_secret
REACT_APP_API=http://localhost:3000
5 changes: 4 additions & 1 deletion client-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@headlessui/react": "^2.1.0",
"@heroicons/react": "^2.1.4",
"@hookform/resolvers": "^3.9.0",
"@tailwindcss/forms": "^0.5.7",
"@tanstack/react-query": "^5.45.1",
"@testing-library/jest-dom": "^5.17.0",
Expand All @@ -21,8 +22,10 @@
"react-hook-form": "^7.52.0",
"react-router-dom": "^6.24.0",
"react-scripts": "5.0.1",
"react-toastify": "^10.0.5",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
"web-vitals": "^2.1.4",
"zod": "^3.23.8"
},
"scripts": {
"start": "react-scripts start",
Expand Down
65 changes: 8 additions & 57 deletions client-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,16 @@
import React from "react";
import logo from "./logo.svg";
import "./App.css";
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import Root from "./routes/root";
import ErrorPage from "./error-page";
import Tasks from "./presentation/pages/Tasks";
import Login from "./presentation/pages/Login";
import Signup from "./presentation/pages/Signup";
import { AuthProvider } from "./AuthContext";
import ProtectedRoute from "./ProtectedRoute";

const router = createBrowserRouter([
{
path: "/",
element: <Root />,
errorElement: <ErrorPage />,
children: [
{
path: "/",
element: (
<ProtectedRoute>
<Tasks />
</ProtectedRoute>
),
},
{
path: "login",
element: <Login />,
},
{
path: "signup",
element: <Signup />,
},
],
},
]);

const queryClient = new QueryClient();
import { RouterProvider } from "react-router-dom";
import { QueryClientProvider } from "@tanstack/react-query";
import { AuthProvider } from "./application/providers/AuthProvider";
import { ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import router from "./routes";
import queryClient from "./query-client";

function App() {
// return (
// <div className="App">
// <header className="App-header">
// <img src={logo} className="App-logo" alt="logo" />
// <p>
// Edit <code>src/App.tsx</code> and save to reload.
// </p>
// <a
// className="App-link"
// href="https://reactjs.org"
// target="_blank"
// rel="noopener noreferrer"
// >
// Learn React
// </a>
// </header>
// </div>
// );
return (
<>
<ToastContainer />
<QueryClientProvider client={queryClient}>
<AuthProvider>
<RouterProvider router={router} />
Expand Down
124 changes: 0 additions & 124 deletions client-app/src/AuthContext.jsx

This file was deleted.

24 changes: 0 additions & 24 deletions client-app/src/AuthStatus.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion client-app/src/application/hooks/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { AuthContext } from "../../AuthContext";
import { AuthContext } from "../providers/AuthProvider";

export function useAuth() {
return React.useContext(AuthContext);
Expand Down
31 changes: 0 additions & 31 deletions client-app/src/application/hooks/useCreateUser.ts

This file was deleted.

51 changes: 0 additions & 51 deletions client-app/src/application/hooks/useLoginUser.ts

This file was deleted.

Loading

0 comments on commit e5aa551

Please sign in to comment.