.
This commit is contained in:
parent
49c790a814
commit
9262e626a1
@ -22,11 +22,12 @@ import { joiResolver } from "@hookform/resolvers/joi";
|
||||
import { ILogin_DTO } from "@shared/contexts";
|
||||
import Joi from "joi";
|
||||
|
||||
import { useToast } from "@/ui/use-toast";
|
||||
import { AlertCircleIcon, ChevronDownIcon } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { SubmitHandler, useForm } from "react-hook-form";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import SpanishJoiMessages from "../../spanish-joi-messages.json";
|
||||
import "/node_modules/flag-icons/css/flag-icons.min.css";
|
||||
|
||||
@ -42,6 +43,8 @@ const languages = [
|
||||
export const LoginPageWithLanguageSelector = () => {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [language, setLanguage] = useState(i18n.language);
|
||||
const navigate = useNavigate();
|
||||
const { toast } = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
const browserLang = navigator.language.split("-")[0];
|
||||
@ -62,8 +65,14 @@ export const LoginPageWithLanguageSelector = () => {
|
||||
if (!success && error) {
|
||||
form.setError("root", error);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
navigate("/quotes", { replace: true });
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
const { message } = error;
|
||||
toast({ description: message, title: "Error" });
|
||||
console.debug(error);
|
||||
},
|
||||
});
|
||||
|
||||
@ -1,40 +1,16 @@
|
||||
import { AuthActionResponse, useAuth } from "@/lib/hooks";
|
||||
import { ILogin_DTO } from "@shared/contexts";
|
||||
import { UseMutationOptions, useMutation } from "@tanstack/react-query";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { useToast } from "@/ui/use-toast";
|
||||
import { useQueryKey } from "../useQueryKey";
|
||||
|
||||
export const useLogin = (params?: UseMutationOptions<AuthActionResponse, Error, ILogin_DTO>) => {
|
||||
const { toast } = useToast();
|
||||
const { onSuccess, onError, ...restParams } = params || {};
|
||||
const keys = useQueryKey();
|
||||
const { login } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return useMutation({
|
||||
mutationKey: keys().auth().action("login").get(),
|
||||
mutationFn: login,
|
||||
onSuccess: (data, variables, context) => {
|
||||
const { success, redirectTo } = data;
|
||||
if (success) {
|
||||
navigate(redirectTo || "/quotes");
|
||||
}
|
||||
if (onSuccess) {
|
||||
onSuccess(data, variables, context);
|
||||
}
|
||||
},
|
||||
onError: (error, variables, context) => {
|
||||
const { message } = error;
|
||||
console.error(message);
|
||||
|
||||
toast({ description: message, title: "Error" });
|
||||
|
||||
if (onError) {
|
||||
onError(error, variables, context);
|
||||
}
|
||||
},
|
||||
...restParams,
|
||||
...params,
|
||||
});
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
dist/client/index.html
vendored
2
dist/client/index.html
vendored
@ -7,7 +7,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link href="https://fonts.upset.dev/css2?family=Poppins&display=swap" rel="stylesheet" />
|
||||
<title>Uecko</title>
|
||||
<script type="module" crossorigin src="/assets/index-DJx8BFtg.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-Db7De-WR.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-D-WUkXMb.css">
|
||||
</head>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user