diff options
author | HombreLaser <sebastian-440@live.com> | 2023-05-25 19:53:48 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2023-05-25 19:53:48 -0600 |
commit | a0318f76f40deaeba367badf18af6141325d29e9 (patch) | |
tree | a88432d82adad9d0acb234935f3b9c3ae9c30c54 | |
parent | e8fa9bd7bba125a339f11876eb5ea99d0cd301b6 (diff) |
Añade redirecciones faltantes
-rw-r--r-- | src/components/forms/login_form.tsx | 4 | ||||
-rw-r--r-- | src/components/user_account_dropdown_menu.tsx | 45 | ||||
-rw-r--r-- | src/lib/redirect_to.ts | 6 |
3 files changed, 39 insertions, 16 deletions
diff --git a/src/components/forms/login_form.tsx b/src/components/forms/login_form.tsx index b1a2296..74557e2 100644 --- a/src/components/forms/login_form.tsx +++ b/src/components/forms/login_form.tsx @@ -1,9 +1,10 @@ import { Modal } from "flowbite"; -import UserAccountButton from "../user_account_button"; +import RedirectTo from '../../lib/redirect_to'; import { useEffect, useState } from "react"; import { ApiClient } from "../../clients/api_client"; import Token from "../../lib/token"; import "../stylesheets/shared.css" +import redirectTo from "../../lib/redirect_to"; export function LoginForm() { const [error_message, setErrorMessage] = useState(''); @@ -43,6 +44,7 @@ export function LoginForm() { const token = new Token(); token.set(response.data.token); token.setRefresh(response.data.refresh); + redirectTo('/products'); } catch(error) { setErrorMessage(error.response.data.errors.auth); } diff --git a/src/components/user_account_dropdown_menu.tsx b/src/components/user_account_dropdown_menu.tsx index 495f3c8..2bd0d28 100644 --- a/src/components/user_account_dropdown_menu.tsx +++ b/src/components/user_account_dropdown_menu.tsx @@ -1,22 +1,37 @@ import { PersonFill, DoorOpenFill, CardList } from "react-bootstrap-icons"; +import { BrowserRouter, Form } from "react-router-dom"; +import RedirectTo from '../lib/redirect_to'; +import Token from "../lib/token"; +import redirectTo from "../lib/redirect_to"; export default function UserAccountDropdownMenu() { + function logout() { + const token = new Token(); + token.logout(); + + redirectTo('/products'); + } + return( - <div id="userAccountDropdownMenu" className="hidden bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700 dark:divide-gray-600"> - <ul className="relative py-2 text-sm text-gray-700 dark:text-gray-200"> - <li className="flex"> - <i className="px-1 my-2"><PersonFill size={16} color="#394490"/></i> - <a href="/account" className="block px-2 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Cuenta</a> - </li> - <li className="flex"> - <i className="px-1 my-2"><CardList size={16} color="#394490"/></i> - <a href="/account/orders" className="block px-2 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Historial de órdenes</a> - </li> - </ul> - <div className="flex py-2"> - <i className="px-1 my-2"><DoorOpenFill size={16} color="#394490"/></i> - <a href="#" className="flex block px-2 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white">Cerrar sesión</a> + <BrowserRouter> + <div id="userAccountDropdownMenu" className="hidden bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700 dark:divide-gray-600"> + <ul className="relative py-2 text-sm text-gray-700 dark:text-gray-200"> + <li className="flex"> + <i className="px-1 my-2"><PersonFill size={16} color="#394490"/></i> + <a href="/account" className="block px-2 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Cuenta</a> + </li> + <li className="flex"> + <i className="px-1 my-2"><CardList size={16} color="#394490"/></i> + <a href="/account/orders" className="block px-2 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Historial de órdenes</a> + </li> + </ul> + <div className="flex py-2"> + <i className="px-1 my-2"><DoorOpenFill size={16} color="#394490"/></i> + <button type="button" onClick={logout} className="flex block px-2 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"> + Cerrar sesión + </button> + </div> </div> - </div> + </BrowserRouter> ); }
\ No newline at end of file diff --git a/src/lib/redirect_to.ts b/src/lib/redirect_to.ts new file mode 100644 index 0000000..e31e235 --- /dev/null +++ b/src/lib/redirect_to.ts @@ -0,0 +1,6 @@ +export default function redirectTo(route: string) { + const split_location = window.location.href.split('/') + const hostname = split_location.slice(0, split_location.length - 1).join('/'); + + window.location.href = hostname + route; +}
\ No newline at end of file |