From bba5f46aa467220af65a34b81f4bb77e077927ad Mon Sep 17 00:00:00 2001 From: Hossein Rahmani Date: Tue, 30 Apr 2024 16:47:47 +0330 Subject: [PATCH] api instance created + Toaster added --- .env | 0 app/layout.tsx | 6 ++- app/page.tsx | 108 +-------------------------------------- components/ui/sonner.tsx | 31 +++++++++++ constants/index.ts | 0 lib/api/Authenticate.ts | 0 lib/api/apiInstance.ts | 19 +++++++ package-lock.json | 20 ++++++++ package.json | 2 + tailwind.config.ts | 18 ++++--- 10 files changed, 88 insertions(+), 116 deletions(-) create mode 100644 .env create mode 100644 components/ui/sonner.tsx create mode 100644 constants/index.ts create mode 100644 lib/api/Authenticate.ts diff --git a/.env b/.env new file mode 100644 index 0000000..e69de29 diff --git a/app/layout.tsx b/app/layout.tsx index 2f0f1c9..dd96ff5 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -2,6 +2,7 @@ import type { Metadata } from "next"; import { Inter } from "next/font/google"; import "./globals.css"; import Provider from "../lib/ReactQuery/Provider"; +import { Toaster } from "@/components/ui/sonner"; const inter = Inter({ subsets: ["latin"] }); @@ -18,7 +19,10 @@ export default function RootLayout({ return ( - {children} + +
{children}
+
+ ); diff --git a/app/page.tsx b/app/page.tsx index 5705d4e..af61af6 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -2,112 +2,6 @@ import Image from "next/image"; export default function Home() { return ( -
-
-

- Get started by editing  - app/page.tsx -

-
- - By{" "} - Vercel Logo - -
-
- -
- Next.js Logo -
- -
- -

- Docs{" "} - - -> - -

-

- Find in-depth information about Next.js features and API. -

-
- - -

- Learn{" "} - - -> - -

-

- Learn about Next.js in an interactive course with quizzes! -

-
- - -

- Templates{" "} - - -> - -

-

- Explore starter templates for Next.js. -

-
- - -

- Deploy{" "} - - -> - -

-

- Instantly deploy your Next.js site to a shareable URL with Vercel. -

-
-
-
+
); } diff --git a/components/ui/sonner.tsx b/components/ui/sonner.tsx new file mode 100644 index 0000000..452f4d9 --- /dev/null +++ b/components/ui/sonner.tsx @@ -0,0 +1,31 @@ +"use client" + +import { useTheme } from "next-themes" +import { Toaster as Sonner } from "sonner" + +type ToasterProps = React.ComponentProps + +const Toaster = ({ ...props }: ToasterProps) => { + const { theme = "system" } = useTheme() + + return ( + + ) +} + +export { Toaster } diff --git a/constants/index.ts b/constants/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/lib/api/Authenticate.ts b/lib/api/Authenticate.ts new file mode 100644 index 0000000..e69de29 diff --git a/lib/api/apiInstance.ts b/lib/api/apiInstance.ts index a90bc75..7028c1f 100644 --- a/lib/api/apiInstance.ts +++ b/lib/api/apiInstance.ts @@ -1,5 +1,24 @@ import axios from "axios"; +import { toast } from "sonner"; const api = axios.create({ baseURL: "https://shahrbinapi.shetabdahi.ir/" }); +api.interceptors.response.use( + function (response) { + console.log(response); + console.log(response.data?.data); + if (response.status == 200 || response.status == 201) { + if (response.data?.message) { + toast.success(response.data?.message); + } + } + return response; + }, + function (error) { + console.log(error); + toast.error("مشکلی پیش آمد."); + return Promise.reject(error); + } +); + export default api; diff --git a/package-lock.json b/package-lock.json index 70aaf64..449d94f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,8 +15,10 @@ "clsx": "^2.1.1", "lucide-react": "^0.376.0", "next": "14.2.3", + "next-themes": "^0.3.0", "react": "^18", "react-dom": "^18", + "sonner": "^1.4.41", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7" }, @@ -3271,6 +3273,15 @@ } } }, + "node_modules/next-themes": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.3.0.tgz", + "integrity": "sha512-/QHIrsYpd6Kfk7xakK4svpDI5mmXP0gfvCoJdGpZQ2TOrQZmsW0QxjaiLn8wbIKjtm4BTSqLoix4lxYYOnLJ/w==", + "peerDependencies": { + "react": "^16.8 || ^17 || ^18", + "react-dom": "^16.8 || ^17 || ^18" + } + }, "node_modules/next/node_modules/postcss": { "version": "8.4.31", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", @@ -4147,6 +4158,15 @@ "node": ">=8" } }, + "node_modules/sonner": { + "version": "1.4.41", + "resolved": "https://registry.npmjs.org/sonner/-/sonner-1.4.41.tgz", + "integrity": "sha512-uG511ggnnsw6gcn/X+YKkWPo5ep9il9wYi3QJxHsYe7yTZ4+cOd1wuodOUmOpFuXL+/RE3R04LczdNCDygTDgQ==", + "peerDependencies": { + "react": "^18.0.0", + "react-dom": "^18.0.0" + } + }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", diff --git a/package.json b/package.json index 2c851e4..4f2297d 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,10 @@ "clsx": "^2.1.1", "lucide-react": "^0.376.0", "next": "14.2.3", + "next-themes": "^0.3.0", "react": "^18", "react-dom": "^18", + "sonner": "^1.4.41", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7" }, diff --git a/tailwind.config.ts b/tailwind.config.ts index 84287e8..6df0ff8 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -1,13 +1,13 @@ -import type { Config } from "tailwindcss" +import type { Config } from "tailwindcss"; const config = { darkMode: ["class"], content: [ - './pages/**/*.{ts,tsx}', - './components/**/*.{ts,tsx}', - './app/**/*.{ts,tsx}', - './src/**/*.{ts,tsx}', - ], + "./pages/**/*.{ts,tsx}", + "./components/**/*.{ts,tsx}", + "./app/**/*.{ts,tsx}", + "./src/**/*.{ts,tsx}", + ], prefix: "", theme: { container: { @@ -19,6 +19,8 @@ const config = { }, extend: { colors: { + mainBlue: "#144887", + mainYellow: "#ffcd08", border: "hsl(var(--border))", input: "hsl(var(--input))", ring: "hsl(var(--ring))", @@ -75,6 +77,6 @@ const config = { }, }, plugins: [require("tailwindcss-animate")], -} satisfies Config +} satisfies Config; -export default config \ No newline at end of file +export default config;