MCPcopy Create free account
hub / github.com/dailydotdev/apps / useUserInfoForm

Function useUserInfoForm

packages/shared/src/hooks/useUserInfoForm.ts:34–156  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34const useUserInfoForm = (): UseUserInfoForm => {
35 const qc = useQueryClient();
36 const { user, updateUser } = useContext(AuthContext);
37 const { logEvent } = useLogContext();
38 const { displayToast } = useToastNotification();
39 const router = useRouter();
40 const userId = user?.id ?? '';
41
42 // Fetch full profile via GraphQL to get socialLinks (boot endpoint doesn't include them)
43 const userQueryKey = generateQueryKey(RequestKey.Profile, user, {
44 id: userId,
45 });
46 const { data: fullProfile } = useQuery({
47 queryKey: userQueryKey,
48 queryFn: () => getProfile(userId),
49 ...disabledRefetch,
50 staleTime: StaleTime.OneHour,
51 enabled: !!userId,
52 });
53
54 useEffect(() => {
55 const searchParams = new URLSearchParams(window?.location?.search);
56 const field = searchParams?.get('field');
57 if (field) {
58 const element = document?.getElementsByName(field)[0];
59 if (element) {
60 element.focus();
61 }
62 }
63 }, []);
64
65 const methods = useForm<UserProfile>({
66 defaultValues: {
67 name: user?.name,
68 username: user?.username,
69 image: user?.image,
70 cover: user?.cover,
71 bio: user?.bio,
72 externalLocationId: user?.location?.externalId,
73 experienceLevel: user?.experienceLevel,
74 hideExperience: user?.hideExperience,
75 readme: user?.readme || '',
76 socialLinks: [],
77 },
78 });
79
80 // Update socialLinks when fullProfile loads (async fetch completes)
81 const hasUpdatedSocialLinks = useRef(false);
82 useEffect(() => {
83 if (fullProfile && !hasUpdatedSocialLinks.current) {
84 hasUpdatedSocialLinks.current = true;
85 methods.setValue('socialLinks', fullProfile.socialLinks || [], {
86 shouldDirty: false,
87 });
88 }
89 }, [fullProfile, methods]);
90
91 const dirtyFormRef = useRef<ReturnType<typeof useDirtyForm> | null>(null);

Callers 1

ProfileIndexFunction · 0.85

Calls 10

useLogContextFunction · 0.90
useToastNotificationFunction · 0.90
generateQueryKeyFunction · 0.90
getProfileFunction · 0.90
mutateUserInfoFunction · 0.90
useDirtyFormFunction · 0.90
displayToastFunction · 0.85
logEventFunction · 0.85
pushMethod · 0.80
useRouterFunction · 0.50

Tested by

no test coverage detected