mirror of
https://github.com/hexastack/hexabot
synced 2025-03-09 22:01:23 +00:00
Merge pull request #616 from Hexastack/feat/add-error-toast-logout
feat: display toasters using react-query callback on success,failure
This commit is contained in:
commit
1382028730
@ -109,7 +109,8 @@
|
|||||||
"code_is_required": "Language code is required",
|
"code_is_required": "Language code is required",
|
||||||
"text_is_required": "Text is required",
|
"text_is_required": "Text is required",
|
||||||
"invalid_file_type": "Invalid file type. Please select a file in the supported format.",
|
"invalid_file_type": "Invalid file type. Please select a file in the supported format.",
|
||||||
"select_category": "Select a flow"
|
"select_category": "Select a flow",
|
||||||
|
"logout_failed": "Something went wrong during logout"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"terms": "Terms of Use",
|
"terms": "Terms of Use",
|
||||||
|
@ -109,7 +109,8 @@
|
|||||||
"code_is_required": "Le code est requis",
|
"code_is_required": "Le code est requis",
|
||||||
"text_is_required": "Texte requis",
|
"text_is_required": "Texte requis",
|
||||||
"invalid_file_type": "Type de fichier invalide. Veuillez choisir un fichier dans un format pris en charge.",
|
"invalid_file_type": "Type de fichier invalide. Veuillez choisir un fichier dans un format pris en charge.",
|
||||||
"select_category": "Sélectionner une catégorie"
|
"select_category": "Sélectionner une catégorie",
|
||||||
|
"logout_failed": "Une erreur s'est produite lors de la déconnexion"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"terms": "Conditions d'utilisation",
|
"terms": "Conditions d'utilisation",
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import getConfig from "next/config";
|
import getConfig from "next/config";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { createContext, ReactNode, useEffect, useState } from "react";
|
import { createContext, ReactNode, useEffect, useState } from "react";
|
||||||
@ -22,7 +21,6 @@ import { Progress } from "@/app-components/displays/Progress";
|
|||||||
import { useLogout } from "@/hooks/entities/auth-hooks";
|
import { useLogout } from "@/hooks/entities/auth-hooks";
|
||||||
import { useApiClient } from "@/hooks/useApiClient";
|
import { useApiClient } from "@/hooks/useApiClient";
|
||||||
import { CURRENT_USER_KEY, PUBLIC_PATHS } from "@/hooks/useAuth";
|
import { CURRENT_USER_KEY, PUBLIC_PATHS } from "@/hooks/useAuth";
|
||||||
import { useToast } from "@/hooks/useToast";
|
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
import { useTranslate } from "@/hooks/useTranslate";
|
||||||
import { RouterType } from "@/services/types";
|
import { RouterType } from "@/services/types";
|
||||||
import { IUser } from "@/types/user.types";
|
import { IUser } from "@/types/user.types";
|
||||||
@ -54,18 +52,16 @@ export const AuthProvider = ({ children }: AuthProviderProps): JSX.Element => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const hasPublicPath = PUBLIC_PATHS.includes(router.pathname);
|
const hasPublicPath = PUBLIC_PATHS.includes(router.pathname);
|
||||||
const { i18n, t } = useTranslate();
|
const { i18n } = useTranslate();
|
||||||
const { toast } = useToast();
|
|
||||||
const [isReady, setIsReady] = useState(false);
|
const [isReady, setIsReady] = useState(false);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const updateLanguage = (lang: string) => {
|
const updateLanguage = (lang: string) => {
|
||||||
i18n.changeLanguage(lang);
|
i18n.changeLanguage(lang);
|
||||||
};
|
};
|
||||||
const { mutateAsync: logoutSession } = useLogout();
|
const { mutate: logoutSession } = useLogout();
|
||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
updateLanguage(publicRuntimeConfig.lang.default);
|
updateLanguage(publicRuntimeConfig.lang.default);
|
||||||
await logoutSession();
|
logoutSession();
|
||||||
toast.success(t("message.logout_success"));
|
|
||||||
};
|
};
|
||||||
const authRedirection = async (isAuthenticated: boolean) => {
|
const authRedirection = async (isAuthenticated: boolean) => {
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
|
@ -22,6 +22,8 @@ import { useSocket } from "@/websocket/socket-hooks";
|
|||||||
import { useFind } from "../crud/useFind";
|
import { useFind } from "../crud/useFind";
|
||||||
import { useApiClient } from "../useApiClient";
|
import { useApiClient } from "../useApiClient";
|
||||||
import { CURRENT_USER_KEY, useAuth, useLogoutRedirection } from "../useAuth";
|
import { CURRENT_USER_KEY, useAuth, useLogoutRedirection } from "../useAuth";
|
||||||
|
import { useToast } from "../useToast";
|
||||||
|
import { useTranslate } from "../useTranslate";
|
||||||
|
|
||||||
export const useLogin = (
|
export const useLogin = (
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
@ -54,6 +56,8 @@ export const useLogout = (
|
|||||||
const { apiClient } = useApiClient();
|
const { apiClient } = useApiClient();
|
||||||
const { socket } = useSocket();
|
const { socket } = useSocket();
|
||||||
const { logoutRedirection } = useLogoutRedirection();
|
const { logoutRedirection } = useLogoutRedirection();
|
||||||
|
const { toast } = useToast();
|
||||||
|
const { t } = useTranslate();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
...options,
|
...options,
|
||||||
@ -65,6 +69,10 @@ export const useLogout = (
|
|||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
queryClient.removeQueries([CURRENT_USER_KEY]);
|
queryClient.removeQueries([CURRENT_USER_KEY]);
|
||||||
await logoutRedirection();
|
await logoutRedirection();
|
||||||
|
toast.success(t("message.logout_success"));
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t("message.logout_failed"));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user