-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
253 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 142 additions & 2 deletions
144
src/app/(userpage)/user/[userId]/components/MyProfileButton/MyProfileButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/app/(userpage)/user/[userId]/hooks/useUpdateProfile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { UpdateProfileRequest } from "@/types/global"; | ||
|
||
export const useUpdateProfile = (token: string) => { | ||
const updateProfileMutation = useMutation({ | ||
mutationFn: async (data: UpdateProfileRequest) => { | ||
const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/users/me`, { | ||
method: "PATCH", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
if (!res.ok) { | ||
const error = await res.json(); | ||
throw new Error(JSON.stringify(error)); | ||
} | ||
|
||
return res.json(); | ||
}, | ||
}); | ||
|
||
return { updateProfileMutation }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters