@@ -8,11 +8,11 @@ import ProfileAvatar from '@/components/ProfileAvatar';
88import AboutTrainee from '@/components/trainee/About' ;
99import ProfileAccountTab from '@/components/trainee/Account' ;
1010import TraineeOrg from '@/components/trainee/Organisation' ;
11- import { GET_PROFILE } from '@/graphql/queries/user' ;
11+ import { GET_PROFILE , GET_TRAINEE_PROFILE } from '@/graphql/queries/user' ;
1212import { useQuery } from '@apollo/client' ;
1313import { Ionicons } from '@expo/vector-icons' ;
1414import AsyncStorage from '@react-native-async-storage/async-storage' ;
15- import { useRouter } from 'expo-router' ;
15+ import { router , useLocalSearchParams , useRouter } from 'expo-router' ;
1616import { useToast } from 'react-native-toast-notifications' ;
1717
1818type TabKey = 'About' | 'Organisation' | 'Account' ;
@@ -32,7 +32,8 @@ export default function Profile() {
3232 const handleTypeChange = ( type : string ) => {
3333 setSelectedType ( type as TabKey ) ;
3434 } ;
35-
35+ const [ orgToken , setOrgToken ] = useState < string | null > ( null ) ;
36+ const [ traineeProfile , setTraineeProfile ] = useState < any > ( { } ) ;
3637 const accountPasswordUpdated = ( ) => {
3738 setSelectedType ( 'About' ) ;
3839 } ;
@@ -66,12 +67,52 @@ export default function Profile() {
6667 setProfile ( data . getProfile ) ;
6768 }
6869 } , [ data ] ) ;
70+
71+ useEffect ( ( ) => {
72+ const fetchOrgToken = async ( ) => {
73+ try {
74+ const orgToken = await AsyncStorage . getItem ( 'orgToken' ) ;
75+ if ( orgToken ) {
76+ setOrgToken ( orgToken ) ;
77+ } else {
78+ toast . show ( 'Token Not found.' , { type : 'danger' , placement : 'top' , duration : 3000 } ) ;
79+ }
80+ } catch ( error ) {
81+ toast . show ( 'Failed to retrieve token.' , { type : 'danger' , placement : 'top' , duration : 3000 } ) ;
82+ }
83+ } ;
84+ fetchOrgToken ( ) ;
85+ } , [ ] ) ;
86+
87+ const { data : traineedata , error : err } = useQuery ( GET_TRAINEE_PROFILE , {
88+ context : {
89+ headers : {
90+ Authorization : `Bearer ${ userToken } ` ,
91+ } ,
92+ } ,
93+ skip : ! userToken ,
94+ variables : {
95+ orgToken : orgToken ,
96+ } ,
97+ } ) ;
98+
99+ useEffect ( ( ) => {
100+ if ( err ) {
101+ toast . show ( `Error fetching profile.${ err } ` , { type : 'danger' , placement : 'top' , duration : 3000 } ) ;
102+ }
103+ } , [ err ] ) ;
104+
105+ useEffect ( ( ) => {
106+ if ( traineedata ) {
107+ setTraineeProfile ( traineedata . getProfile ) ;
108+ }
109+ } , [ traineedata ] ) ;
69110
70111 return (
71112 < View >
72113 < View className = "relative h-48" >
73- < CoverImage cover = { profile ?. cover } name = { profile ?. name } />
74- < TouchableOpacity className = "absolute bottom-1 right-4 rounded-full shadow-md" >
114+ < CoverImage cover = { profile ?. cover } name = { profile ?. name } />
115+ < TouchableOpacity onPress = { ( ) => router . push ( '/dashboard/trainee/profile/edit' ) } className = "absolute bottom-1 right-4 rounded-full shadow-md" >
75116 < SvgXml xml = { editBG } />
76117 </ TouchableOpacity >
77118
@@ -116,7 +157,7 @@ export default function Profile() {
116157 className = "mt-4 w-[100%] flex-grow"
117158 >
118159 { selectedType === 'About' && (
119- < AboutTrainee profile = { profile } bgColor = { bgColor } textColor = { textColor } />
160+ < AboutTrainee profile = { profile } Resume = { traineeProfile } bgColor = { bgColor } textColor = { textColor } />
120161 ) }
121162
122163 { selectedType === 'Organisation' && (
0 commit comments