From 19ef22422ffeaffeadec9d53785241c04bae3d87 Mon Sep 17 00:00:00 2001 From: walt-it Date: Sat, 5 Oct 2024 18:33:31 -0300 Subject: [PATCH 1/4] feat: move files to services folder --- src/main.tsx | 15 ++++++++------ src/providers/Providers.tsx | 13 ------------ src/providers/index.ts | 1 - src/router/router.tsx | 16 --------------- src/{ => services}/api/api.types.ts | 0 src/{ => services}/api/axios.ts | 0 .../api/handleAxiosFieldErrors.ts | 0 src/{ => services}/api/index.ts | 0 .../api/interceptors/authHeader.ts | 0 .../interceptors/errorResponseInterceptors.ts | 0 src/{ => services}/api/interceptors/index.ts | 0 .../api/interceptors/refreshToken.ts | 0 .../monitoring/SentryInit.ts} | 0 .../monitoring}/SentryProvider.tsx | 0 src/services/monitoring/index.ts | 1 + .../query}/ReactQueryProvider.tsx | 0 src/services/query/index.ts | 1 + .../RouterWrapper/RouterWrapper.tsx | 0 .../router/components/RouterWrapper/index.ts | 0 src/{ => services}/router/components/index.ts | 0 src/{ => services}/router/constants/index.ts | 0 src/{ => services}/router/constants/routes.ts | 0 src/{ => services}/router/index.ts | 0 .../router/layouts/MainLayout/MainLayout.tsx | 0 .../router/layouts/MainLayout/index.ts | 0 src/{ => services}/router/layouts/index.ts | 0 src/services/router/router.tsx | 12 +++++++++++ src/{ => services}/router/types/index.ts | 0 src/{ => services}/stores/index.ts | 0 src/{ => services}/stores/useAuthStore.ts | 0 src/{ => services}/stores/useExampleStore.ts | 0 tsconfig.json | 5 +++++ vite.config.ts | 20 +++++++++++++++++++ 33 files changed, 48 insertions(+), 36 deletions(-) delete mode 100644 src/providers/Providers.tsx delete mode 100644 src/providers/index.ts delete mode 100644 src/router/router.tsx rename src/{ => services}/api/api.types.ts (100%) rename src/{ => services}/api/axios.ts (100%) rename src/{ => services}/api/handleAxiosFieldErrors.ts (100%) rename src/{ => services}/api/index.ts (100%) rename src/{ => services}/api/interceptors/authHeader.ts (100%) rename src/{ => services}/api/interceptors/errorResponseInterceptors.ts (100%) rename src/{ => services}/api/interceptors/index.ts (100%) rename src/{ => services}/api/interceptors/refreshToken.ts (100%) rename src/{providers/sentry/sentry.ts => services/monitoring/SentryInit.ts} (100%) rename src/{providers/sentry => services/monitoring}/SentryProvider.tsx (100%) create mode 100644 src/services/monitoring/index.ts rename src/{providers => services/query}/ReactQueryProvider.tsx (100%) create mode 100644 src/services/query/index.ts rename src/{ => services}/router/components/RouterWrapper/RouterWrapper.tsx (100%) rename src/{ => services}/router/components/RouterWrapper/index.ts (100%) rename src/{ => services}/router/components/index.ts (100%) rename src/{ => services}/router/constants/index.ts (100%) rename src/{ => services}/router/constants/routes.ts (100%) rename src/{ => services}/router/index.ts (100%) rename src/{ => services}/router/layouts/MainLayout/MainLayout.tsx (100%) rename src/{ => services}/router/layouts/MainLayout/index.ts (100%) rename src/{ => services}/router/layouts/index.ts (100%) create mode 100644 src/services/router/router.tsx rename src/{ => services}/router/types/index.ts (100%) rename src/{ => services}/stores/index.ts (100%) rename src/{ => services}/stores/useAuthStore.ts (100%) rename src/{ => services}/stores/useExampleStore.ts (100%) diff --git a/src/main.tsx b/src/main.tsx index a5c905e..d6f9e57 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,12 +1,13 @@ -import "~/config/providers/scripts/sentry"; +import "~/services/monitoring/SentryInit"; import React, { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import "./index.css"; -import { Providers } from "./providers"; -import { Router } from "./router"; +import { SentryProvider } from "~/services/monitoring"; +import { ReactQueryProvider } from "~/services/query"; +import { Router } from "~/services/router"; const root = document.getElementById("root"); @@ -18,8 +19,10 @@ if (!root) { createRoot(root).render( - - - + + + + + , ); diff --git a/src/providers/Providers.tsx b/src/providers/Providers.tsx deleted file mode 100644 index ed683a8..0000000 --- a/src/providers/Providers.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import type { PropsWithChildren } from "react"; -import React from "react"; - -import { ReactQueryProvider } from "./ReactQueryProvider"; -import { SentryProvider } from "./sentry/SentryProvider"; - -export const Providers = ({ children }: PropsWithChildren) => { - return ( - - {children} - - ); -}; diff --git a/src/providers/index.ts b/src/providers/index.ts deleted file mode 100644 index 5dfd111..0000000 --- a/src/providers/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./Providers"; diff --git a/src/router/router.tsx b/src/router/router.tsx deleted file mode 100644 index e335e3d..0000000 --- a/src/router/router.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from "react"; -import { BrowserRouter, Route, Routes } from "react-router-dom"; - -import { GuestRouter } from "~/domains"; -import { NotFound } from "~/sections"; - -export const Router = () => { - return ( - - - - } /> - - - ); -}; diff --git a/src/api/api.types.ts b/src/services/api/api.types.ts similarity index 100% rename from src/api/api.types.ts rename to src/services/api/api.types.ts diff --git a/src/api/axios.ts b/src/services/api/axios.ts similarity index 100% rename from src/api/axios.ts rename to src/services/api/axios.ts diff --git a/src/api/handleAxiosFieldErrors.ts b/src/services/api/handleAxiosFieldErrors.ts similarity index 100% rename from src/api/handleAxiosFieldErrors.ts rename to src/services/api/handleAxiosFieldErrors.ts diff --git a/src/api/index.ts b/src/services/api/index.ts similarity index 100% rename from src/api/index.ts rename to src/services/api/index.ts diff --git a/src/api/interceptors/authHeader.ts b/src/services/api/interceptors/authHeader.ts similarity index 100% rename from src/api/interceptors/authHeader.ts rename to src/services/api/interceptors/authHeader.ts diff --git a/src/api/interceptors/errorResponseInterceptors.ts b/src/services/api/interceptors/errorResponseInterceptors.ts similarity index 100% rename from src/api/interceptors/errorResponseInterceptors.ts rename to src/services/api/interceptors/errorResponseInterceptors.ts diff --git a/src/api/interceptors/index.ts b/src/services/api/interceptors/index.ts similarity index 100% rename from src/api/interceptors/index.ts rename to src/services/api/interceptors/index.ts diff --git a/src/api/interceptors/refreshToken.ts b/src/services/api/interceptors/refreshToken.ts similarity index 100% rename from src/api/interceptors/refreshToken.ts rename to src/services/api/interceptors/refreshToken.ts diff --git a/src/providers/sentry/sentry.ts b/src/services/monitoring/SentryInit.ts similarity index 100% rename from src/providers/sentry/sentry.ts rename to src/services/monitoring/SentryInit.ts diff --git a/src/providers/sentry/SentryProvider.tsx b/src/services/monitoring/SentryProvider.tsx similarity index 100% rename from src/providers/sentry/SentryProvider.tsx rename to src/services/monitoring/SentryProvider.tsx diff --git a/src/services/monitoring/index.ts b/src/services/monitoring/index.ts new file mode 100644 index 0000000..d9fc189 --- /dev/null +++ b/src/services/monitoring/index.ts @@ -0,0 +1 @@ +export * from "./SentryProvider"; diff --git a/src/providers/ReactQueryProvider.tsx b/src/services/query/ReactQueryProvider.tsx similarity index 100% rename from src/providers/ReactQueryProvider.tsx rename to src/services/query/ReactQueryProvider.tsx diff --git a/src/services/query/index.ts b/src/services/query/index.ts new file mode 100644 index 0000000..5e9a785 --- /dev/null +++ b/src/services/query/index.ts @@ -0,0 +1 @@ +export * from "./ReactQueryProvider"; diff --git a/src/router/components/RouterWrapper/RouterWrapper.tsx b/src/services/router/components/RouterWrapper/RouterWrapper.tsx similarity index 100% rename from src/router/components/RouterWrapper/RouterWrapper.tsx rename to src/services/router/components/RouterWrapper/RouterWrapper.tsx diff --git a/src/router/components/RouterWrapper/index.ts b/src/services/router/components/RouterWrapper/index.ts similarity index 100% rename from src/router/components/RouterWrapper/index.ts rename to src/services/router/components/RouterWrapper/index.ts diff --git a/src/router/components/index.ts b/src/services/router/components/index.ts similarity index 100% rename from src/router/components/index.ts rename to src/services/router/components/index.ts diff --git a/src/router/constants/index.ts b/src/services/router/constants/index.ts similarity index 100% rename from src/router/constants/index.ts rename to src/services/router/constants/index.ts diff --git a/src/router/constants/routes.ts b/src/services/router/constants/routes.ts similarity index 100% rename from src/router/constants/routes.ts rename to src/services/router/constants/routes.ts diff --git a/src/router/index.ts b/src/services/router/index.ts similarity index 100% rename from src/router/index.ts rename to src/services/router/index.ts diff --git a/src/router/layouts/MainLayout/MainLayout.tsx b/src/services/router/layouts/MainLayout/MainLayout.tsx similarity index 100% rename from src/router/layouts/MainLayout/MainLayout.tsx rename to src/services/router/layouts/MainLayout/MainLayout.tsx diff --git a/src/router/layouts/MainLayout/index.ts b/src/services/router/layouts/MainLayout/index.ts similarity index 100% rename from src/router/layouts/MainLayout/index.ts rename to src/services/router/layouts/MainLayout/index.ts diff --git a/src/router/layouts/index.ts b/src/services/router/layouts/index.ts similarity index 100% rename from src/router/layouts/index.ts rename to src/services/router/layouts/index.ts diff --git a/src/services/router/router.tsx b/src/services/router/router.tsx new file mode 100644 index 0000000..a26f5eb --- /dev/null +++ b/src/services/router/router.tsx @@ -0,0 +1,12 @@ +import React from "react"; +import { BrowserRouter } from "react-router-dom"; + +import { GuestRouter } from "~/domains"; + +export const Router = () => { + return ( + + + + ); +}; diff --git a/src/router/types/index.ts b/src/services/router/types/index.ts similarity index 100% rename from src/router/types/index.ts rename to src/services/router/types/index.ts diff --git a/src/stores/index.ts b/src/services/stores/index.ts similarity index 100% rename from src/stores/index.ts rename to src/services/stores/index.ts diff --git a/src/stores/useAuthStore.ts b/src/services/stores/useAuthStore.ts similarity index 100% rename from src/stores/useAuthStore.ts rename to src/services/stores/useAuthStore.ts diff --git a/src/stores/useExampleStore.ts b/src/services/stores/useExampleStore.ts similarity index 100% rename from src/stores/useExampleStore.ts rename to src/services/stores/useExampleStore.ts diff --git a/tsconfig.json b/tsconfig.json index fa56153..877d5b2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,11 @@ "~/icons": ["./shared/components/icons"], "~/sections": ["./shared/sections"], "~/utils": ["./shared/utils"], + "~/api": ["./services/api"], + "~/monitoring": ["./services/monitoring"], + "~/query": ["./services/query"], + "~/router": ["./services/router"], + "~/stores": ["./services/stores"], "~/*": ["*"] }, diff --git a/vite.config.ts b/vite.config.ts index c4938e2..1aa6f52 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -59,6 +59,26 @@ const config = ({ mode }: ConfigEnv): UserConfigExport => { find: "~/utils", replacement: path.resolve(__dirname, "./src/shared/utils"), }, + { + find: "~/api", + replacement: path.resolve(__dirname, "./src/services/api"), + }, + { + find: "~/monitoring", + replacement: path.resolve(__dirname, "./src/services/monitoring"), + }, + { + find: "~/query", + replacement: path.resolve(__dirname, "./src/services/query"), + }, + { + find: "~/router", + replacement: path.resolve(__dirname, "./src/services/router"), + }, + { + find: "~/stores", + replacement: path.resolve(__dirname, "./src/services/stores"), + }, { find: "~", replacement: path.resolve(__dirname, "./src") }, ], }, From d9fdfd0545da0b4e084663dd74c7241f9fcbabb5 Mon Sep 17 00:00:00 2001 From: walt-it Date: Sat, 5 Oct 2024 23:41:53 -0300 Subject: [PATCH 2/4] feat: flatten router structure --- src/services/router/{layouts/MainLayout => }/MainLayout.tsx | 0 .../router/{components/RouterWrapper => }/RouterWrapper.tsx | 0 src/services/router/components/RouterWrapper/index.ts | 1 - src/services/router/components/index.ts | 1 - src/services/router/constants/index.ts | 1 - src/services/router/index.ts | 6 +++--- src/services/router/layouts/MainLayout/index.ts | 1 - src/services/router/layouts/index.ts | 1 - src/services/router/{constants => }/routes.ts | 0 src/services/router/{types/index.ts => types.ts} | 0 10 files changed, 3 insertions(+), 8 deletions(-) rename src/services/router/{layouts/MainLayout => }/MainLayout.tsx (100%) rename src/services/router/{components/RouterWrapper => }/RouterWrapper.tsx (100%) delete mode 100644 src/services/router/components/RouterWrapper/index.ts delete mode 100644 src/services/router/components/index.ts delete mode 100644 src/services/router/constants/index.ts delete mode 100644 src/services/router/layouts/MainLayout/index.ts delete mode 100644 src/services/router/layouts/index.ts rename src/services/router/{constants => }/routes.ts (100%) rename src/services/router/{types/index.ts => types.ts} (100%) diff --git a/src/services/router/layouts/MainLayout/MainLayout.tsx b/src/services/router/MainLayout.tsx similarity index 100% rename from src/services/router/layouts/MainLayout/MainLayout.tsx rename to src/services/router/MainLayout.tsx diff --git a/src/services/router/components/RouterWrapper/RouterWrapper.tsx b/src/services/router/RouterWrapper.tsx similarity index 100% rename from src/services/router/components/RouterWrapper/RouterWrapper.tsx rename to src/services/router/RouterWrapper.tsx diff --git a/src/services/router/components/RouterWrapper/index.ts b/src/services/router/components/RouterWrapper/index.ts deleted file mode 100644 index 58dd800..0000000 --- a/src/services/router/components/RouterWrapper/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./RouterWrapper"; diff --git a/src/services/router/components/index.ts b/src/services/router/components/index.ts deleted file mode 100644 index 58dd800..0000000 --- a/src/services/router/components/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./RouterWrapper"; diff --git a/src/services/router/constants/index.ts b/src/services/router/constants/index.ts deleted file mode 100644 index 9bf9b1b..0000000 --- a/src/services/router/constants/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./routes"; diff --git a/src/services/router/index.ts b/src/services/router/index.ts index b6b4eeb..18a0067 100644 --- a/src/services/router/index.ts +++ b/src/services/router/index.ts @@ -1,5 +1,5 @@ export * from "./router"; -export * from "./components"; -export * from "./constants"; -export * from "./layouts"; +export * from "./MainLayout"; +export * from "./RouterWrapper"; +export * from "./routes"; export * from "./types"; diff --git a/src/services/router/layouts/MainLayout/index.ts b/src/services/router/layouts/MainLayout/index.ts deleted file mode 100644 index 1268cf9..0000000 --- a/src/services/router/layouts/MainLayout/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./MainLayout"; diff --git a/src/services/router/layouts/index.ts b/src/services/router/layouts/index.ts deleted file mode 100644 index 1268cf9..0000000 --- a/src/services/router/layouts/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./MainLayout"; diff --git a/src/services/router/constants/routes.ts b/src/services/router/routes.ts similarity index 100% rename from src/services/router/constants/routes.ts rename to src/services/router/routes.ts diff --git a/src/services/router/types/index.ts b/src/services/router/types.ts similarity index 100% rename from src/services/router/types/index.ts rename to src/services/router/types.ts From f6b687cb68a460766b86b8d3bad1abf379e47a1a Mon Sep 17 00:00:00 2001 From: walt-it Date: Sat, 5 Oct 2024 23:44:46 -0300 Subject: [PATCH 3/4] feat: change name to sentry --- src/main.tsx | 4 ++-- src/services/{monitoring => sentry}/SentryInit.ts | 0 src/services/{monitoring => sentry}/SentryProvider.tsx | 0 src/services/{monitoring => sentry}/index.ts | 0 tsconfig.json | 2 +- vite.config.ts | 4 ++-- 6 files changed, 5 insertions(+), 5 deletions(-) rename src/services/{monitoring => sentry}/SentryInit.ts (100%) rename src/services/{monitoring => sentry}/SentryProvider.tsx (100%) rename src/services/{monitoring => sentry}/index.ts (100%) diff --git a/src/main.tsx b/src/main.tsx index d6f9e57..735d526 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,13 +1,13 @@ -import "~/services/monitoring/SentryInit"; +import "~/services/sentry/SentryInit"; import React, { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import "./index.css"; -import { SentryProvider } from "~/services/monitoring"; import { ReactQueryProvider } from "~/services/query"; import { Router } from "~/services/router"; +import { SentryProvider } from "~/services/sentry"; const root = document.getElementById("root"); diff --git a/src/services/monitoring/SentryInit.ts b/src/services/sentry/SentryInit.ts similarity index 100% rename from src/services/monitoring/SentryInit.ts rename to src/services/sentry/SentryInit.ts diff --git a/src/services/monitoring/SentryProvider.tsx b/src/services/sentry/SentryProvider.tsx similarity index 100% rename from src/services/monitoring/SentryProvider.tsx rename to src/services/sentry/SentryProvider.tsx diff --git a/src/services/monitoring/index.ts b/src/services/sentry/index.ts similarity index 100% rename from src/services/monitoring/index.ts rename to src/services/sentry/index.ts diff --git a/tsconfig.json b/tsconfig.json index 877d5b2..2ddf001 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,7 @@ "~/sections": ["./shared/sections"], "~/utils": ["./shared/utils"], "~/api": ["./services/api"], - "~/monitoring": ["./services/monitoring"], + "~/sentry": ["./services/sentry"], "~/query": ["./services/query"], "~/router": ["./services/router"], "~/stores": ["./services/stores"], diff --git a/vite.config.ts b/vite.config.ts index 1aa6f52..5906ee4 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -64,8 +64,8 @@ const config = ({ mode }: ConfigEnv): UserConfigExport => { replacement: path.resolve(__dirname, "./src/services/api"), }, { - find: "~/monitoring", - replacement: path.resolve(__dirname, "./src/services/monitoring"), + find: "~/sentry", + replacement: path.resolve(__dirname, "./src/services/sentry"), }, { find: "~/query", From 7d45f987e32568e869a9ed1a478d4307bf6ef424 Mon Sep 17 00:00:00 2001 From: walt-it Date: Sat, 5 Oct 2024 23:51:54 -0300 Subject: [PATCH 4/4] feat: move env to config --- src/{ => config}/env.ts | 2 ++ src/config/index.ts | 5 +---- src/services/api/axios.ts | 2 +- src/services/sentry/SentryInit.ts | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) rename src/{ => config}/env.ts (96%) diff --git a/src/env.ts b/src/config/env.ts similarity index 96% rename from src/env.ts rename to src/config/env.ts index f894693..cab8955 100644 --- a/src/env.ts +++ b/src/config/env.ts @@ -47,3 +47,5 @@ function checkEnv() { } export const env = checkEnv(); + +export const isLocal = env.VITE_APP_ENV === "local"; diff --git a/src/config/index.ts b/src/config/index.ts index 6af149a..562743a 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,6 +1,3 @@ -import { env } from "~/env"; - -export const isLocal = env.VITE_APP_ENV === "local"; - export * from "./common"; +export * from "./env"; export * from "./storybook"; diff --git a/src/services/api/axios.ts b/src/services/api/axios.ts index c849f2b..ee4f727 100644 --- a/src/services/api/axios.ts +++ b/src/services/api/axios.ts @@ -1,6 +1,6 @@ import axios from "axios"; -import { env } from "~/env"; +import { env } from "~/config"; import { authHeaderInterceptor, errorResponseInterceptor, diff --git a/src/services/sentry/SentryInit.ts b/src/services/sentry/SentryInit.ts index 87ff5f9..6a47da6 100644 --- a/src/services/sentry/SentryInit.ts +++ b/src/services/sentry/SentryInit.ts @@ -1,7 +1,6 @@ import * as Sentry from "@sentry/react"; -import { isLocal } from "~/config"; -import { env } from "~/env"; +import { env, isLocal } from "~/config"; if (!isLocal) { Sentry.init({