react-groundwork 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.env.example +6 -0
  2. package/.gitattributes +2 -0
  3. package/.prettierignore +7 -0
  4. package/.prettierrc.json +12 -0
  5. package/README.md +24 -2
  6. package/cli/index.js +119 -0
  7. package/components.json +25 -0
  8. package/eslint.config.js +17 -0
  9. package/index.html +13 -0
  10. package/jsconfig.json +8 -0
  11. package/package.json +111 -4
  12. package/public/.htaccess +11 -0
  13. package/public/logo.png +0 -0
  14. package/src/App.jsx +14 -0
  15. package/src/api/api.routes.js +12 -0
  16. package/src/api/api.services.js +8 -0
  17. package/src/api/apiCall.js +128 -0
  18. package/src/api/apiHelpers.js +20 -0
  19. package/src/assets/css/index.css +173 -0
  20. package/src/assets/images/placeholders/placeholder-170x166.png +0 -0
  21. package/src/assets/images/placeholders/placeholder-360x260.png +0 -0
  22. package/src/assets/images/placeholders/placeholder-372x225.png +0 -0
  23. package/src/assets/images/placeholders/placeholder-40x40.png +0 -0
  24. package/src/assets/images/placeholders/placeholder-451x392.png +0 -0
  25. package/src/components/common/AppChart.jsx +56 -0
  26. package/src/components/common/Breadcrumbs.jsx +90 -0
  27. package/src/components/common/DataTable.jsx +203 -0
  28. package/src/components/common/DatePicker.jsx +275 -0
  29. package/src/components/common/DialogComponent.jsx +308 -0
  30. package/src/components/common/ErrorStateComponent.jsx +46 -0
  31. package/src/components/common/FullscreenToggle.jsx +54 -0
  32. package/src/components/common/HeadingComponent.jsx +29 -0
  33. package/src/components/common/LoadingComponent.jsx +33 -0
  34. package/src/components/common/NetworkStatus.jsx +103 -0
  35. package/src/components/common/NoDataComponent.jsx +45 -0
  36. package/src/components/common/Pagination.jsx +128 -0
  37. package/src/components/common/ParagraphComponent.jsx +14 -0
  38. package/src/components/common/PhoneInputComponent.jsx +242 -0
  39. package/src/components/common/ReactSelect.jsx +145 -0
  40. package/src/components/common/SearchSelect.jsx +176 -0
  41. package/src/components/common/SeeMore.jsx +26 -0
  42. package/src/components/common/SortableHeader.jsx +23 -0
  43. package/src/components/common/theme-toggle.jsx +39 -0
  44. package/src/components/layout/AuthLayout.jsx +90 -0
  45. package/src/components/layout/PageLayout.jsx +32 -0
  46. package/src/components/layout/SidebarLayout.jsx +233 -0
  47. package/src/components/ui/avatar.jsx +84 -0
  48. package/src/components/ui/badge.jsx +43 -0
  49. package/src/components/ui/button.jsx +44 -0
  50. package/src/components/ui/card.jsx +69 -0
  51. package/src/components/ui/checkbox.jsx +25 -0
  52. package/src/components/ui/dialog.jsx +149 -0
  53. package/src/components/ui/empty.jsx +82 -0
  54. package/src/components/ui/input.jsx +19 -0
  55. package/src/components/ui/label.jsx +19 -0
  56. package/src/components/ui/select.jsx +156 -0
  57. package/src/components/ui/skeleton.jsx +7 -0
  58. package/src/components/ui/sonner.jsx +37 -0
  59. package/src/components/ui/switch.jsx +23 -0
  60. package/src/components/ui/table.jsx +74 -0
  61. package/src/components/ui/textarea.jsx +16 -0
  62. package/src/constants/constant.js +16 -0
  63. package/src/context/theme-provider.jsx +48 -0
  64. package/src/features/components/ComponentFormDialog.jsx +162 -0
  65. package/src/features/components/ComponentsTable.jsx +219 -0
  66. package/src/features/components/componentStyles.js +16 -0
  67. package/src/features/components/mockData.js +407 -0
  68. package/src/features/playground/BasicsSection.jsx +122 -0
  69. package/src/features/playground/DataSection.jsx +210 -0
  70. package/src/features/playground/DemoCard.jsx +21 -0
  71. package/src/features/playground/FeedbackSection.jsx +309 -0
  72. package/src/features/playground/FormsSection.jsx +188 -0
  73. package/src/features/playground/UtilitiesSection.jsx +200 -0
  74. package/src/hooks/useApiHandler.jsx +82 -0
  75. package/src/hooks/useDebounce.js +12 -0
  76. package/src/lib/utils.js +1 -0
  77. package/src/main.jsx +16 -0
  78. package/src/pages/auth/ForgotPasswordPage.jsx +101 -0
  79. package/src/pages/auth/LoginPage.jsx +120 -0
  80. package/src/pages/auth/SignupPage.jsx +135 -0
  81. package/src/pages/views/ComponentsPage.jsx +316 -0
  82. package/src/pages/views/DashboardPage.jsx +260 -0
  83. package/src/pages/views/LandingPage.jsx +772 -0
  84. package/src/pages/views/NotFoundPage.jsx +30 -0
  85. package/src/pages/views/PlaygroundPage.jsx +50 -0
  86. package/src/routes/AppRoutes.jsx +29 -0
  87. package/src/routes/ProtectedRoute.jsx +18 -0
  88. package/src/utils/exportCsv.js +17 -0
  89. package/src/utils/formatCurrency.js +19 -0
  90. package/src/utils/formatDateTime.js +34 -0
  91. package/src/utils/handleSessionExpire.js +22 -0
  92. package/src/utils/logger.js +34 -0
  93. package/vite.config.js +23 -0
package/.env.example ADDED
@@ -0,0 +1,6 @@
1
+ # App Setup
2
+ VITE_APP_NAME="React Project"
3
+ VITE_IS_PRODUCTION=false
4
+ # API Setup
5
+ VITE_BASE_URL=
6
+ VITE_API_SECRET=
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,7 @@
1
+ node_modules
2
+ dist
3
+ dist-ssr
4
+ package-lock.json
5
+ public
6
+ .env
7
+ .env.*
@@ -0,0 +1,12 @@
1
+ {
2
+ "printWidth": 120,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": false,
7
+ "jsxSingleQuote": false,
8
+ "trailingComma": "all",
9
+ "bracketSpacing": true,
10
+ "arrowParens": "always",
11
+ "endOfLine": "auto"
12
+ }
package/README.md CHANGED
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # React Starter Template
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A reusable React frontend foundation with routing, an API layer, a component kit and layouts already set up.
4
+
5
+ ## Tech stack
6
+
7
+ React 19 · Vite 8 · React Router 7 · Tailwind CSS 4 · shadcn/ui on Base UI · Axios · Chart.js · Framer Motion · Sonner
8
+
9
+ ## Getting started
10
+
11
+ Requires Node.js 20.19 or later.
12
+
13
+ ```bash
14
+ npx react-groundwork my-app
15
+ cd my-app
16
+ npm install
17
+ npm run dev # http://localhost:5000
18
+ ```
19
+
20
+ Set these in `.env`:
21
+
22
+ | Variable | Purpose |
23
+ | --------------- | ---------------------------- |
24
+ | `VITE_APP_NAME` | App name shown in the UI |
25
+ | `VITE_BASE_URL` | Base URL of your backend API |
package/cli/index.js ADDED
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
7
+ const DEFAULT_APP_NAME = "my-app";
8
+ const APP_VERSION = "0.1.0";
9
+ const NAME_PATTERN = /^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
10
+
11
+ const TEMPLATE_ENTRIES = [
12
+ "src",
13
+ "public",
14
+ "index.html",
15
+ "vite.config.js",
16
+ "eslint.config.js",
17
+ "jsconfig.json",
18
+ "components.json",
19
+ ".env.example",
20
+ ".prettierrc.json",
21
+ ".prettierignore",
22
+ ".gitattributes",
23
+ "README.md",
24
+ ];
25
+
26
+ const GITIGNORE = `logs
27
+ *.log
28
+ npm-debug.log*
29
+ yarn-debug.log*
30
+ yarn-error.log*
31
+ pnpm-debug.log*
32
+ lerna-debug.log*
33
+
34
+ node_modules
35
+ dist
36
+ dist-ssr
37
+ *.local
38
+
39
+ .vscode/*
40
+ !.vscode/extensions.json
41
+ .idea
42
+ .DS_Store
43
+ *.suo
44
+ *.ntvs*
45
+ *.njsproj
46
+ *.sln
47
+ *.sw?
48
+
49
+ .env
50
+ `;
51
+
52
+ const fail = (message) => {
53
+ console.error(`\n Error: ${message}\n`);
54
+ process.exit(1);
55
+ };
56
+
57
+ const readTemplatePackage = () => JSON.parse(readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf8"));
58
+
59
+ const splitDependencies = (allDependencies, runtimeNames) => {
60
+ const runtime = new Set(runtimeNames);
61
+ const entries = Object.entries(allDependencies);
62
+ return {
63
+ dependencies: Object.fromEntries(entries.filter(([name]) => runtime.has(name))),
64
+ devDependencies: Object.fromEntries(entries.filter(([name]) => !runtime.has(name))),
65
+ };
66
+ };
67
+
68
+ const buildAppPackage = (appName) => {
69
+ const { type, scripts, engines, devDependencies: allDependencies, appDependencies } = readTemplatePackage();
70
+ const { dependencies, devDependencies } = splitDependencies(allDependencies, appDependencies);
71
+ return { name: appName, private: true, version: APP_VERSION, type, engines, scripts, dependencies, devDependencies };
72
+ };
73
+
74
+ const ensureEmptyTarget = (targetDir) => {
75
+ if (!existsSync(targetDir)) {
76
+ mkdirSync(targetDir, { recursive: true });
77
+ return;
78
+ }
79
+ if (readdirSync(targetDir).length > 0) {
80
+ fail(`The folder "${path.basename(targetDir)}" already exists and is not empty.`);
81
+ }
82
+ };
83
+
84
+ const copyTemplate = (targetDir) => {
85
+ for (const entry of TEMPLATE_ENTRIES) {
86
+ const source = path.join(PACKAGE_ROOT, entry);
87
+ if (!existsSync(source)) fail(`Template file is missing from the package: ${entry}`);
88
+ cpSync(source, path.join(targetDir, entry), { recursive: true });
89
+ }
90
+ writeFileSync(path.join(targetDir, ".gitignore"), GITIGNORE);
91
+ cpSync(path.join(targetDir, ".env.example"), path.join(targetDir, ".env"));
92
+ };
93
+
94
+ const main = () => {
95
+ const input = (process.argv[2] ?? DEFAULT_APP_NAME).trim();
96
+ const targetDir = path.resolve(process.cwd(), input);
97
+ const appName = path.basename(targetDir).toLowerCase();
98
+
99
+ if (!NAME_PATTERN.test(appName)) {
100
+ fail(`"${appName}" is not a valid package name. Use lowercase letters, numbers and dashes.`);
101
+ }
102
+
103
+ ensureEmptyTarget(targetDir);
104
+ copyTemplate(targetDir);
105
+ writeFileSync(path.join(targetDir, "package.json"), `${JSON.stringify(buildAppPackage(appName), null, 2)}\n`);
106
+
107
+ const relative = path.relative(process.cwd(), targetDir) || ".";
108
+ console.log(`\n Created ${appName} in ${targetDir}\n`);
109
+ console.log(" Next steps:");
110
+ if (relative !== ".") console.log(` cd ${relative}`);
111
+ console.log(" npm install");
112
+ console.log(" npm run dev\n");
113
+ };
114
+
115
+ try {
116
+ main();
117
+ } catch (error) {
118
+ fail(error instanceof Error ? error.message : String(error));
119
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "base-nova",
4
+ "rsc": false,
5
+ "tsx": false,
6
+ "tailwind": {
7
+ "config": "",
8
+ "css": "src/assets/css/index.css",
9
+ "baseColor": "neutral",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "iconLibrary": "lucide",
14
+ "rtl": false,
15
+ "aliases": {
16
+ "components": "@/components",
17
+ "utils": "@/lib/utils",
18
+ "ui": "@/components/ui",
19
+ "lib": "@/lib",
20
+ "hooks": "@/hooks"
21
+ },
22
+ "menuColor": "default",
23
+ "menuAccent": "subtle",
24
+ "registries": {}
25
+ }
@@ -0,0 +1,17 @@
1
+ import js from "@eslint/js";
2
+ import globals from "globals";
3
+ import reactHooks from "eslint-plugin-react-hooks";
4
+ import reactRefresh from "eslint-plugin-react-refresh";
5
+ import { defineConfig, globalIgnores } from "eslint/config";
6
+
7
+ export default defineConfig([
8
+ globalIgnores(["dist", "cli"]),
9
+ {
10
+ files: ["**/*.{js,jsx}"],
11
+ extends: [js.configs.recommended, reactHooks.configs.flat.recommended, reactRefresh.configs.vite],
12
+ languageOptions: {
13
+ globals: globals.browser,
14
+ parserOptions: { ecmaFeatures: { jsx: true } },
15
+ },
16
+ },
17
+ ]);
package/index.html ADDED
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/png" href="/logo.png" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>React Starter Template</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.jsx"></script>
12
+ </body>
13
+ </html>
package/jsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "paths": {
5
+ "@/*": ["./src/*"]
6
+ }
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,6 +1,113 @@
1
1
  {
2
2
  "name": "react-groundwork",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "vite",
7
+ "build": "vite build",
8
+ "lint": "eslint .",
9
+ "preview": "vite preview",
10
+ "format": "prettier --write .",
11
+ "format:check": "prettier --check ."
12
+ },
13
+ "devDependencies": {
14
+ "@babel/core": "^7.29.7",
15
+ "@base-ui/react": "^1.8.0",
16
+ "@eslint/js": "^10.0.1",
17
+ "@fontsource-variable/geist": "^5.3.0",
18
+ "@gsap/react": "^2.1.2",
19
+ "@react-spring/web": "^10.1.2",
20
+ "@rolldown/plugin-babel": "^0.2.3",
21
+ "@tailwindcss/vite": "^4.3.3",
22
+ "@types/react": "^19.2.18",
23
+ "@types/react-dom": "^19.2.4",
24
+ "@vitejs/plugin-react": "^6.1.0",
25
+ "axios": "^1.20.0",
26
+ "babel-plugin-react-compiler": "^1.0.0",
27
+ "chart.js": "^4.5.1",
28
+ "class-variance-authority": "^0.7.1",
29
+ "cn": "^0.2.5",
30
+ "eslint": "^10.9.0",
31
+ "eslint-plugin-react-hooks": "^7.1.1",
32
+ "eslint-plugin-react-refresh": "^0.5.4",
33
+ "framer-motion": "^14.7.1",
34
+ "globals": "^17.11.0",
35
+ "gsap": "^3.15.1",
36
+ "libphonenumber-js": "^1.13.12",
37
+ "lucide-react": "^1.41.0",
38
+ "next-themes": "^0.4.6",
39
+ "prettier": "3.10.1",
40
+ "react": "^19.2.8",
41
+ "react-chartjs-2": "^5.3.1",
42
+ "react-dom": "^19.2.8",
43
+ "react-phone-number-input": "^3.4.18",
44
+ "react-router-dom": "^7.18.3",
45
+ "react-select": "^5.10.2",
46
+ "shadcn": "^4.21.0",
47
+ "sonner": "^2.0.8",
48
+ "tailwindcss": "^4.3.3",
49
+ "tw-animate-css": "^1.4.0",
50
+ "vite": "^8.2.2"
51
+ },
52
+ "appDependencies": [
53
+ "@base-ui/react",
54
+ "@fontsource-variable/geist",
55
+ "@gsap/react",
56
+ "@react-spring/web",
57
+ "@tailwindcss/vite",
58
+ "axios",
59
+ "chart.js",
60
+ "class-variance-authority",
61
+ "cn",
62
+ "framer-motion",
63
+ "gsap",
64
+ "libphonenumber-js",
65
+ "lucide-react",
66
+ "next-themes",
67
+ "react",
68
+ "react-chartjs-2",
69
+ "react-dom",
70
+ "react-phone-number-input",
71
+ "react-router-dom",
72
+ "react-select",
73
+ "shadcn",
74
+ "sonner",
75
+ "tailwindcss",
76
+ "tw-animate-css"
77
+ ],
78
+ "description": "React 19 + Vite starter with routing, an API layer, a component kit and layouts already set up.",
79
+ "bin": {
80
+ "react-groundwork": "cli/index.js"
81
+ },
82
+ "engines": {
83
+ "node": ">=20.19.0"
84
+ },
85
+ "repository": {
86
+ "type": "git",
87
+ "url": "git+https://github.com/ZainHanif29/react-groundwork.git"
88
+ },
89
+ "homepage": "https://github.com/ZainHanif29/react-groundwork#readme",
90
+ "files": [
91
+ "cli",
92
+ "src",
93
+ "public",
94
+ "index.html",
95
+ "vite.config.js",
96
+ "eslint.config.js",
97
+ "jsconfig.json",
98
+ "components.json",
99
+ ".env.example",
100
+ ".prettierrc.json",
101
+ ".prettierignore",
102
+ "README.md",
103
+ ".gitattributes"
104
+ ],
105
+ "keywords": [
106
+ "react",
107
+ "vite",
108
+ "template",
109
+ "starter",
110
+ "tailwindcss",
111
+ "shadcn"
112
+ ]
113
+ }
@@ -0,0 +1,11 @@
1
+ <IfModule mod_rewrite.c>
2
+
3
+ RewriteEngine On
4
+ RewriteBase /
5
+ RewriteRule ^index\.html$ - [L]
6
+ RewriteCond %{REQUEST_FILENAME} !-f
7
+ RewriteCond %{REQUEST_FILENAME} !-d
8
+ RewriteCond %{REQUEST_FILENAME} !-l
9
+ RewriteRule . /index.html [L]
10
+
11
+ </IfModule>
Binary file
package/src/App.jsx ADDED
@@ -0,0 +1,14 @@
1
+ import { BrowserRouter } from "react-router-dom";
2
+ import AppRoutes from "./routes/AppRoutes";
3
+ import NetworkStatus from "./components/common/NetworkStatus";
4
+
5
+ function App() {
6
+ return (
7
+ <BrowserRouter>
8
+ <AppRoutes />
9
+ <NetworkStatus />
10
+ </BrowserRouter>
11
+ );
12
+ }
13
+
14
+ export default App;
@@ -0,0 +1,12 @@
1
+ import { BASE_URL } from "@/constants/constant";
2
+
3
+ export const API_BASE_URLS = {
4
+ AUTH: `${BASE_URL}/api`,
5
+ };
6
+
7
+ export const API_ROUTES = {
8
+ AUTH_ROUTES: {
9
+ REGISTER: `${API_BASE_URLS.AUTH}/signup`,
10
+ LOGIN: `${API_BASE_URLS.AUTH}/login`,
11
+ },
12
+ };
@@ -0,0 +1,8 @@
1
+ import { apiCall } from "./apiCall";
2
+ import { API_ROUTES } from "./api.routes";
3
+
4
+ const { LOGIN, REGISTER } = API_ROUTES.AUTH_ROUTES;
5
+
6
+ export const loginApi = (data) => apiCall({ method: "POST", apiUrl: LOGIN, data });
7
+
8
+ export const registerApi = (data) => apiCall({ method: "POST", apiUrl: REGISTER, data });
@@ -0,0 +1,128 @@
1
+ import { getToken } from "@/constants/constant";
2
+ import axios from "axios";
3
+ import { toast } from "sonner";
4
+ import {
5
+ DEFAULT_ERROR_MESSAGE,
6
+ DEFAULT_TIMEOUT,
7
+ isRequestSuccessful,
8
+ NETWORK_ERROR_MESSAGE,
9
+ SESSION_EXPIRED_MESSAGE,
10
+ SUCCESS_MESSAGES,
11
+ TIMEOUT_ERROR_MESSAGE,
12
+ } from "./apiHelpers";
13
+ import { API_ROUTES } from "./api.routes";
14
+ import { handleSessionExpire } from "@/utils/handleSessionExpire";
15
+
16
+ const { LOGIN, REGISTER } = API_ROUTES.AUTH_ROUTES;
17
+ const PUBLIC_URL = [LOGIN, REGISTER];
18
+
19
+ export const apiCall = async ({
20
+ method,
21
+ apiUrl,
22
+ data = null,
23
+ params = null,
24
+ navigate = null,
25
+ isFormData = false,
26
+ showToast = true,
27
+ signal = null,
28
+ timeout = DEFAULT_TIMEOUT,
29
+ }) => {
30
+ const isPublicUrl = PUBLIC_URL.includes(apiUrl);
31
+
32
+ if (!isPublicUrl) {
33
+ if (!getToken()) {
34
+ handleSessionExpire({ navigate: navigate, showToast: true, message: SESSION_EXPIRED_MESSAGE });
35
+ throw SESSION_EXPIRED_MESSAGE;
36
+ }
37
+ }
38
+
39
+ const methodKey = method?.toLowerCase();
40
+ let response;
41
+
42
+ try {
43
+ const config = {
44
+ method: methodKey,
45
+ url: `${apiUrl}`,
46
+ headers: {
47
+ "Content-Type": isFormData ? "multipart/form-data" : "application/json",
48
+ },
49
+ timeout,
50
+ transitional: { clarifyTimeoutError: true },
51
+ };
52
+
53
+ if (signal) {
54
+ config.signal = signal;
55
+ }
56
+
57
+ if (getToken() && !isPublicUrl) {
58
+ config.headers.Authorization = `Bearer ${getToken()}`;
59
+ }
60
+
61
+ if (["post", "put", "patch", "delete"].includes(methodKey) && data) {
62
+ config.data = data;
63
+ }
64
+
65
+ if (methodKey === "get" && data) {
66
+ config.params = data;
67
+ }
68
+
69
+ if (params) {
70
+ config.params = { ...config.params, ...params };
71
+ }
72
+
73
+ response = await axios(config);
74
+ } catch (error) {
75
+ if (axios.isCancel(error)) {
76
+ throw error;
77
+ }
78
+
79
+ if (!axios.isAxiosError(error)) {
80
+ if (showToast) {
81
+ toast.error(DEFAULT_ERROR_MESSAGE);
82
+ }
83
+ throw error;
84
+ }
85
+
86
+ if (error.code === "ETIMEDOUT") {
87
+ if (showToast) {
88
+ toast.error(TIMEOUT_ERROR_MESSAGE);
89
+ }
90
+ throw TIMEOUT_ERROR_MESSAGE;
91
+ }
92
+
93
+ if (error.code === "ECONNABORTED") {
94
+ throw error.message || DEFAULT_ERROR_MESSAGE;
95
+ }
96
+
97
+ if (!error.response) {
98
+ if (showToast) {
99
+ toast.error(NETWORK_ERROR_MESSAGE);
100
+ }
101
+ throw NETWORK_ERROR_MESSAGE;
102
+ }
103
+
104
+ if (error.response.status === 401 && !isPublicUrl) {
105
+ handleSessionExpire({ navigate: navigate, showToast: true, message: error.response?.data?.message });
106
+ throw error.response?.data?.message || SESSION_EXPIRED_MESSAGE;
107
+ }
108
+ if (showToast) {
109
+ toast.error(error.response?.data?.message || DEFAULT_ERROR_MESSAGE);
110
+ }
111
+ throw error.response?.data?.message || DEFAULT_ERROR_MESSAGE;
112
+ }
113
+
114
+ const success = isRequestSuccessful(response?.data);
115
+
116
+ if (!success) {
117
+ if (showToast) {
118
+ toast.error(response?.data?.message || DEFAULT_ERROR_MESSAGE);
119
+ }
120
+ throw response?.data?.message || DEFAULT_ERROR_MESSAGE;
121
+ }
122
+
123
+ if (showToast) {
124
+ toast.success(response?.data?.message || SUCCESS_MESSAGES[methodKey] || "Success");
125
+ }
126
+
127
+ return response.data;
128
+ };
@@ -0,0 +1,20 @@
1
+ export const DEFAULT_TIMEOUT = 30000;
2
+
3
+ export const SESSION_EXPIRED_MESSAGE = "Your session has expired. Please log in again.";
4
+ export const NETWORK_ERROR_MESSAGE = "Network error. Check your internet connection and try again.";
5
+ export const TIMEOUT_ERROR_MESSAGE = "The request timed out. Please try again.";
6
+ export const DEFAULT_ERROR_MESSAGE = "Something went wrong. Please try again.";
7
+
8
+ export const SUCCESS_MESSAGES = {
9
+ get: "Data fetched successfully",
10
+ post: "Data created successfully",
11
+ put: "Data updated successfully",
12
+ delete: "Data deleted successfully",
13
+ };
14
+
15
+ export const isRequestSuccessful = (responseData) => {
16
+ const successValues = [true, "true"];
17
+ const statusValues = [true, "true"];
18
+
19
+ return successValues.includes(responseData?.success) || statusValues.includes(responseData?.status);
20
+ };