@@ -4,37 +4,11 @@ import React, { useEffect } from 'react';
44import { useParams } from 'next/navigation' ;
55import { graphql } from '@/gql' ;
66import { UpdateUserInput } from '@/gql/generated/graphql' ;
7- import { useMutation , useQuery } from '@tanstack/react-query' ;
7+ import { useMutation } from '@tanstack/react-query' ;
88import { Button , DropZone , Text , TextField , toast } from 'opub-ui' ;
99
1010import { GraphQL } from '@/lib/api' ;
11-
12- const UserDetails : any = graphql ( `
13- query userDetails {
14- me {
15- bio
16- email
17- firstName
18- lastName
19- profilePicture {
20- name
21- path
22- url
23- }
24- username
25- id
26- organizationMemberships {
27- organization {
28- name
29- id
30- }
31- role {
32- name
33- }
34- }
35- }
36- }
37- ` ) ;
11+ import { useDashboardStore } from '../layout' ;
3812
3913const updateUserMutation : any = graphql ( `
4014 mutation updateUser($input: UpdateUserInput!) {
@@ -60,21 +34,19 @@ const updateUserMutation: any = graphql(`
6034const UserProfile = ( ) => {
6135 const params = useParams < { entitySlug : string } > ( ) ;
6236
63- const userDetails : any = useQuery ( [ `user_details_${ params . entitySlug } ` ] , ( ) =>
64- GraphQL ( UserDetails , { } , [ ] )
65- ) ;
37+ const { setUserDetails, userDetails } = useDashboardStore ( ) ;
6638
6739 useEffect ( ( ) => {
68- if ( userDetails . data ) {
40+ if ( userDetails && userDetails ?. me ) {
6941 setFormData ( {
70- firstName : userDetails . data ?. me ?. firstName ,
71- lastName : userDetails . data ?. me ?. lastName ,
72- email : userDetails . data ?. me ?. email ,
73- bio : userDetails . data ?. me ?. bio ,
74- profilePicture : userDetails . data ?. me ?. profilePicture ,
42+ firstName : userDetails ?. me ?. firstName ,
43+ lastName : userDetails ?. me ?. lastName ,
44+ email : userDetails ?. me ?. email ,
45+ bio : userDetails ?. me ?. bio ,
46+ profilePicture : userDetails ?. me ?. profilePicture ,
7547 } ) ;
7648 }
77- } , [ userDetails . data ] ) ;
49+ } , [ userDetails ] ) ;
7850
7951 const initialFormData = {
8052 firstName : '' ,
@@ -97,6 +69,10 @@ const UserProfile = () => {
9769 bio : res ?. updateUser ?. bio ,
9870 profilePicture : res ?. updateUser ?. profilePicture ,
9971 } ) ;
72+ setUserDetails ( {
73+ ...userDetails ,
74+ me : res . updateUser ,
75+ } ) ;
10076 } ,
10177 onError : ( error : any ) => {
10278 toast ( `Error: ${ error . message } ` ) ;
@@ -106,9 +82,7 @@ const UserProfile = () => {
10682
10783 const [ formData , setFormData ] = React . useState ( initialFormData ) ;
10884
109-
11085 const handleSave = ( ) => {
111-
11286 // Create mutation input with only changed fields
11387 const inputData : UpdateUserInput = {
11488 firstName : formData . firstName ,
0 commit comments