2023-06-05 18:58:59 +03:00
|
|
|
"use client";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-02-04 04:45:05 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
import PageHeader from "@/lib/components/PageHeader/PageHeader";
|
2024-02-11 03:17:05 +03:00
|
|
|
import { Modal } from "@/lib/components/ui/Modal/Modal";
|
2024-02-07 03:05:07 +03:00
|
|
|
import QuivrButton from "@/lib/components/ui/QuivrButton/QuivrButton";
|
2023-06-20 17:17:13 +03:00
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
2024-02-04 04:45:05 +03:00
|
|
|
import { useUserData } from "@/lib/hooks/useUserData";
|
2023-07-13 19:05:08 +03:00
|
|
|
import { redirectToLogin } from "@/lib/router/redirectToLogin";
|
2024-02-07 03:05:07 +03:00
|
|
|
import { ButtonType } from "@/lib/types/QuivrButton";
|
2023-09-26 19:26:19 +03:00
|
|
|
|
2024-02-04 04:45:05 +03:00
|
|
|
import { Settings } from "./components/Settings/Settings";
|
|
|
|
import styles from "./page.module.scss";
|
2023-06-05 18:58:59 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
import { useLogoutModal } from "../../lib/hooks/useLogoutModal";
|
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
const UserPage = (): JSX.Element => {
|
2023-06-05 18:58:59 +03:00
|
|
|
const { session } = useSupabase();
|
2024-02-04 04:45:05 +03:00
|
|
|
const { userData } = useUserData();
|
2024-02-07 03:05:07 +03:00
|
|
|
const { t } = useTranslation(["translation", "logout"]);
|
|
|
|
const {
|
|
|
|
handleLogout,
|
|
|
|
isLoggingOut,
|
|
|
|
isLogoutModalOpened,
|
|
|
|
setIsLogoutModalOpened,
|
|
|
|
} = useLogoutModal();
|
2024-02-04 04:45:05 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
const button: ButtonType = {
|
|
|
|
label: "Logout",
|
|
|
|
color: "dangerous",
|
|
|
|
onClick: () => {
|
|
|
|
setIsLogoutModalOpened(true);
|
|
|
|
},
|
2024-02-07 10:34:50 +03:00
|
|
|
iconName: "logout",
|
2024-02-07 03:05:07 +03:00
|
|
|
};
|
2023-07-13 19:05:08 +03:00
|
|
|
|
2024-02-04 04:45:05 +03:00
|
|
|
if (!session || !userData) {
|
2023-07-13 19:05:08 +03:00
|
|
|
redirectToLogin();
|
2023-06-05 18:58:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-10-26 19:23:36 +03:00
|
|
|
<>
|
2024-02-07 03:05:07 +03:00
|
|
|
<div className={styles.page_header}>
|
|
|
|
<PageHeader iconName="user" label="Profile" buttons={[button]} />
|
|
|
|
</div>
|
|
|
|
<div className={styles.user_page_container}>
|
2024-02-04 04:45:05 +03:00
|
|
|
<div className={styles.content_wrapper}>
|
2024-03-15 21:41:25 +03:00
|
|
|
<Settings email={userData.email} />
|
2024-02-07 03:05:07 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Modal
|
|
|
|
isOpen={isLogoutModalOpened}
|
|
|
|
setOpen={setIsLogoutModalOpened}
|
2024-03-29 00:22:16 +03:00
|
|
|
size="auto"
|
2024-02-07 03:05:07 +03:00
|
|
|
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">
|
|
|
|
<QuivrButton
|
|
|
|
onClick={() => setIsLogoutModalOpened(false)}
|
|
|
|
color="primary"
|
|
|
|
label={t("cancel", { ns: "logout" })}
|
2024-02-07 10:34:50 +03:00
|
|
|
iconName="close"
|
2024-02-07 03:05:07 +03:00
|
|
|
></QuivrButton>
|
|
|
|
<QuivrButton
|
|
|
|
isLoading={isLoggingOut}
|
|
|
|
color="dangerous"
|
|
|
|
onClick={() => void handleLogout()}
|
|
|
|
label={t("logoutButton")}
|
2024-02-07 10:34:50 +03:00
|
|
|
iconName="logout"
|
2024-02-07 03:05:07 +03:00
|
|
|
></QuivrButton>
|
|
|
|
</div>
|
2024-02-04 04:45:05 +03:00
|
|
|
</div>
|
2024-02-07 03:05:07 +03:00
|
|
|
</Modal>
|
2023-10-26 19:23:36 +03:00
|
|
|
</>
|
2023-06-05 18:58:59 +03:00
|
|
|
);
|
2023-06-15 12:52:46 +03:00
|
|
|
};
|
2023-10-05 18:50:02 +03:00
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
export default UserPage;
|