forked from NCUAppTeam/NCU-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
902 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { HStack } from "../components"; | ||
import { supabase } from "../utils/supabase"; | ||
import { DrawerSideBar } from "./DrawerSideBar"; | ||
|
||
|
||
|
||
import React, { useEffect, useState } from 'react'; | ||
|
||
export const Header: React.FC = () => { | ||
|
||
const [userName, setUserName] = useState<string>(''); | ||
const [userAvatar, setUserAvatar] = useState<string>(''); | ||
const [error, setError] = useState<unknown>(''); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const userId = (await supabase.auth.getUser()).data?.user?.id; | ||
if (!userId) { | ||
throw new Error('User ID is undefined'); | ||
} | ||
const { data } = await supabase | ||
.from('members') | ||
.select(`*, identities ( identity_no, identity_name )`) | ||
.eq('uuid', userId); | ||
|
||
if (data && data.length > 0) { | ||
setUserName(data[0].name); | ||
setUserAvatar(data[0].avatar); | ||
} else { | ||
throw new Error('User data not found'); | ||
} | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
setError(error.message); | ||
} else { | ||
setError(String(error)); | ||
} | ||
} | ||
}; | ||
fetchData(); | ||
}, []); | ||
|
||
if (!userName || !userAvatar) { | ||
return <div>Loading...</div>; | ||
} | ||
if (error) { | ||
console.log('error', error); | ||
} | ||
|
||
return ( | ||
<div className="p-2 gap-2 justify-start"> | ||
<HStack className='items-center'> | ||
<DrawerSideBar name={userName} avatar={userAvatar} /> | ||
<div className='flex flex-1 justify-center'> | ||
<span className='mr-10'>NCU App</span> | ||
</div> | ||
</HStack> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.