@@ -8,11 +8,11 @@ import ProfileAvatar from '@/components/ProfileAvatar';
8
8
import AboutTrainee from '@/components/trainee/About' ;
9
9
import ProfileAccountTab from '@/components/trainee/Account' ;
10
10
import TraineeOrg from '@/components/trainee/Organisation' ;
11
- import { GET_PROFILE } from '@/graphql/queries/user' ;
11
+ import { GET_PROFILE , GET_TRAINEE_PROFILE } from '@/graphql/queries/user' ;
12
12
import { useQuery } from '@apollo/client' ;
13
13
import { Ionicons } from '@expo/vector-icons' ;
14
14
import AsyncStorage from '@react-native-async-storage/async-storage' ;
15
- import { useRouter } from 'expo-router' ;
15
+ import { router , useLocalSearchParams , useRouter } from 'expo-router' ;
16
16
import { useToast } from 'react-native-toast-notifications' ;
17
17
18
18
type TabKey = 'About' | 'Organisation' | 'Account' ;
@@ -32,7 +32,8 @@ export default function Profile() {
32
32
const handleTypeChange = ( type : string ) => {
33
33
setSelectedType ( type as TabKey ) ;
34
34
} ;
35
-
35
+ const [ orgToken , setOrgToken ] = useState < string | null > ( null ) ;
36
+ const [ traineeProfile , setTraineeProfile ] = useState < any > ( { } ) ;
36
37
const accountPasswordUpdated = ( ) => {
37
38
setSelectedType ( 'About' ) ;
38
39
} ;
@@ -66,12 +67,52 @@ export default function Profile() {
66
67
setProfile ( data . getProfile ) ;
67
68
}
68
69
} , [ 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 ] ) ;
69
110
70
111
return (
71
112
< View >
72
113
< 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" >
75
116
< SvgXml xml = { editBG } />
76
117
</ TouchableOpacity >
77
118
@@ -116,7 +157,7 @@ export default function Profile() {
116
157
className = "mt-4 w-[100%] flex-grow"
117
158
>
118
159
{ selectedType === 'About' && (
119
- < AboutTrainee profile = { profile } bgColor = { bgColor } textColor = { textColor } />
160
+ < AboutTrainee profile = { profile } Resume = { traineeProfile } bgColor = { bgColor } textColor = { textColor } />
120
161
) }
121
162
122
163
{ selectedType === 'Organisation' && (
0 commit comments