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

Function useProfileForm

packages/shared/src/hooks/useProfileForm.ts:72–126  ·  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: ({ upload, coverUpload, onUpdateSuccess, ...data }) =>
84 gqlClient.request(UPDATE_USER_PROFILE_MUTATION, {
85 data,
86 upload,
87 coverUpload,
88 }),
89
90 onSuccess: async (
91 _,
92 { onUpdateSuccess, upload, coverUpload, ...userUpdates },
93 ) => {
94 setHint({});
95
96 if (user) {
97 await updateUser({ ...user, ...userUpdates });
98 }
99
100 onUpdateSuccess?.();
101 onSuccess?.();
102 },
103 onError: (err) => {
104 onError?.(err);
105
106 if (!err?.response?.errors?.length) {
107 return;
108 }
109
110 const firstError = err.response.errors[0];
111 if (!firstError?.message) {
112 return;
113 }
114
115 const data: ProfileFormHint = JSON.parse(firstError.message);
116 setHint(data);
117 },
118 });
119
120 return {
121 hint,
122 isLoading,
123 onUpdateHint: setHint,
124 updateUserProfile,
125 };
126};
127
128export default useProfileForm;

Callers 5

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

Calls 2

onSuccessFunction · 0.50
onErrorFunction · 0.50

Tested by

no test coverage detected