From eeb9cc7ff81ea14e1f98697a77bb22b30f9d3d18 Mon Sep 17 00:00:00 2001 From: Alibek Date: Fri, 2 Feb 2024 17:35:09 +0600 Subject: [PATCH] . --- .env | 2 + app/api/auth/[...nextauth]/route.ts | 91 ++++++++++++ app/create-report/page.tsx | 3 + app/profile/layout.tsx | 3 + app/profile/my-reports/page.tsx | 3 + app/profile/page.tsx | 7 - app/profile/personal-data/page.tsx | 3 + app/report/[id]/page.tsx | 3 + lib/next-auth.d.ts | 18 +++ package.json | 7 +- src/App/App.tsx | 9 +- src/App/Providers.tsx | 11 ++ src/Entities/NavAuthBtn/NavAuthBtn.tsx | 9 +- src/Entities/NewsCard/NewsCard.scss | 6 +- src/Entities/NewsCard/NewsCard.tsx | 9 +- src/Entities/ReviewCard/ReviewCard.scss | 8 + src/Entities/RoadType/RoadType.scss | 8 + src/Entities/RoadType/RoadType.tsx | 19 +++ src/Entities/Switch/Switch.tsx | 40 ++++- .../CreateReportMap/CreateReportMap.scss | 31 ++++ .../CreateReportMap/CreateReportMap.tsx | 80 ++++++++++ src/Features/CreateReportMap/assets/pin.svg | 5 + src/Features/CreateReview/CreateReview.scss | 16 ++ src/Features/HomeMap/HomeMap.scss | 44 ++++++ src/Features/HomeMap/HomeMap.tsx | 98 ++++++++++++ src/Features/HomeMap/icons/geo-green.svg | 5 + src/Features/HomeMap/icons/geo-orange.svg | 5 + src/Features/HomeMap/icons/geo-pink.svg | 5 + src/Features/HomeMap/icons/geo-purple.svg | 5 + src/Features/HomeMap/icons/geo-red.svg | 5 + src/Features/HomeMap/icons/geo-yellow.svg | 5 + src/Features/ReportLike/ReportLike.scss | 10 ++ src/Features/ReportLike/ReportLike.tsx | 22 +++ src/Features/ReportLike/icons/like-icon.svg | 5 + src/Features/SearchBar/SearchBar.tsx | 11 +- src/Features/SignInForm/SignInForm.tsx | 54 ++++--- .../CreateReportPage/CreateReportPage.scss | 133 +++++++++++++++++ .../CreateReportPage/CreateReportPage.tsx | 94 ++++++++++++ .../CreateReportPage/icons/arrow-right.svg | 6 + .../CreateReportPage/icons/paperclip.svg | 5 + src/Pages/Homepage/Homepage.tsx | 22 ++- .../NewsDetailsPage/NewsDetailsPage.scss | 29 +--- src/Pages/NewsDetailsPage/NewsDetailsPage.tsx | 54 ++----- .../ReportDetailsPage/ReportDetailsPage.scss | 36 +++++ .../ReportDetailsPage/ReportDetailsPage.tsx | 32 ++++ .../ReportDetailsPage/report-details.store.ts | 57 +++++++ .../profile/MyReportsPage/MyReportsPage.scss | 0 .../profile/MyReportsPage/MyReportsPage.tsx | 7 + .../PersonalDataPage/PersonalDataPage.scss | 0 .../PersonalDataPage/PersonalDataPage.tsx | 7 + .../profile/ProfilePage/ProfileLayout.scss | 24 +++ .../profile/ProfilePage/ProfileLayout.tsx | 17 +++ src/Shared/helpers/sliceDate.ts | 0 src/Shared/hooks/useUpdateEffect.ts | 27 ---- src/Shared/variables/road-types.ts | 17 +++ src/Widgets/NewsHeader/NewsHeader.scss | 55 +++++++ src/Widgets/NewsHeader/NewsHeader.tsx | 58 ++++++++ .../NewsHeader}/icons/calendar-icon.svg | 0 .../NewsHeader}/icons/message-icon.svg | 0 .../NewsReviewsSection/NewsReviewsSection.tsx | 46 ------ src/Widgets/ProfileNav/ProfileNav.scss | 47 ++++++ src/Widgets/ProfileNav/ProfileNav.tsx | 51 +++++++ src/Widgets/ReportImages/ReportImages.scss | 42 ++++++ src/Widgets/ReportImages/ReportImages.tsx | 50 +++++++ .../ReportImages/icons/default-image.svg | 8 + src/Widgets/ReportInfo/ReportInfo.scss | 61 ++++++++ src/Widgets/ReportInfo/ReportInfo.tsx | 94 ++++++++++++ .../ReportInfo/icons/calendar-icon.svg | 8 + src/Widgets/ReportInfo/icons/map-pin.svg | 17 +++ src/Widgets/general/Navbar/Navbar.scss | 2 +- .../ReviewsSection/ReviewsSection.scss} | 28 +++- .../general/ReviewsSection/ReviewsSection.tsx | 34 +++++ src/Widgets/general/ReviewsSection/store.ts | 46 ++++++ src/Widgets/home/Header/Header.tsx | 2 +- src/Widgets/home/MapSection/MapSection.scss | 8 - src/Widgets/home/MapSection/MapSection.tsx | 139 +++++++++++++----- .../home/MapSection/assets/geo-green.svg | 5 + .../home/MapSection/assets/geo-orange.svg | 5 + .../home/MapSection/assets/geo-pink.svg | 5 + .../home/MapSection/assets/geo-purple.svg | 5 + .../home/MapSection/assets/geo-red.svg | 5 + .../home/MapSection/assets/geo-yellow.svg | 5 + src/Widgets/home/MapSection/map.store.ts | 39 +++++ src/Widgets/home/MapSection/types.ts | 22 +++ src/Widgets/home/NewsSection/NewsSection.tsx | 2 +- .../home/RatingSection/RatingSection.scss | 9 -- .../home/RatingSection/RatingSection.tsx | 50 ++++++- .../home/RatingSection/rating.store.ts | 21 ++- src/Widgets/home/RatingSection/types.ts | 13 +- src/middleware.ts | 3 + tsconfig.json | 1 + yarn.lock | 137 +++++++++++++++-- 92 files changed, 2076 insertions(+), 279 deletions(-) create mode 100644 .env create mode 100644 app/api/auth/[...nextauth]/route.ts create mode 100644 app/create-report/page.tsx create mode 100644 app/profile/layout.tsx create mode 100644 app/profile/my-reports/page.tsx delete mode 100644 app/profile/page.tsx create mode 100644 app/profile/personal-data/page.tsx create mode 100644 app/report/[id]/page.tsx create mode 100644 lib/next-auth.d.ts create mode 100644 src/App/Providers.tsx create mode 100644 src/Entities/RoadType/RoadType.scss create mode 100644 src/Entities/RoadType/RoadType.tsx create mode 100644 src/Features/CreateReportMap/CreateReportMap.scss create mode 100644 src/Features/CreateReportMap/CreateReportMap.tsx create mode 100644 src/Features/CreateReportMap/assets/pin.svg create mode 100644 src/Features/HomeMap/HomeMap.scss create mode 100644 src/Features/HomeMap/HomeMap.tsx create mode 100644 src/Features/HomeMap/icons/geo-green.svg create mode 100644 src/Features/HomeMap/icons/geo-orange.svg create mode 100644 src/Features/HomeMap/icons/geo-pink.svg create mode 100644 src/Features/HomeMap/icons/geo-purple.svg create mode 100644 src/Features/HomeMap/icons/geo-red.svg create mode 100644 src/Features/HomeMap/icons/geo-yellow.svg create mode 100644 src/Features/ReportLike/ReportLike.scss create mode 100644 src/Features/ReportLike/ReportLike.tsx create mode 100644 src/Features/ReportLike/icons/like-icon.svg create mode 100644 src/Pages/CreateReportPage/CreateReportPage.scss create mode 100644 src/Pages/CreateReportPage/CreateReportPage.tsx create mode 100644 src/Pages/CreateReportPage/icons/arrow-right.svg create mode 100644 src/Pages/CreateReportPage/icons/paperclip.svg create mode 100644 src/Pages/ReportDetailsPage/ReportDetailsPage.scss create mode 100644 src/Pages/ReportDetailsPage/ReportDetailsPage.tsx create mode 100644 src/Pages/ReportDetailsPage/report-details.store.ts create mode 100644 src/Pages/profile/MyReportsPage/MyReportsPage.scss create mode 100644 src/Pages/profile/MyReportsPage/MyReportsPage.tsx create mode 100644 src/Pages/profile/PersonalDataPage/PersonalDataPage.scss create mode 100644 src/Pages/profile/PersonalDataPage/PersonalDataPage.tsx create mode 100644 src/Pages/profile/ProfilePage/ProfileLayout.scss create mode 100644 src/Pages/profile/ProfilePage/ProfileLayout.tsx create mode 100644 src/Shared/helpers/sliceDate.ts delete mode 100644 src/Shared/hooks/useUpdateEffect.ts create mode 100644 src/Shared/variables/road-types.ts create mode 100644 src/Widgets/NewsHeader/NewsHeader.scss create mode 100644 src/Widgets/NewsHeader/NewsHeader.tsx rename src/{Pages/NewsDetailsPage => Widgets/NewsHeader}/icons/calendar-icon.svg (100%) rename src/{Pages/NewsDetailsPage => Widgets/NewsHeader}/icons/message-icon.svg (100%) delete mode 100644 src/Widgets/NewsReviewsSection/NewsReviewsSection.tsx create mode 100644 src/Widgets/ProfileNav/ProfileNav.scss create mode 100644 src/Widgets/ProfileNav/ProfileNav.tsx create mode 100644 src/Widgets/ReportImages/ReportImages.scss create mode 100644 src/Widgets/ReportImages/ReportImages.tsx create mode 100644 src/Widgets/ReportImages/icons/default-image.svg create mode 100644 src/Widgets/ReportInfo/ReportInfo.scss create mode 100644 src/Widgets/ReportInfo/ReportInfo.tsx create mode 100644 src/Widgets/ReportInfo/icons/calendar-icon.svg create mode 100644 src/Widgets/ReportInfo/icons/map-pin.svg rename src/Widgets/{NewsReviewsSection/NewsReviewsSection.scss => general/ReviewsSection/ReviewsSection.scss} (56%) create mode 100644 src/Widgets/general/ReviewsSection/ReviewsSection.tsx create mode 100644 src/Widgets/general/ReviewsSection/store.ts create mode 100644 src/Widgets/home/MapSection/assets/geo-green.svg create mode 100644 src/Widgets/home/MapSection/assets/geo-orange.svg create mode 100644 src/Widgets/home/MapSection/assets/geo-pink.svg create mode 100644 src/Widgets/home/MapSection/assets/geo-purple.svg create mode 100644 src/Widgets/home/MapSection/assets/geo-red.svg create mode 100644 src/Widgets/home/MapSection/assets/geo-yellow.svg create mode 100644 src/Widgets/home/MapSection/map.store.ts create mode 100644 src/Widgets/home/MapSection/types.ts create mode 100644 src/middleware.ts diff --git a/.env b/.env new file mode 100644 index 0000000..efab21d --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +NEXTAUTH_SECRET=";sadmfxflpdk" +NEXTAUTH_URL="http://localhost:3000" \ No newline at end of file diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..8db3ff8 --- /dev/null +++ b/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,91 @@ +import axios from "axios"; +import NextAuth, { NextAuthOptions } from "next-auth"; +import { JWT } from "next-auth/jwt"; +import CredentialsProvider from "next-auth/providers/credentials"; + +interface IToken { + access: string; +} + +const refreshToken = async (token: JWT): Promise => { + const data = { + refresh: token.refresh_token, + }; + + const response = await axios.post( + "https://api.kgroaduat.fishrungames.com/api/v1/token/refresh/", + data + ); + + return { + ...token, + access_token: response.data.access, + }; +}; + +export const authOptions: NextAuthOptions = { + providers: [ + CredentialsProvider({ + name: "Credentials", + credentials: { + email: { + label: "Email", + type: "text", + placeholder: "jsmith@example.com", + }, + password: { label: "Password", type: "password" }, + }, + async authorize(credentials, req) { + if (!credentials?.email || !credentials?.password) + return null; + const { email, password } = credentials as any; + + const res = await fetch( + "https://api.kgroaduat.fishrungames.com/api/v1/users/login/", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + email, + password, + }), + } + ); + + if (res.status === 401) { + console.log(res.status); + return null; + } + + const user = await res.json(); + return user; + }, + }), + ], + pages: { + signIn: "/sign-in", + }, + session: { + strategy: "jwt", + }, + callbacks: { + async jwt({ token, user }) { + if (user) return { ...token, ...user }; + + return refreshToken(token); + }, + + async session({ token, session }) { + session.access_token = token.access_token; + session.refresh_token = token.refresh_token; + + return session; + }, + }, +}; + +const handler = NextAuth(authOptions); + +export { handler as GET, handler as POST }; diff --git a/app/create-report/page.tsx b/app/create-report/page.tsx new file mode 100644 index 0000000..e05f648 --- /dev/null +++ b/app/create-report/page.tsx @@ -0,0 +1,3 @@ +import CreateReportPage from "@/Pages/CreateReportPage/CreateReportPage"; + +export default CreateReportPage; diff --git a/app/profile/layout.tsx b/app/profile/layout.tsx new file mode 100644 index 0000000..7eb27f3 --- /dev/null +++ b/app/profile/layout.tsx @@ -0,0 +1,3 @@ +import ProfileLayout from "@/Pages/profile/ProfilePage/ProfileLayout"; + +export default ProfileLayout; diff --git a/app/profile/my-reports/page.tsx b/app/profile/my-reports/page.tsx new file mode 100644 index 0000000..3e91dd0 --- /dev/null +++ b/app/profile/my-reports/page.tsx @@ -0,0 +1,3 @@ +import MyReportsPage from "@/Pages/profile/MyReportsPage/MyReportsPage"; + +export default MyReportsPage; diff --git a/app/profile/page.tsx b/app/profile/page.tsx deleted file mode 100644 index a54c709..0000000 --- a/app/profile/page.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; - -const page = () => { - return
page
; -}; - -export default page; diff --git a/app/profile/personal-data/page.tsx b/app/profile/personal-data/page.tsx new file mode 100644 index 0000000..9122a75 --- /dev/null +++ b/app/profile/personal-data/page.tsx @@ -0,0 +1,3 @@ +import PersonalDataPage from "@/Pages/profile/PersonalDataPage/PersonalDataPage"; + +export default PersonalDataPage; diff --git a/app/report/[id]/page.tsx b/app/report/[id]/page.tsx new file mode 100644 index 0000000..614d113 --- /dev/null +++ b/app/report/[id]/page.tsx @@ -0,0 +1,3 @@ +import ReportDetailsPage from "@/Pages/ReportDetailsPage/ReportDetailsPage"; + +export default ReportDetailsPage; diff --git a/lib/next-auth.d.ts b/lib/next-auth.d.ts new file mode 100644 index 0000000..f526420 --- /dev/null +++ b/lib/next-auth.d.ts @@ -0,0 +1,18 @@ +import NextAuth from "next-auth"; + +declare module "next-auth" { + interface Session { + refresh_token: string; + access_token: string; + } +} + +import { JWT } from "next-auth/jwt"; + +declare module "next-auth/jwt" { + interface JWT { + refresh_token: string; + access_token: string; + exp: number; + } +} diff --git a/package.json b/package.json index c6f06bb..774b7ae 100644 --- a/package.json +++ b/package.json @@ -10,17 +10,22 @@ }, "dependencies": { "axios": "^1.6.5", + "leaflet": "^1.9.4", "next": "14.1.0", + "next-auth": "^4.24.5", "react": "^18", "react-dom": "^18", + "react-leaflet": "^4.2.1", "sass": "^1.70.0", - "swr": "^2.2.4", + "use-debounce": "^10.0.0", "zustand": "^4.5.0" }, "devDependencies": { + "@types/leaflet": "^1.9.8", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", + "@types/react-leaflet": "^3.0.0", "eslint": "^8", "eslint-config-next": "14.1.0", "typescript": "^5" diff --git a/src/App/App.tsx b/src/App/App.tsx index fd75142..18826aa 100644 --- a/src/App/App.tsx +++ b/src/App/App.tsx @@ -2,6 +2,7 @@ import { Montserrat } from "next/font/google"; import "./globals.scss"; import Navbar from "@/Widgets/general/Navbar/Navbar"; import Footer from "@/Widgets/general/Footer/Footer"; +import { Providers } from "./Providers"; const montserrat = Montserrat({ subsets: ["latin"] }); @@ -13,9 +14,11 @@ export default function RootLayout({ return ( - - {children} -