From c0220a114f5ac94f680c0450bddb022df6d230b4 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Tue, 11 Jul 2023 17:17:45 +0330 Subject: [PATCH 1/3] interaction with back --- src/components/login-expert/index.jsx | 38 ++++++++++---------- src/core/data/apiRoutes.js | 5 +++ src/pages/dashboard/loan-follow-up/index.jsx | 2 +- src/pages/dashboard/loan-request/index.jsx | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/components/login-expert/index.jsx b/src/components/login-expert/index.jsx index 65b1e1c..bcc3b1a 100644 --- a/src/components/login-expert/index.jsx +++ b/src/components/login-expert/index.jsx @@ -2,7 +2,7 @@ import LinkRouting from "@/core/components/LinkRouting"; // import Notifications from "@/core/components/notifications"; import PasswordField from "@/core/components/PasswordField"; import StyledForm from "@/core/components/StyledForm"; -// import { GET_USER_TOKEN } from "@/core/data/apiRoutes"; +import { GET_USER_TOKEN } from "@/core/data/apiRoutes"; import CenterLayout from "@/layouts/CenterLayout"; import FullPageLayout from "@/layouts/FullPageLayout"; import useDirection from "@/lib/app/hooks/useDirection"; @@ -17,7 +17,7 @@ import { TextField, Typography, } from "@mui/material"; -// import axios from "axios"; +import axios from "axios"; import { Field, Formik } from "formik"; import { useTranslations } from "next-intl"; import Image from "next/image"; @@ -33,21 +33,23 @@ const LoginComponent = () => { const searchParams = useSearchParams(); const backUrlDecodedPath = searchParams.get("back_url"); - // formik properties - // const handleSubmit = async (values, props) => { - // await axios - // .post(GET_USER_TOKEN, { - // username: values.username, - // password: values.password, - // }) - // .then(function (response) { - // setToken(response.data.token); - // }) - // .catch(function (error) { - // Notifications(directionApp, error.response, t); - // props.setSubmitting(false); - // }); - // }; + //formik properties + const handleSubmit = async (values, props) => { + await axios + .post(GET_USER_TOKEN, { + username: values.username, + password: values.password, + }) + .then(function (response) { + console.log(response); + setToken(response.data.token); + }) + .catch(function (error) { + // Notifications(directionApp, error.response, t); + console.log(error); + props.setSubmitting(false); + }); + }; const initialValues = { username: "", password: "", @@ -64,7 +66,7 @@ const LoginComponent = () => { {(props) => ( diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index e69de29..2b4b463 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -0,0 +1,5 @@ +const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL; + +//login +export const GET_USER_TOKEN = BASE_URL + "/dashboard/login"; +//end login diff --git a/src/pages/dashboard/loan-follow-up/index.jsx b/src/pages/dashboard/loan-follow-up/index.jsx index fc299c4..6bab35f 100644 --- a/src/pages/dashboard/loan-follow-up/index.jsx +++ b/src/pages/dashboard/loan-follow-up/index.jsx @@ -6,7 +6,7 @@ import { parse } from "next-useragent"; export default function LoanFollowUp() { return ( - + ); diff --git a/src/pages/dashboard/loan-request/index.jsx b/src/pages/dashboard/loan-request/index.jsx index b76f172..ad64ce8 100644 --- a/src/pages/dashboard/loan-request/index.jsx +++ b/src/pages/dashboard/loan-request/index.jsx @@ -6,7 +6,7 @@ import { parse } from "next-useragent"; export default function LoanRequest() { return ( - + ); From 22317fe901e84617d8ca8189de38570b8fcb0126 Mon Sep 17 00:00:00 2001 From: Yasiu1376 Date: Wed, 12 Jul 2023 11:47:23 +0330 Subject: [PATCH 2/3] user implementt --- src/core/data/apiRoutes.js | 4 ++++ src/lib/app/contexts/user.jsx | 22 +--------------------- src/lib/app/hooks/useUser.jsx | 2 -- src/pages/dashboard/index.jsx | 2 +- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index 7e05eec..1b299cc 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -7,3 +7,7 @@ export const GET_USER_TOKEN = BASE_URL + "/dashboard/login"; //change password export const CHANGE_PASSWORD = BASE_URL + "/dashboard/profile/change_password"; //end change password + +//user data +export const GET_USER_ROUTE = BASE_URL + "/dashboard/profile/info"; +//user data \ No newline at end of file diff --git a/src/lib/app/contexts/user.jsx b/src/lib/app/contexts/user.jsx index 49d55af..30875d9 100644 --- a/src/lib/app/contexts/user.jsx +++ b/src/lib/app/contexts/user.jsx @@ -51,27 +51,7 @@ export const UserProvider = ({ children }) => { dispatch({ type: "CHANGE_USER", user }); }, []); - const changeUserLanguage = useCallback( - (language) => { - dispatch({ type: "CHANGE_USER_LANGUAGE", language }); - axios - .post( - SET_LANGUAGE, - { language: language }, - { - headers: { - authorization: `Bearer ${state.token}`, - }, - } - ) - .then(() => { - getUser((data) => { - changeUser(data); - }); - }); - }, - [state.token] - ); + const changeUserLanguage = useCallback(/* use in multi language app */); const changeAuthState = useCallback((isAuth) => { dispatch({ type: "CHANGE_AUTH_STATE", isAuth }); diff --git a/src/lib/app/hooks/useUser.jsx b/src/lib/app/hooks/useUser.jsx index baa0aaa..56bdf7c 100644 --- a/src/lib/app/hooks/useUser.jsx +++ b/src/lib/app/hooks/useUser.jsx @@ -10,7 +10,6 @@ const useUser = () => { getUser, clearUser, changeUser, - changeUserLanguage, changeAuthState, changeLanguageState, clearToken, @@ -25,7 +24,6 @@ const useUser = () => { getUser, clearUser, changeUser, - changeUserLanguage, changeAuthState, changeLanguageState, clearToken, diff --git a/src/pages/dashboard/index.jsx b/src/pages/dashboard/index.jsx index 5ebc479..57a801a 100644 --- a/src/pages/dashboard/index.jsx +++ b/src/pages/dashboard/index.jsx @@ -1,6 +1,6 @@ import DashboardFirstComponent from "@/components/dashboard/first"; import TitlePage from "@/core/components/TitlePage"; -import WithAuthMiddleware from "@/middlewares/WithoutAuth"; +import WithAuthMiddleware from "@/middlewares/WithAuth"; import { parse } from "next-useragent"; export default function Dashboard() { From 4f4873d7bb24520c9e784bff8cb36054213a2600 Mon Sep 17 00:00:00 2001 From: Yasiu1376 Date: Wed, 12 Jul 2023 11:59:28 +0330 Subject: [PATCH 3/3] change password auth --- src/pages/dashboard/change-password/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/dashboard/change-password/index.jsx b/src/pages/dashboard/change-password/index.jsx index 85660ff..30685f1 100644 --- a/src/pages/dashboard/change-password/index.jsx +++ b/src/pages/dashboard/change-password/index.jsx @@ -1,6 +1,6 @@ import DashboardChangePasswordComponent from "@/components/dashboard/change-password"; import TitlePage from "@/core/components/TitlePage"; -import WithAuthMiddleware from "@/middlewares/WithoutAuth"; +import WithAuthMiddleware from "@/middlewares/WithAuth"; import { parse } from "next-useragent"; export default function LoanFollowUp() {