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

Function useProfileForm

packages/shared/src/hooks/useProfileForm.ts:72–132  ·  view source on GitHub ↗
({
  onSuccess,
  onError,
}: UseProfileFormProps = {})

Source from the content-addressed store, hash-verified

70 * @deprecated Use useUserInfoForm instead
71 */
72const useProfileForm = ({
73 onSuccess,
74 onError,
75}: UseProfileFormProps = {}): UseProfileForm => {
76 const { user, updateUser } = useContext(AuthContext);
77 const [hint, setHint] = useState<ProfileFormHint>({});
78 const { isPending: isLoading, mutate: updateUserProfile } = useMutation<
79 LoggedUser,
80 ResponseError,
81 UpdateProfileParameters
82 >({
83 mutationFn: async ({ upload, coverUpload, onUpdateSuccess, ...data }) => {
84 const res = await gqlClient.request<{ updateUserProfile: LoggedUser }>(
85 UPDATE_USER_PROFILE_MUTATION,
86 {
87 data,
88 upload,
89 coverUpload,
90 },
91 );
92
93 return res?.updateUserProfile;
94 },
95
96 onSuccess: async (
97 updatedUser,
98 { onUpdateSuccess, upload, coverUpload, ...userUpdates },
99 ) => {
100 setHint({});
101
102 if (user) {
103 await updateUser({ ...user, ...userUpdates, ...updatedUser });
104 }
105
106 onUpdateSuccess?.();
107 onSuccess?.();
108 },
109 onError: (err) => {
110 onError?.(err);
111
112 if (!err?.response?.errors?.length) {
113 return;
114 }
115
116 const data = parseProfileFormHint(err.response.errors[0]?.message);
117
118 if (!data) {
119 return;
120 }
121
122 setHint(data);
123 },
124 });
125
126 return {
127 hint,
128 isLoading,
129 onUpdateHint: setHint,

Callers 7

BootPopupsFunction · 0.85
AuthOptionsInnerFunction · 0.85
TimezoneDropdownFunction · 0.85
InnerFunnelProfileFormFunction · 0.85
FunnelUserRoleComponentFunction · 0.85

Calls 3

parseProfileFormHintFunction · 0.90
onSuccessFunction · 0.50
onErrorFunction · 0.50

Tested by

no test coverage detected