Skip to content

Commit

Permalink
feat: improve ux (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
coolCatalyst committed Oct 30, 2023
1 parent 4282285 commit d7c7f4b
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 127 deletions.
51 changes: 0 additions & 51 deletions frontend/app/(auth)/logout/__tests__/page.test.tsx

This file was deleted.

50 changes: 0 additions & 50 deletions frontend/app/(auth)/logout/page.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PublicBrain } from "@/lib/context/BrainProvider/types";
export const useBrainsLibrary = () => {
const [searchBarText, setSearchBarText] = useState("");
const { getPublicBrains } = useBrainApi();
const { data: publicBrains = [] } = useQuery({
const { data: publicBrains = [], isLoading } = useQuery({
queryKey: [PUBLIC_BRAINS_KEY],
queryFn: getPublicBrains,
});
Expand Down Expand Up @@ -39,5 +39,6 @@ export const useBrainsLibrary = () => {
displayingPublicBrains,
searchBarText,
setSearchBarText,
isLoading,
};
};
8 changes: 7 additions & 1 deletion frontend/app/brains-management/library/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import { useTranslation } from "react-i18next";

import Field from "@/lib/components/ui/Field";
import Spinner from "@/lib/components/ui/Spinner";

import { PublicBrainItem } from "./components/PublicBrainItem/PublicBrainItem";
import { useBrainsLibrary } from "./hooks/useBrainsLibrary";

const BrainsLibrary = (): JSX.Element => {
const { displayingPublicBrains, searchBarText, setSearchBarText } =
const { displayingPublicBrains, searchBarText, setSearchBarText, isLoading } =
useBrainsLibrary();
const { t } = useTranslation("brain");

Expand All @@ -23,6 +24,11 @@ const BrainsLibrary = (): JSX.Element => {
placeholder={t("public_brains_search_bar_placeholder")}
/>
</div>
{isLoading && (
<div className="flex justify-center items-center flex-1">
<Spinner className="text-4xl" />
</div>
)}

<div className="flex flex-wrap justify-stretch w-full">
{displayingPublicBrains.map((brain) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const ChatInput = ({
onClick={() => setShouldDisplayFeedCard(true)}
tooltip={t("add_content_card_button_tooltip")}
>
<PiPaperclipFill className="text-3xl" />
<PiPaperclipFill size={38} />
</Button>
)}

Expand Down
51 changes: 51 additions & 0 deletions frontend/app/user/components/LogoutCard/LogoutModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useTranslation } from "react-i18next";

import Button from "@/lib/components/ui/Button";
import { Modal } from "@/lib/components/ui/Modal";

import { useLogoutModal } from "./hooks/useLogoutModal";

export const LogoutModal = (): JSX.Element => {
const { t } = useTranslation(["translation", "logout"]);
const {
handleLogout,
isLoggingOut,
isLogoutModalOpened,
setIsLogoutModalOpened,
} = useLogoutModal();

return (
<Modal
Trigger={
<Button className="px-3 py-2" variant="secondary">
{t("logoutButton")}
</Button>
}
isOpen={isLogoutModalOpened}
setOpen={setIsLogoutModalOpened}
CloseTrigger={<div />}
>
<div className="text-center flex flex-col items-center gap-5">
<h2 className="text-lg font-medium mb-5">
{t("areYouSure", { ns: "logout" })}
</h2>
<div className="flex gap-5 items-center justify-center">
<Button
onClick={() => setIsLogoutModalOpened(false)}
variant={"primary"}
>
{t("cancel", { ns: "logout" })}
</Button>
<Button
isLoading={isLoggingOut}
variant={"danger"}
onClick={() => void handleLogout()}
data-testid="logout-button"
>
{t("logoutButton")}
</Button>
</div>
</div>
</Modal>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { act, renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";

import { useLogout } from "../useLogout";
import { useLogoutModal } from "../useLogoutModal";

const mockSignOut = vi.fn(() => ({ error: null }));

Expand All @@ -28,9 +28,9 @@ Object.defineProperty(window, "localStorage", {
},
});

describe("useLogout", () => {
describe("useLogoutModal", () => {
it("should call signOut", async () => {
const { result } = renderHook(() => useLogout());
const { result } = renderHook(() => useLogoutModal());

await act(() => result.current.handleLogout());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import { useToast } from "@/lib/hooks";
import { useEventTracking } from "@/services/analytics/june/useEventTracking";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useLogout = () => {
export const useLogoutModal = () => {
const { supabase } = useSupabase();
const [isPending, setIsPending] = useState(false);
const [isLoggingOut, setIsLoggingOut] = useState(false);
const [isLogoutModalOpened, setIsLogoutModalOpened] = useState(false);
const { track } = useEventTracking();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { t, i18n } = useTranslation(["translation", "logout"]);
const { t } = useTranslation(["translation", "logout"]);

const { publish } = useToast();
const router = useRouter();

const handleLogout = async () => {
setIsPending(true);
setIsLoggingOut(true);
const { error } = await supabase.auth.signOut();
void track("LOGOUT");
localStorage.clear();
Expand All @@ -37,11 +38,13 @@ export const useLogout = () => {
});
router.replace("/");
}
setIsPending(false);
setIsLoggingOut(false);
};

return {
handleLogout,
isPending,
isLoggingOut,
isLogoutModalOpened,
setIsLogoutModalOpened,
};
};
8 changes: 3 additions & 5 deletions frontend/app/user/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { redirectToLogin } from "@/lib/router/redirectToLogin";
import { StripePricingOrManageButton, UserStatistics } from "./components";
import { ApiKeyConfig } from "./components/ApiKeyConfig";
import LanguageSelect from "./components/LanguageDropDown/LanguageSelect";
import { LogoutModal } from "./components/LogoutCard/LogoutModal";
import ThemeSelect from "./components/ThemeSelect/ThemeSelect";

const UserPage = (): JSX.Element => {
Expand Down Expand Up @@ -42,11 +43,8 @@ const UserPage = (): JSX.Element => {
<p>
<strong>{t("email")}:</strong> <span>{user.email}</span>
</p>
<Link href={"/logout"}>
<Button className="px-3 py-2" variant="secondary">
{t("logoutButton")}
</Button>
</Link>

<LogoutModal />
</div>
<StripePricingOrManageButton />
</CardBody>
Expand Down
9 changes: 7 additions & 2 deletions frontend/lib/components/ui/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { FaSpinner } from "react-icons/fa";

const Spinner = (): JSX.Element => {
return <FaSpinner className="animate-spin m-5" />;
import { cn } from "@/lib/utils";

type SpinnerProps = {
className?: string;
};
const Spinner = ({ className }: SpinnerProps): JSX.Element => {
return <FaSpinner className={cn("animate-spin m-5", className)} />;
};

export default Spinner;
4 changes: 2 additions & 2 deletions frontend/public/locales/en/logout.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"title": "Logout",
"subtitle": "See you next time",
"areYouSure": "Are you sure you want to sign out?",
"cancel": "Go back",
"areYouSure": "Are you sure you want to sign out ?",
"cancel": "Cancel",
"error": "Error on logout {{errorMessage}}",
"loggedOut": "Logged out successfully"
}
2 changes: 1 addition & 1 deletion frontend/public/locales/es/logout.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"areYouSure": "¿Seguro que quieres cerrar la sesión?",
"cancel": "Regresar",
"cancel": "Cancelar",
"error": "Error al cerrar sesión {{errorMessage}}",
"loggedOut": "Sesión finalizada",
"subtitle": "Hasta pronto",
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/locales/fr/logout.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "Déconnexion",
"subtitle": "À la prochaine",
"areYouSure": "Êtes-vous sûr de vouloir vous déconnecter ?",
"cancel": "Retour",
"cancel": "Annuler",
"error": "Erreur lors de la déconnexion {{errorMessage}}",
"loggedOut": "Déconnexion réussie"
}
2 changes: 1 addition & 1 deletion frontend/public/locales/pt-br/logout.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "Sair",
"subtitle": "Até a próxima vez",
"areYouSure": "Você tem certeza de que deseja sair?",
"cancel": "Voltar",
"cancel": "Cancelar",
"error": "Erro ao fazer logout {{errorMessage}}",
"loggedOut": "Saiu com sucesso"
}
2 changes: 1 addition & 1 deletion frontend/public/locales/ru/logout.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "Выход",
"subtitle": "Увидимся в следующий раз",
"areYouSure": "Вы уверены, что хотите выйти?",
"cancel": "Вернуться",
"cancel": "Отмена",
"error": "Ошибка при выходе: {{errorMessage}}",
"loggedOut": "Успешный выход"
}
2 changes: 1 addition & 1 deletion frontend/public/locales/zh-cn/logout.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "注销",
"subtitle": "下次见",
"areYouSure": "是否确实要注销?",
"cancel": "返回",
"cancel": "取消",
"error": "注销时出错 {{errorMessage}}",
"loggedOut": "注销成功"
}

0 comments on commit d7c7f4b

Please sign in to comment.