Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display toasters using react-query callback on success,failure #616

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
"code_is_required": "Language code is required",
"text_is_required": "Text is required",
"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 while disconnecting"
marrouchi marked this conversation as resolved.
Show resolved Hide resolved
},
"menu": {
"terms": "Terms of Use",
Expand Down
3 changes: 2 additions & 1 deletion frontend/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
"code_is_required": "Le code est requis",
"text_is_required": "Texte requis",
"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": {
"terms": "Conditions d'utilisation",
Expand Down
10 changes: 3 additions & 7 deletions frontend/src/contexts/auth.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/


import getConfig from "next/config";
import { useRouter } from "next/router";
import { createContext, ReactNode, useEffect, useState } from "react";
Expand All @@ -22,7 +21,6 @@ import { Progress } from "@/app-components/displays/Progress";
import { useLogout } from "@/hooks/entities/auth-hooks";
import { useApiClient } from "@/hooks/useApiClient";
import { CURRENT_USER_KEY, PUBLIC_PATHS } from "@/hooks/useAuth";
import { useToast } from "@/hooks/useToast";
import { useTranslate } from "@/hooks/useTranslate";
import { RouterType } from "@/services/types";
import { IUser } from "@/types/user.types";
Expand Down Expand Up @@ -54,18 +52,16 @@ export const AuthProvider = ({ children }: AuthProviderProps): JSX.Element => {
const router = useRouter();
const [search, setSearch] = useState("");
const hasPublicPath = PUBLIC_PATHS.includes(router.pathname);
const { i18n, t } = useTranslate();
const { toast } = useToast();
const { i18n } = useTranslate();
const [isReady, setIsReady] = useState(false);
const queryClient = useQueryClient();
const updateLanguage = (lang: string) => {
i18n.changeLanguage(lang);
};
const { mutateAsync: logoutSession } = useLogout();
const { mutate: logoutSession } = useLogout();
const logout = async () => {
updateLanguage(publicRuntimeConfig.lang.default);
await logoutSession();
toast.success(t("message.logout_success"));
logoutSession();
};
const authRedirection = async (isAuthenticated: boolean) => {
if (isAuthenticated) {
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/hooks/entities/auth-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { useSocket } from "@/websocket/socket-hooks";
import { useFind } from "../crud/useFind";
import { useApiClient } from "../useApiClient";
import { CURRENT_USER_KEY, useAuth, useLogoutRedirection } from "../useAuth";
import { useToast } from "../useToast";
import { useTranslate } from "../useTranslate";

export const useLogin = (
options?: Omit<
Expand Down Expand Up @@ -54,6 +56,8 @@ export const useLogout = (
const { apiClient } = useApiClient();
const { socket } = useSocket();
const { logoutRedirection } = useLogoutRedirection();
const { toast } = useToast();
const { t } = useTranslate();

return useMutation({
...options,
Expand All @@ -65,6 +69,10 @@ export const useLogout = (
onSuccess: async () => {
queryClient.removeQueries([CURRENT_USER_KEY]);
await logoutRedirection();
toast.success(t("message.logout_success"));
},
onError: () => {
toast.error(t("message.logout_failed"));
},
});
};
Expand Down
Loading