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

Function useUserInfoForm

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

Source from the content-addressed store, hash-verified

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

Callers 2

renderUserInfoFormFunction · 0.85
ProfileIndexFunction · 0.85

Calls 12

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

Tested by 1

renderUserInfoFormFunction · 0.68