import { IonButton, IonCol, IonContent, IonFooter, IonGrid, IonHeader, IonPage, IonRow, IonText, useIonRouter, } from '@ionic/react'; import styles from './style.module.scss'; import { useParams } from 'react-router'; import { Wave } from '../../../components/Wave'; import { Paths } from '../../../Paths'; import { useEffect, useState } from 'react'; import { getUserMetaById } from '../../../db/UserMetas/GetById'; import { useTranslation } from 'react-i18next'; import { DBUserMeta } from '../../../db/UserMetas/type'; import { LoadingScreen } from '../../../components/LoadingScreen'; import { getStudentAvatar } from '../../../lib/getStudentAvatar'; import { authClient } from '../../../lib/auth/custom/client'; import { useUser } from '../../../hooks/use-user'; function StudentInfo(): React.JSX.Element { const router = useIonRouter(); const { id } = useParams<{ id: string }>(); const { t } = useTranslation(); const [studentMeta, setStudentMeta] = useState(); const test = useUser(); const [showLoading, setShowLoading] = useState(true); const [showError, setShowError] = useState<{ show: boolean; message: string }>({ show: false, message: '' }); function handleBackToLogin() { router.push(Paths.AuthLogin); } function handleBackOnClick() { router.push(Paths.Setting); } async function handleFetchUserMeta() { try { const result = await getUserMetaById(id); const tempStudentMeta = result as unknown as DBUserMeta; setStudentMeta(tempStudentMeta); setShowLoading(false); } catch (error) { setShowError({ show: true, message: JSON.stringify({ error }, null, 2) }); setShowLoading(false); } } async function handleLogoutOnClick() { try { await authClient.signOut(); router.push(Paths.AuthLogin); } catch (error) { console.error(error); } } useEffect(() => { void handleFetchUserMeta(); }, []); if (showLoading) return ; if (!studentMeta) return ; if (showError.show) return <>{showError.message}; return ( {/* */} {/* */}
{/* */} {t('student-name')} {studentMeta.name} {/* */} {t('student-email')} {studentMeta.email} {/* */} {t('student-phone')} {studentMeta.phone} {/* */} {t('back')} {t('logout')}
{/* */}
); } export default StudentInfo;